Skip to content

Opencl interop #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
added unit tests for range function
  • Loading branch information
Chaluvadi committed Mar 28, 2024
commit 2fbaace5e3775703e0c97471017cd0bba5df1a77
61 changes: 61 additions & 0 deletions tests/test_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import random

import pytest

import arrayfire_wrapper.dtypes as dtypes
import arrayfire_wrapper.lib as wrapper


@pytest.mark.parametrize(
"shape",
[
(),
(random.randint(1, 10), 1),
(random.randint(1, 10), random.randint(1, 10)),
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
],
)
def test_range_shape(shape: tuple) -> None:
"""Test if the range function output an AFArray with the correct shape"""
dim = 2
dtype = dtypes.s16

result = wrapper.range(shape, dim, dtype)

assert wrapper.get_dims(result)[0 : len(shape)] == shape # noqa: E203


def test_range_invalid_shape() -> None:
"""Test if range function correctly handles an invalid shape"""
with pytest.raises(TypeError):
shape = (
random.randint(1, 10),
random.randint(1, 10),
random.randint(1, 10),
random.randint(1, 10),
random.randint(1, 10),
)
dim = 2
dtype = dtypes.s16

wrapper.range(shape, dim, dtype)


@pytest.mark.parametrize(
"shape",
[
(),
(random.randint(1, 10), 1),
(random.randint(1, 10), random.randint(1, 10)),
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
],
)
def test_range_invalid_dim(shape: tuple) -> None:
"""Test if the range function can properly handle and invalid dimension given"""
with pytest.raises(RuntimeError):
dim = random.randint(4, 10)
dtype = dtypes.s16

wrapper.range(shape, dim, dtype)