Skip to content

define a new helper function for tests called get_integer_float_dtypes #2402

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

Merged
merged 4 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions dpnp/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,36 @@ def get_integer_dtypes(all_int_types=False, no_unsigned=False):
return dtypes


def get_integer_float_dtypes(
all_int_types=False,
no_unsigned=False,
no_float16=True,
device=None,
xfail_dtypes=None,
exclude=None,
):
"""
Build a list of integer and float types supported by DPNP.
"""
dtypes = get_integer_dtypes(
all_int_types=all_int_types, no_unsigned=no_unsigned
)
dtypes += get_float_dtypes(no_float16=no_float16, device=device)

def mark_xfail(dtype):
if xfail_dtypes is not None and dtype in xfail_dtypes:
return pytest.param(dtype, marks=pytest.mark.xfail)
return dtype

def not_excluded(dtype):
if exclude is None:
return True
return dtype not in exclude

dtypes = [mark_xfail(dtype) for dtype in dtypes if not_excluded(dtype)]
return dtypes


def has_support_aspect16(device=None):
"""
Return True if the device supports 16-bit precision floating point operations,
Expand Down
5 changes: 3 additions & 2 deletions dpnp/tests/test_binary_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_float_complex_dtypes,
get_float_dtypes,
get_integer_dtypes,
get_integer_float_dtypes,
has_support_aspect16,
numpy_version,
)
Expand Down Expand Up @@ -141,7 +142,7 @@ def test_invalid_out(self, xp, out):
@pytest.mark.parametrize("func", ["fmax", "fmin", "maximum", "minimum"])
class TestBoundFuncs:
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
def test_out(self, func, dtype):
def test_basic(self, func, dtype):
a = generate_random_numpy_array(10, dtype)
b = generate_random_numpy_array(10, dtype)
expected = getattr(numpy, func)(a, b)
Expand Down Expand Up @@ -278,7 +279,7 @@ def test_invalid_out(self, xp, out):

@pytest.mark.parametrize("func", ["floor_divide", "remainder"])
class TestFloorDivideRemainder:
ALL_DTYPES = get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
ALL_DTYPES = get_integer_float_dtypes()

def do_inplace_op(self, base, other, func):
if func == "floor_divide":
Expand Down
17 changes: 5 additions & 12 deletions dpnp/tests/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
get_float_complex_dtypes,
get_float_dtypes,
get_integer_dtypes,
get_integer_float_dtypes,
has_support_aspect64,
numpy_version,
)


class TestDigitize:
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
)
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
@pytest.mark.parametrize("right", [True, False])
@pytest.mark.parametrize(
"x, bins",
Expand Down Expand Up @@ -73,12 +72,8 @@ def test_digitize_inf(self, dtype, right):
expected = numpy.digitize(x, bins, right=right)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize(
"dtype_x", get_all_dtypes(no_bool=True, no_complex=True)
)
@pytest.mark.parametrize(
"dtype_bins", get_all_dtypes(no_bool=True, no_complex=True)
)
@pytest.mark.parametrize("dtype_x", get_integer_float_dtypes())
@pytest.mark.parametrize("dtype_bins", get_integer_float_dtypes())
@pytest.mark.parametrize("right", [True, False])
def test_digitize_diff_types(self, dtype_x, dtype_bins, right):
x = numpy.array([1, 2, 3, 4, 5], dtype=dtype_x)
Expand All @@ -90,9 +85,7 @@ def test_digitize_diff_types(self, dtype_x, dtype_bins, right):
expected = numpy.digitize(x, bins, right=right)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
)
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
@pytest.mark.parametrize(
"x, bins",
[
Expand Down
5 changes: 2 additions & 3 deletions dpnp/tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
get_all_dtypes,
get_complex_dtypes,
get_float_complex_dtypes,
get_integer_float_dtypes,
has_support_aspect64,
is_cpu_device,
is_cuda_device,
Expand Down Expand Up @@ -1409,9 +1410,7 @@ def test_einsum_tensor(self):
result = dpnp.einsum("ijij->", tensor_dp)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_complex=True, no_none=True)
)
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
def test_different_paths(self, dtype):
# Simple test, designed to exercise most specialized code paths,
# note the +0.5 for floats. This makes sure we use a float value
Expand Down
9 changes: 5 additions & 4 deletions dpnp/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
get_all_dtypes,
get_float_complex_dtypes,
get_float_dtypes,
get_integer_float_dtypes,
)


Expand Down Expand Up @@ -83,7 +84,7 @@ def check_raises(func_name, exception, *args, **kwargs):
check_raises(func, TypeError, [0, 1, 2, 3])


@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
def test_allclose(dtype):
a = numpy.random.rand(10)
b = a + numpy.random.rand(10) * 1e-8
Expand Down Expand Up @@ -508,7 +509,7 @@ def test_infinity_sign_errors(func):
getattr(dpnp, func)(x, out=out)


@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
@pytest.mark.parametrize(
"rtol", [1e-05, dpnp.array(1e-05), dpnp.full(10, 1e-05)]
)
Expand Down Expand Up @@ -549,7 +550,7 @@ def test_array_equiv(a, b):
assert_equal(result, expected)


@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
def test_array_equiv_dtype(dtype):
a = numpy.array([1, 2], dtype=dtype)
b = numpy.array([1, 2], dtype=dtype)
Expand All @@ -575,7 +576,7 @@ def test_array_equiv_scalar(a):
assert_equal(result, expected)


@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
@pytest.mark.parametrize("equal_nan", [True, False])
def test_array_equal_dtype(dtype, equal_nan):
a = numpy.array([1, 2], dtype=dtype)
Expand Down
5 changes: 2 additions & 3 deletions dpnp/tests/test_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_float_complex_dtypes,
get_float_dtypes,
get_integer_dtypes,
get_integer_float_dtypes,
has_support_aspect64,
numpy_version,
)
Expand Down Expand Up @@ -325,9 +326,7 @@ class TestCopyTo:
]
testdata += [
([1, -1, 0], dtype)
for dtype in get_all_dtypes(
no_none=True, no_bool=True, no_complex=True, no_unsigned=True
)
for dtype in get_integer_float_dtypes(no_unsigned=True)
]
testdata += [([0.1, 0.0, -0.1], dtype) for dtype in get_float_dtypes()]
testdata += [([1j, -1j, 1 - 2j], dtype) for dtype in get_complex_dtypes()]
Expand Down
Loading
Loading