tracel-ai / cubecl

Multi-platform high-performance compute language extension for Rust.
https://burn.dev
Apache License 2.0
535 stars 21 forks source link

Tests for various unary functions #117

Closed RianGoossens closed 1 day ago

RianGoossens commented 1 week ago

Some unary functions have trivial implementations. Others however have more complicated implementations on either or both backends. These should be unit tested so we can be sure that:

Writing these unit tests is cumbersome, so I made a macro that makes things a bit easier:

test_unary_impl!(
    test_normalize,
    F,
    F::normalize,
    [
        {
            input_vectorization: 2,
            out_vectorization: 2,
            input: [-1., 0., 1., 5.],
            expected: [-1.0, 0.0, 0.196, 0.981]
        },
        {
            input_vectorization: 4,
            out_vectorization: 4,
            input: [-1., 0., 1., 5.],
            expected: [-0.192, 0.0, 0.192, 0.962]
        }
        //...
    ]
);

This also allows for some TDD, and will make it easier to verify new backends in the future.