Skip to content

Commit 58e859a

Browse files
Review comments
1 parent f0d5cfb commit 58e859a

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

dpnp/dpnp_iface_manipulation.py

+3
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,9 @@ def atleast_1d(*arys):
958958
dpnp.check_supported_arrays_type(*arys)
959959
for ary in arys:
960960
if ary.ndim == 0:
961+
# Scalars cannot be empty
962+
# Scalars always have a size of 1, so
963+
# reshape(1) is guaranteed to succeed
961964
result = ary.reshape(1)
962965
else:
963966
result = ary

dpnp/dpnp_iface_statistics.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,9 @@ def convolve(a, v, mode="full", method="auto"):
392392
Parameters
393393
----------
394394
a : {dpnp.ndarray, usm_ndarray}
395-
First 1-D array.
395+
First input array.
396396
v : {dpnp.ndarray, usm_ndarray}
397-
Second 1-D array. The length of `v` must be less than or equal to
398-
the length of `a`.
397+
Second input array.
399398
mode : {'full', 'valid', 'same'}, optional
400399
- 'full': This returns the convolution
401400
at each point of overlap, with an output shape of (N+M-1,). At
@@ -475,7 +474,7 @@ def convolve(a, v, mode="full", method="auto"):
475474
476475
"""
477476

478-
dpnp.check_supported_arrays_type(a, v)
477+
a, v = dpnp.atleast_1d(a, v)
479478

480479
if a.size == 0 or v.size == 0:
481480
raise ValueError(
@@ -488,11 +487,6 @@ def convolve(a, v, mode="full", method="auto"):
488487
f"Received shapes: a.shape={a.shape}, v.shape={v.shape}"
489488
)
490489

491-
if a.ndim == 0:
492-
a = dpnp.reshape(a, (1,))
493-
if v.ndim == 0:
494-
v = dpnp.reshape(v, (1,))
495-
496490
device = a.sycl_device
497491
rdtype = result_type_for_device([a.dtype, v.dtype], device)
498492

dpnp/tests/test_statistics.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ def _get_kwargs(mode=None, method=None):
140140
dpnp_kwargs["method"] = method
141141
return dpnp_kwargs, numpy_kwargs
142142

143-
def setup_method(self):
144-
numpy.random.seed(0)
145-
146143
@pytest.mark.parametrize(
147144
"a, v", [([1], [1, 2, 3]), ([1, 2, 3], [1]), ([1, 2, 3], [1, 2])]
148145
)
@@ -171,10 +168,10 @@ def test_convolve_random(self, a_size, v_size, mode, dtype, method):
171168
if dtype in [numpy.int8, numpy.uint8, numpy.int16, numpy.uint16]:
172169
pytest.skip("avoid overflow.")
173170
an = generate_random_numpy_array(
174-
a_size, dtype, low=-3, high=3, probability=0.9
171+
a_size, dtype, low=-3, high=3, probability=0.9, seed_value=0
175172
)
176173
vn = generate_random_numpy_array(
177-
v_size, dtype, low=-3, high=3, probability=0.9
174+
v_size, dtype, low=-3, high=3, probability=0.9, seed_value=1
178175
)
179176

180177
ad = dpnp.array(an)
@@ -282,8 +279,12 @@ def test_convolve_shape_error(self, a, v):
282279

283280
@pytest.mark.parametrize("size", [2, 10**1, 10**2, 10**3, 10**4, 10**5])
284281
def test_convolve_different_sizes(self, size):
285-
a = generate_random_numpy_array(size, dtype=numpy.float32, low=0, high=1)
286-
v = generate_random_numpy_array(size // 2, dtype=numpy.float32, low=0, high=1)
282+
a = generate_random_numpy_array(
283+
size, dtype=numpy.float32, low=0, high=1, seed_value=0
284+
)
285+
v = generate_random_numpy_array(
286+
size // 2, dtype=numpy.float32, low=0, high=1, seed_value=1
287+
)
287288

288289
ad = dpnp.array(a)
289290
vd = dpnp.array(v)
@@ -375,9 +376,6 @@ def _get_kwargs(mode=None, method=None):
375376
dpnp_kwargs["method"] = method
376377
return dpnp_kwargs, numpy_kwargs
377378

378-
def setup_method(self):
379-
numpy.random.seed(0)
380-
381379
@pytest.mark.parametrize(
382380
"a, v", [([1], [1, 2, 3]), ([1, 2, 3], [1]), ([1, 2, 3], [1, 2])]
383381
)
@@ -406,10 +404,10 @@ def test_correlate_random(self, a_size, v_size, mode, dtype, method):
406404
if dtype in [numpy.int8, numpy.uint8, numpy.int16, numpy.uint16]:
407405
pytest.skip("avoid overflow.")
408406
an = generate_random_numpy_array(
409-
a_size, dtype, low=-3, high=3, probability=0.9
407+
a_size, dtype, low=-3, high=3, probability=0.9, seed_value=0
410408
)
411409
vn = generate_random_numpy_array(
412-
v_size, dtype, low=-3, high=3, probability=0.9
410+
v_size, dtype, low=-3, high=3, probability=0.9, seed_value=1
413411
)
414412

415413
ad = dpnp.array(an)
@@ -505,8 +503,12 @@ def test_correlate_shape_error(self, a, v):
505503

506504
@pytest.mark.parametrize("size", [2, 10**1, 10**2, 10**3, 10**4, 10**5])
507505
def test_correlate_different_sizes(self, size):
508-
a = numpy.random.rand(size).astype(numpy.float32)
509-
v = numpy.random.rand(size // 2).astype(numpy.float32)
506+
a = generate_random_numpy_array(
507+
size, dtype=numpy.float32, low=0, high=1, seed_value=0
508+
)
509+
v = generate_random_numpy_array(
510+
size // 2, dtype=numpy.float32, low=0, high=1, seed_value=1
511+
)
510512

511513
ad = dpnp.array(a)
512514
vd = dpnp.array(v)

dpnp/tests/third_party/cupy/math_tests/test_misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,14 @@ def test_convolve(self, xp, dtype):
545545
class TestConvolve:
546546

547547
@testing.for_all_dtypes(no_float16=True)
548-
@testing.numpy_cupy_allclose(rtol=1e-6, type_check=has_support_aspect64())
548+
@testing.numpy_cupy_allclose(rtol=1e-6)
549549
def test_convolve_non_contiguous(self, xp, dtype, mode):
550550
a = testing.shaped_arange((300,), xp, dtype)
551551
b = testing.shaped_arange((100,), xp, dtype)
552552
return xp.convolve(a[::200], b[10::70], mode=mode)
553553

554554
@testing.for_all_dtypes(no_float16=True)
555-
@testing.numpy_cupy_allclose(rtol=5e-4, type_check=has_support_aspect64())
555+
@testing.numpy_cupy_allclose(rtol=5e-4)
556556
def test_convolve_large_non_contiguous(self, xp, dtype, mode):
557557
a = testing.shaped_arange((10000,), xp, dtype)
558558
b = testing.shaped_arange((100,), xp, dtype)

0 commit comments

Comments
 (0)