Skip to content

Commit

Permalink
Some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderKalistratov committed Dec 11, 2024
1 parent f0bd5bc commit 67244af
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ jobs:
- name: Run full tests
env:
DPNP_TEST_ALL_TYPES: 1
DPNP_TEST_ALL_INT_TYPES: 1
run: |
pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
Expand Down Expand Up @@ -527,7 +527,7 @@ jobs:
- name: Run full tests
if: matrix.python == '3.12'
env:
DPNP_TEST_ALL_TYPES: 1
DPNP_TEST_ALL_INT_TYPES: 1
run: |
pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
Expand Down
5 changes: 4 additions & 1 deletion dpnp/tests/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os

all_types = int(os.getenv("DPNP_TEST_ALL_TYPES", 0))
all_int_types = int(os.getenv("DPNP_TEST_ALL_INT_TYPES", 0))
float16_types = int(os.getenv("DPNP_TEST_FLOAT_16", 0))
complex_types = int(os.getenv("DPNP_TEST_COMPLEX_TYPES", 0))
bool_types = int(os.getenv("DPNP_TEST_BOOL_TYPES", 0))
22 changes: 20 additions & 2 deletions dpnp/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_integer_dtypes():
Build a list of integer types supported by DPNP.
"""

if config.all_types:
if config.all_int_types:
return [
dpnp.int8,
dpnp.int16,
Expand Down Expand Up @@ -147,7 +147,13 @@ def get_float_complex_dtypes(no_float16=True, device=None):


def get_all_dtypes(
no_bool=False, no_float16=True, no_complex=False, no_none=False, device=None
no_bool=False,
no_float16=True,
no_complex=False,
no_none=False,
device=None,
xfail_dtypes=None,
exclude=None,
):
"""
Build a list of types supported by DPNP based on input flags and device capabilities.
Expand All @@ -171,6 +177,18 @@ def get_all_dtypes(
# add None value to validate a default dtype
if not no_none:
dtypes.append(None)

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


Expand Down
4 changes: 2 additions & 2 deletions dpnp/tests/test_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@


@pytest.mark.parametrize("func", ["abs", "absolute"])
@pytest.mark.parametrize("dtype", get_all_dtypes())
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
def test_abs(func, dtype):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9], dtype=dtype)
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9]).astype(dtype=dtype)
ia = dpnp.array(a)

result = getattr(dpnp, func)(ia)
Expand Down
9 changes: 8 additions & 1 deletion dpnp/tests/test_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,17 @@ def test_dpctl_tensor_input(func, args):
ids=["1", "5", "numpy.array(10)", "dpnp.array(17)", "dpt.asarray(100)"],
)
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_float16=False)
"dtype",
get_all_dtypes(
no_bool=True, no_float16=False, exclude=[numpy.uint8, dpnp.int8]
),
)
@pytest.mark.parametrize("retstep", [True, False])
def test_linspace(start, stop, num, dtype, retstep):
if numpy.issubdtype(dtype, numpy.unsignedinteger):
start = abs(start)
stop = abs(stop)

res_np = numpy.linspace(start, stop, num, dtype=dtype, retstep=retstep)
res_dp = dpnp.linspace(start, stop, num, dtype=dtype, retstep=retstep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def check_distribution(self, dist_name, params, dtype=None):
np_out = numpy.asarray(
getattr(numpy.random, dist_name)(size=self.shape, **params), dtype
)
dt_kward = {dtype: dtype} if dtype else {}
dt_kward = {"dtype": dtype} if dtype else {}
cp_out = getattr(_distributions, dist_name)(
size=self.shape, **dt_kward, **cp_params
)
Expand Down Expand Up @@ -72,12 +72,14 @@ def test_beta(self, a_dtype, b_dtype):
"shape": [(4, 3, 2), (3, 2)],
"n_shape": [(), (3, 2)],
"p_shape": [(), (3, 2)],
"dtype": _int_dtypes, # to escape timeout
# "dtype": _int_dtypes, # to escape timeout
"dtype": [None], # no dtype supported
}
)
)
class TestDistributionsBinomial(RandomDistributionsTestCase):

@pytest.mark.skip()
@testing.for_signed_dtypes("n_dtype")
@testing.for_float_dtypes("p_dtype")
def test_binomial(self, n_dtype, p_dtype):
Expand Down
49 changes: 41 additions & 8 deletions dpnp/tests/third_party/cupy/testing/_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Tuple, Type

import numpy
import pytest
from dpctl import select_default_device
from dpctl.tensor._numpy_helper import AxisError

Expand Down Expand Up @@ -979,7 +980,7 @@ def test_func(*args, **kw):
return decorator


def for_dtypes(dtypes, name="dtype"):
def for_dtypes(dtypes, name="dtype", xfail_dtypes=None):
"""Decorator for parameterized dtype test.
Args:
Expand Down Expand Up @@ -1010,7 +1011,11 @@ def test_func(*args, **kw):

try:
kw[name] = numpy.dtype(dtype).type
impl(*args, **kw)
if xfail_dtypes is not None and dtype in xfail_dtypes:
impl_ = pytest.mark.xfail(impl)
else:
impl_ = impl
impl_(*args, **kw)
except _skip_classes as e:
print("skipped: {} = {} ({})".format(name, dtype, e))
except Exception:
Expand Down Expand Up @@ -1041,19 +1046,47 @@ def _get_supported_complex_dtypes():


def _get_int_dtypes():
if config.all_types:
if config.all_int_types:
return _signed_dtypes + _unsigned_dtypes
else:
return (numpy.int64, numpy.int32)


def _get_float_dtypes():
if config.float16_types:
return _regular_float_dtypes + (numpy.float16,)
else:
return _regular_float_dtypes


def _get_signed_dtypes():
if config.all_int_types:
return tuple(numpy.dtype(i).type for i in "bhilq")
else:
return (numpy.int32,)


def _get_unsigned_dtypes():
if config.all_int_types:
return tuple(numpy.dtype(i).type for i in "BHILQ")
else:
return (numpy.uint32,)


def _get_int_bool_dtypes():
if config.bool_types:
return _int_dtypes + (numpy.bool_,)
else:
return _int_dtypes


_complex_dtypes = _get_supported_complex_dtypes()
_regular_float_dtypes = _get_supported_float_dtypes()
_float_dtypes = _regular_float_dtypes # + (numpy.float16,)
_signed_dtypes = tuple(numpy.dtype(i).type for i in "bhilq")
_unsigned_dtypes = tuple(numpy.dtype(i).type for i in "BHILQ")
_float_dtypes = _get_float_dtypes()
_signed_dtypes = _get_signed_dtypes()
_unsigned_dtypes = _get_unsigned_dtypes()
_int_dtypes = _get_int_dtypes()
_int_bool_dtypes = _int_dtypes + (numpy.bool_,)
_int_bool_dtypes = _get_int_bool_dtypes()
_regular_dtypes = _regular_float_dtypes + _int_bool_dtypes
_dtypes = _float_dtypes + _int_bool_dtypes

Expand All @@ -1069,7 +1102,7 @@ def _make_all_dtypes(no_float16, no_bool, no_complex):
else:
dtypes += _int_bool_dtypes

if not no_complex:
if config.complex_types and not no_complex:
dtypes += _complex_dtypes

return dtypes
Expand Down

0 comments on commit 67244af

Please sign in to comment.