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)

tests/test_histograms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def setup(self):
1313
def teardown(self):
1414
pass
1515

16+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
1617
def test_simple(self):
1718
n = 100
1819
v = dpnp.random.rand(n)
@@ -24,6 +25,7 @@ def test_simple(self):
2425
(a, b) = dpnp.histogram(numpy.linspace(0, 10, 100))
2526
numpy.testing.assert_array_equal(a, 10)
2627

28+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
2729
def test_one_bin(self):
2830
# Ticket 632
2931
hist, edges = dpnp.histogram([1, 2, 3, 4], [1, 2])
@@ -66,6 +68,8 @@ def test_density(self):
6668
[1, 2, 3, 4], [0.5, 1.5, numpy.inf], density=True)
6769
numpy.testing.assert_equal(counts, [.25, 0])
6870

71+
72+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
6973
def test_arr_weights_mismatch(self):
7074
a = dpnp.arange(10) + .5
7175
w = dpnp.arange(11) + .5

tests/test_indexing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy
66

77

8+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
89
def test_choose():
910
a = numpy.r_[:4]
1011
ia = dpnp.array(a)
@@ -109,6 +110,7 @@ def test_nonzero(array):
109110
numpy.testing.assert_array_equal(expected, result)
110111

111112

113+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
112114
@pytest.mark.parametrize("vals",
113115
[[100, 200],
114116
(100, 200)],
@@ -138,6 +140,7 @@ def test_place1(arr, mask, vals):
138140
numpy.testing.assert_array_equal(a, ia)
139141

140142

143+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
141144
@pytest.mark.parametrize("vals",
142145
[[100, 200],
143146
[100, 200, 300, 400, 500, 600],
@@ -161,6 +164,7 @@ def test_place2(arr, mask, vals):
161164
numpy.testing.assert_array_equal(a, ia)
162165

163166

167+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
164168
@pytest.mark.parametrize("vals",
165169
[[100, 200],
166170
[100, 200, 300, 400, 500, 600],
@@ -243,6 +247,7 @@ def test_put3():
243247
numpy.testing.assert_array_equal(a, ia)
244248

245249

250+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
246251
def test_put_along_axis_val_int():
247252
a = numpy.arange(16).reshape(4, 4)
248253
ai = dpnp.array(a)
@@ -254,6 +259,7 @@ def test_put_along_axis_val_int():
254259
numpy.testing.assert_array_equal(a, ai)
255260

256261

262+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
257263
def test_put_along_axis1():
258264
a = numpy.arange(64).reshape(4, 4, 4)
259265
ai = dpnp.array(a)
@@ -265,6 +271,7 @@ def test_put_along_axis1():
265271
numpy.testing.assert_array_equal(a, ai)
266272

267273

274+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
268275
def test_put_along_axis2():
269276
a = numpy.arange(64).reshape(4, 4, 4)
270277
ai = dpnp.array(a)
@@ -411,6 +418,7 @@ def test_take(array, indices, array_type, indices_type):
411418
numpy.testing.assert_array_equal(expected, result)
412419

413420

421+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
414422
def test_take_along_axis():
415423
a = numpy.arange(16).reshape(4, 4)
416424
ai = dpnp.array(a)
@@ -422,6 +430,7 @@ def test_take_along_axis():
422430
numpy.testing.assert_array_equal(expected, result)
423431

424432

433+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
425434
def test_take_along_axis1():
426435
a = numpy.arange(64).reshape(4, 4, 4)
427436
ai = dpnp.array(a)

tests/test_linalg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def test_det(array):
8585
numpy.testing.assert_allclose(expected, result)
8686

8787

88+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
8889
@pytest.mark.parametrize("type",
8990
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
9091
ids=['float64', 'float32', 'int64', 'int32'])
@@ -179,6 +180,7 @@ def test_matrix_rank(type, tol, array):
179180
numpy.testing.assert_allclose(expected, result)
180181

181182

183+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
182184
@pytest.mark.parametrize("array",
183185
[[7], [1, 2], [1, 0]],
184186
ids=['[7]', '[1, 2]', '[1, 0]'])
@@ -196,6 +198,7 @@ def test_norm1(array, ord, axis):
196198
numpy.testing.assert_allclose(expected, result)
197199

198200

201+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
199202
@pytest.mark.parametrize("array",
200203
[[[1, 0]], [[1, 2]], [[1, 0], [3, 0]], [[1, 2], [3, 4]]],
201204
ids=['[[1, 0]]', '[[1, 2]]', '[[1, 0], [3, 0]]', '[[1, 2], [3, 4]]'])
@@ -213,6 +216,7 @@ def test_norm2(array, ord, axis):
213216
numpy.testing.assert_array_equal(expected, result)
214217

215218

219+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
216220
@pytest.mark.parametrize("array",
217221
[[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[1, 0], [3, 0]], [[5, 0], [7, 0]]]],
218222
ids=['[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]', '[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]'])
@@ -230,6 +234,7 @@ def test_norm3(array, ord, axis):
230234
numpy.testing.assert_array_equal(expected, result)
231235

232236

237+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
233238
@pytest.mark.parametrize("type",
234239
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
235240
ids=['float64', 'float32', 'int64', 'int32'])
@@ -273,6 +278,7 @@ def test_qr(type, shape, mode):
273278
numpy.testing.assert_allclose(dpnp_r, np_r, rtol=tol, atol=tol)
274279

275280

281+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
276282
@pytest.mark.parametrize("type",
277283
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
278284
ids=['float64', 'float32', 'int64', 'int32'])

0 commit comments

Comments
 (0)