Skip to content

Commit c7178ad

Browse files
authored
Add missing content upon the last merge from master (#1267)
1 parent 1b30de4 commit c7178ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+355
-33
lines changed

dpnp/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@
4747
'''
4848
Explicitly use SYCL shared memory parameter in DPCtl array constructor for creation functions
4949
'''
50+
51+
__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ = int(os.getenv('DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK', 1))
52+
'''
53+
Trigger non-implemented exception when DPNP fallbacks on NumPy implementation
54+
'''

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ def call_origin(function, *args, **kwargs):
126126
Call fallback function for unsupported cases
127127
"""
128128

129+
allow_fallback = kwargs.pop("allow_fallback", False)
130+
131+
if not allow_fallback and config.__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__ == 1:
132+
raise NotImplementedError(f"Requested funtion={function.__name__} with args={args} and kwargs={kwargs} "
133+
"isn't currently supported and would fall back on NumPy implementation. "
134+
"Define enviroment variable `DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK` to `0` "
135+
"if the fall back is required to be supported without rasing an exception.")
136+
129137
dpnp_inplace = kwargs.pop("dpnp_inplace", False)
130138
sycl_queue = kwargs.pop("sycl_queue", None)
131139
# print(f"DPNP call_origin(): Fallback called. \n\t function={function}, \n\t args={args}, \n\t kwargs={kwargs}, \n\t dpnp_inplace={dpnp_inplace}")

dpnp/random/dpnp_iface_random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ def seed(seed=None):
13141314
dpnp_rng_srand(seed)
13151315

13161316
# always reseed numpy engine also
1317-
return call_origin(numpy.random.seed, seed)
1317+
return call_origin(numpy.random.seed, seed, allow_fallback=True)
13181318

13191319

13201320
def standard_cauchy(size=None):

dpnp/random/dpnp_random_state.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,10 @@ def randint(self, low, high=None, size=None, dtype=int, usm_type="device"):
345345

346346
min_int = numpy.iinfo('int32').min
347347
max_int = numpy.iinfo('int32').max
348-
if not dpnp.isfinite(low) or low > max_int or low < min_int:
348+
349+
if not self._is_finite_scalar(low) or low > max_int or low < min_int:
349350
raise OverflowError(f"Range of low={low} exceeds valid bounds")
350-
elif not dpnp.isfinite(high) or high > max_int or high < min_int:
351+
elif not self._is_finite_scalar(high) or high > max_int or high < min_int:
351352
raise OverflowError(f"Range of high={high} exceeds valid bounds")
352353

353354
low = int(low)
@@ -547,9 +548,10 @@ def uniform(self, low=0.0, high=1.0, size=None, dtype=None, usm_type="device"):
547548
else:
548549
min_double = numpy.finfo('double').min
549550
max_double = numpy.finfo('double').max
550-
if not dpnp.isfinite(low) or low >= max_double or low <= min_double:
551+
552+
if not self._is_finite_scalar(low) or low >= max_double or low <= min_double:
551553
raise OverflowError(f"Range of low={low} exceeds valid bounds")
552-
elif not dpnp.isfinite(high) or high >= max_double or high <= min_double:
554+
elif not self._is_finite_scalar(high) or high >= max_double or high <= min_double:
553555
raise OverflowError(f"Range of high={high} exceeds valid bounds")
554556

555557
if low > high:

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ def pytest_collection_modifyitems(config, items):
7373
# exact match of the test name with items from excluded_list
7474
if test_name == item_tbl_str:
7575
item.add_marker(skip_mark)
76+
77+
@pytest.fixture
78+
def allow_fall_back_on_numpy(monkeypatch):
79+
monkeypatch.setattr(dpnp.config, '__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__', 0)

tests/test_amin_amax.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def _get_min_max_input(type, shape):
6767
return a.reshape(shape)
6868

6969

70+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
7071
@pytest.mark.parametrize("type",
7172
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
7273
ids=['float64', 'float32', 'int64', 'int32'])
@@ -87,6 +88,7 @@ def test_amax(type, shape):
8788
numpy.testing.assert_array_equal(dpnp_res, np_res)
8889

8990

91+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
9092
@pytest.mark.parametrize("type",
9193
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
9294
ids=['float64', 'float32', 'int64', 'int32'])

tests/test_arithmetic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import pytest
23

34
from tests.third_party.cupy import testing
45

@@ -21,12 +22,14 @@ def test_modf_part2(self, xp, dtype):
2122

2223
return c
2324

25+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
2426
@testing.for_float_dtypes()
2527
@testing.numpy_cupy_allclose()
2628
def test_nanprod(self, xp, dtype):
2729
a = xp.array([-2.5, -1.5, xp.nan, 10.5, 1.5, xp.nan], dtype=dtype)
2830
return xp.nanprod(a)
2931

32+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
3033
@testing.for_float_dtypes()
3134
@testing.numpy_cupy_allclose()
3235
def test_nansum(self, xp, dtype):

tests/test_arraycreation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ def test_identity(n, dtype):
258258

259259
assert_array_equal(func(numpy), func(dpnp))
260260

261-
assert_array_equal(func(numpy), func(dpnp))
262-
263261

264262
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
265263
@pytest.mark.parametrize("dtype",

tests/test_arraymanipulation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy
55

66

7+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
78
@pytest.mark.parametrize("dtype",
89
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
910
ids=["float64", "float32", "int64", "int32"])
@@ -30,6 +31,7 @@ def test_asfarray2(dtype, data):
3031
numpy.testing.assert_array_equal(result, expected)
3132

3233

34+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
3335
class TestConcatenate:
3436
def test_returns_copy(self):
3537
a = dpnp.array(numpy.eye(3))
@@ -91,23 +93,27 @@ class TestHstack:
9193
def test_non_iterable(self):
9294
numpy.testing.assert_raises(TypeError, dpnp.hstack, 1)
9395

96+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
9497
def test_empty_input(self):
9598
numpy.testing.assert_raises(ValueError, dpnp.hstack, ())
9699

100+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
97101
def test_0D_array(self):
98102
b = dpnp.array(2)
99103
a = dpnp.array(1)
100104
res = dpnp.hstack([a, b])
101105
desired = dpnp.array([1, 2])
102106
numpy.testing.assert_array_equal(res, desired)
103107

108+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
104109
def test_1D_array(self):
105110
a = dpnp.array([1])
106111
b = dpnp.array([2])
107112
res = dpnp.hstack([a, b])
108113
desired = dpnp.array([1, 2])
109114
numpy.testing.assert_array_equal(res, desired)
110115

116+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
111117
def test_2D_array(self):
112118
a = dpnp.array([[1], [2]])
113119
b = dpnp.array([[1], [2]])
@@ -126,30 +132,35 @@ class TestVstack:
126132
def test_non_iterable(self):
127133
numpy.testing.assert_raises(TypeError, dpnp.vstack, 1)
128134

135+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
129136
def test_empty_input(self):
130137
numpy.testing.assert_raises(ValueError, dpnp.vstack, ())
131138

139+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
132140
def test_0D_array(self):
133141
a = dpnp.array(1)
134142
b = dpnp.array(2)
135143
res = dpnp.vstack([a, b])
136144
desired = dpnp.array([[1], [2]])
137145
numpy.testing.assert_array_equal(res, desired)
138146

147+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
139148
def test_1D_array(self):
140149
a = dpnp.array([1])
141150
b = dpnp.array([2])
142151
res = dpnp.vstack([a, b])
143152
desired = dpnp.array([[1], [2]])
144153
numpy.testing.assert_array_equal(res, desired)
145154

155+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
146156
def test_2D_array(self):
147157
a = dpnp.array([[1], [2]])
148158
b = dpnp.array([[1], [2]])
149159
res = dpnp.vstack([a, b])
150160
desired = dpnp.array([[1], [2], [1], [2]])
151161
numpy.testing.assert_array_equal(res, desired)
152162

163+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
153164
def test_2D_array2(self):
154165
a = dpnp.array([1, 2])
155166
b = dpnp.array([1, 2])

tests/test_bitwise.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,26 @@ def _test_binary_int(self, name, lhs, rhs, dtype):
3737

3838
numpy.testing.assert_array_equal(result, expected)
3939

40+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4041
def test_bitwise_and(self, lhs, rhs, dtype):
4142
self._test_binary_int('bitwise_and', lhs, rhs, dtype)
4243

44+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4345
def test_bitwise_or(self, lhs, rhs, dtype):
4446
self._test_binary_int('bitwise_or', lhs, rhs, dtype)
4547

48+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4649
def test_bitwise_xor(self, lhs, rhs, dtype):
4750
self._test_binary_int('bitwise_xor', lhs, rhs, dtype)
4851

52+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4953
def test_invert(self, lhs, rhs, dtype):
5054
self._test_unary_int('invert', lhs, dtype)
5155

56+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
5257
def test_left_shift(self, lhs, rhs, dtype):
5358
self._test_binary_int('left_shift', lhs, rhs, dtype)
5459

60+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
5561
def test_right_shift(self, lhs, rhs, dtype):
5662
self._test_binary_int('right_shift', lhs, rhs, dtype)

0 commit comments

Comments
 (0)