Skip to content

Commit 6d3f817

Browse files
committed
address comments - first round
cherry-pick
1 parent 2a38192 commit 6d3f817

File tree

7 files changed

+65
-108
lines changed

7 files changed

+65
-108
lines changed

dpnp/dpnp_array.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,31 +1039,6 @@ def prod(
10391039

10401040
return dpnp.prod(self, axis, dtype, out, keepdims, initial, where)
10411041

1042-
def ptp(
1043-
self,
1044-
axis=None,
1045-
out=None,
1046-
keepdims=numpy._NoValue,
1047-
device=None,
1048-
usm_type=None,
1049-
sycl_queue=None,
1050-
):
1051-
"""
1052-
Range of values (maximum - minimum) along an axis.
1053-
1054-
For full documentation refer to :obj:`numpy.ptp`.
1055-
"""
1056-
1057-
return dpnp.ptp(
1058-
self,
1059-
axis=axis,
1060-
out=out,
1061-
keepdims=keepdims,
1062-
device=device,
1063-
usm_type=usm_type,
1064-
sycl_queue=sycl_queue,
1065-
)
1066-
10671042
def put(self, indices, vals, /, *, axis=None, mode="wrap"):
10681043
"""
10691044
Puts values of an array into another array along a given axis.

dpnp/dpnp_iface_arraycreation.py

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"ogrid",
8787
"ones",
8888
"ones_like",
89-
"ptp",
9089
"trace",
9190
"tri",
9291
"tril",
@@ -1649,69 +1648,6 @@ def ones_like(
16491648
return call_origin(numpy.ones_like, x1, dtype, order, subok, shape)
16501649

16511650

1652-
def ptp(
1653-
arr,
1654-
/,
1655-
axis=None,
1656-
out=None,
1657-
keepdims=numpy._NoValue,
1658-
*,
1659-
device=None,
1660-
usm_type=None,
1661-
sycl_queue=None,
1662-
):
1663-
"""
1664-
Range of values (maximum - minimum) along an axis.
1665-
1666-
For full documentation refer to :obj:`numpy.ptp`.
1667-
1668-
Returns
1669-
-------
1670-
ptp : dpnp.ndarray
1671-
The range of a given array.
1672-
1673-
Limitations
1674-
-----------
1675-
Input array is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
1676-
Parameters `out` and `keepdims` are supported only with default values.
1677-
Otherwise the function will be executed sequentially on CPU.
1678-
1679-
Examples
1680-
--------
1681-
>>> import dpnp as np
1682-
>>> x = np.array([[4, 9, 2, 10],[6, 9, 7, 12]])
1683-
>>> np.ptp(x, axis=1)
1684-
array([8, 6])
1685-
1686-
>>> np.ptp(x, axis=0)
1687-
array([2, 0, 5, 2])
1688-
1689-
>>> np.ptp(x)
1690-
array(10)
1691-
"""
1692-
if not isinstance(arr, (dpnp.ndarray, dpt.usm_ndarray)):
1693-
pass
1694-
elif axis is not None and not isinstance(axis, int):
1695-
pass
1696-
elif out is not None:
1697-
pass
1698-
elif keepdims is not numpy._NoValue:
1699-
pass
1700-
else:
1701-
max_array = dpnp.max(arr, axis=axis)
1702-
min_array = dpnp.min(arr, axis=axis)
1703-
1704-
_usm_type = arr.usm_type if usm_type is None else usm_type
1705-
_sycl_queue = dpnp.get_normalized_queue_device(
1706-
arr, sycl_queue=sycl_queue, device=device
1707-
)
1708-
return dpnp.array(
1709-
max_array - min_array, usm_type=_usm_type, sycl_queue=_sycl_queue
1710-
)
1711-
1712-
return call_origin(numpy.ptp, arr, axis, out, keepdims)
1713-
1714-
17151651
def trace(x1, offset=0, axis1=0, axis2=1, dtype=None, out=None):
17161652
"""
17171653
Return the sum along diagonals of the array.

dpnp/dpnp_iface_statistics.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"mean",
6161
"median",
6262
"min",
63+
"ptp",
6364
"nanvar",
6465
"std",
6566
"var",
@@ -692,6 +693,55 @@ def min(a, axis=None, out=None, keepdims=False, initial=None, where=True):
692693
return out
693694

694695

696+
def ptp(
697+
a,
698+
/,
699+
axis=None,
700+
out=None,
701+
keepdims=False,
702+
):
703+
"""
704+
Range of values (maximum - minimum) along an axis.
705+
706+
For full documentation refer to :obj:`numpy.ptp`.
707+
708+
Returns
709+
-------
710+
ptp : dpnp.ndarray
711+
The range of a given array.
712+
713+
Limitations
714+
-----------
715+
Input array is supported as :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
716+
Otherwise the function will be executed sequentially on CPU.
717+
718+
Examples
719+
--------
720+
>>> import dpnp as np
721+
>>> x = np.array([[4, 9, 2, 10],[6, 9, 7, 12]])
722+
>>> np.ptp(x, axis=1)
723+
array([8, 6])
724+
725+
>>> np.ptp(x, axis=0)
726+
array([2, 0, 5, 2])
727+
728+
>>> np.ptp(x)
729+
array(10)
730+
731+
"""
732+
733+
if not isinstance(a, (dpnp.ndarray, dpt.usm_ndarray)):
734+
pass
735+
else:
736+
return dpnp.subtract(
737+
dpnp.max(a, axis=axis, keepdims=keepdims),
738+
dpnp.min(a, axis=axis, keepdims=keepdims),
739+
out=out,
740+
)
741+
742+
return call_origin(numpy.ptp, a, axis, out, keepdims)
743+
744+
695745
def nanvar(x1, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
696746
"""
697747
Compute the variance along the specified axis, while ignoring NaNs.

tests/skipped_tests_gpu.tbl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py::TestArrayFlatte
199199
tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py::TestArrayFlatten::test_flatten_order_copied
200200
tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py::TestArrayFlatten::test_flatten_order_transposed
201201

202-
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestArrayReduction::test_ptp_nan
203-
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestArrayReduction::test_ptp_nan_imag
204-
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestArrayReduction::test_ptp_nan_real
202+
205203

206204
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_0_{order='C', shape=(10,)}::test_cub_max
207205
tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_0_{order='C', shape=(10,)}::test_cub_min

tests/test_sycl_queue.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,11 @@ def test_array_creation_follow_device_logspace_base(device):
199199
assert_sycl_queue_equal(y.sycl_queue, x.sycl_queue)
200200

201201

202-
@pytest.mark.skip("muted until the issue reported by SAT-5969 is resolved")
203202
@pytest.mark.parametrize(
204203
"func, args, kwargs",
205204
[
206205
pytest.param("diag", ["x0"], {}),
207206
pytest.param("diagflat", ["x0"], {}),
208-
pytest.param("ptp", ["x0"], {"axis": 0}),
209207
],
210208
)
211209
@pytest.mark.parametrize(
@@ -226,6 +224,7 @@ def test_array_creation_follow_device_2d_array(func, args, kwargs, device):
226224
assert_sycl_queue_equal(y.sycl_queue, x.sycl_queue)
227225

228226

227+
@pytest.mark.skip("muted until the issue reported by SAT-5969 is resolved")
229228
@pytest.mark.parametrize(
230229
"func, args, kwargs",
231230
[
@@ -276,7 +275,6 @@ def test_array_creation_cross_device(func, args, kwargs, device_x, device_y):
276275
[
277276
pytest.param("diag", ["x0"], {}),
278277
pytest.param("diagflat", ["x0"], {}),
279-
pytest.param("ptp", ["x0"], {"axis": 0}),
280278
],
281279
)
282280
@pytest.mark.parametrize(
@@ -375,6 +373,7 @@ def test_meshgrid(device_x, device_y):
375373
pytest.param("negative", [1.0, 0.0, -1.0]),
376374
pytest.param("positive", [1.0, 0.0, -1.0]),
377375
pytest.param("prod", [1.0, 2.0]),
376+
pytest.param("ptp", [1.0, 2.0, 4.0, 7.0]),
378377
pytest.param(
379378
"real", [complex(1.0, 2.0), complex(3.0, 4.0), complex(5.0, 6.0)]
380379
),

tests/test_usm_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ def test_array_creation_from_1d_array(func, args, usm_type_x, usm_type_y):
179179
[
180180
pytest.param("diag", ["x0"]),
181181
pytest.param("diagflat", ["x0"]),
182-
pytest.param("ptp", ["x0", "0"]),
183182
],
184183
)
185184
@pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
@@ -403,6 +402,7 @@ def test_meshgrid(usm_type_x, usm_type_y):
403402
pytest.param("positive", [1.0, 0.0, -1.0]),
404403
pytest.param("prod", [1.0, 2.0]),
405404
pytest.param("proj", [complex(1.0, 2.0), complex(dp.inf, -1.0)]),
405+
pytest.param("ptp", [1.0, 2.0, 4.0, 7.0]),
406406
pytest.param(
407407
"real", [complex(1.0, 2.0), complex(3.0, 4.0), complex(5.0, 6.0)]
408408
),

tests/third_party/cupy/core_tests/test_ndarray_reduction.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from tests.third_party.cupy import testing
1010

1111

12-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
1312
@testing.gpu
1413
class TestArrayReduction(unittest.TestCase):
1514
@testing.for_all_dtypes()
@@ -149,70 +148,70 @@ def test_min_nan_imag(self, xp, dtype):
149148
@testing.numpy_cupy_allclose()
150149
def test_ptp_all(self, xp, dtype):
151150
a = testing.shaped_random((2, 3), xp, dtype)
152-
return a.ptp()
151+
return xp.ptp(a)
153152

154153
@testing.with_requires("numpy>=1.15")
155154
@testing.for_all_dtypes(no_bool=True)
156155
@testing.numpy_cupy_allclose()
157156
def test_ptp_all_keepdims(self, xp, dtype):
158157
a = testing.shaped_random((2, 3), xp, dtype)
159-
return a.ptp(keepdims=True)
158+
return xp.ptp(a, keepdims=True)
160159

161160
@testing.for_all_dtypes(no_bool=True)
162161
@testing.numpy_cupy_allclose()
163162
def test_ptp_axis_large(self, xp, dtype):
164163
a = testing.shaped_random((3, 1000), xp, dtype)
165-
return a.ptp(axis=0)
164+
return xp.ptp(a, axis=0)
166165

167166
@testing.for_all_dtypes(no_bool=True)
168167
@testing.numpy_cupy_allclose()
169168
def test_ptp_axis0(self, xp, dtype):
170169
a = testing.shaped_random((2, 3, 4), xp, dtype)
171-
return a.ptp(axis=0)
170+
return xp.ptp(a, axis=0)
172171

173172
@testing.for_all_dtypes(no_bool=True)
174173
@testing.numpy_cupy_allclose()
175174
def test_ptp_axis1(self, xp, dtype):
176175
a = testing.shaped_random((2, 3, 4), xp, dtype)
177-
return a.ptp(axis=1)
176+
return xp.ptp(a, axis=1)
178177

179178
@testing.for_all_dtypes(no_bool=True)
180179
@testing.numpy_cupy_allclose()
181180
def test_ptp_axis2(self, xp, dtype):
182181
a = testing.shaped_random((2, 3, 4), xp, dtype)
183-
return a.ptp(axis=2)
182+
return xp.ptp(a, axis=2)
184183

185184
@testing.with_requires("numpy>=1.15")
186185
@testing.for_all_dtypes(no_bool=True)
187186
@testing.numpy_cupy_allclose()
188187
def test_ptp_multiple_axes(self, xp, dtype):
189188
a = testing.shaped_random((2, 3, 4), xp, dtype)
190-
return a.ptp(axis=(1, 2))
189+
return xp.ptp(a, axis=(1, 2))
191190

192191
@testing.with_requires("numpy>=1.15")
193192
@testing.for_all_dtypes(no_bool=True)
194193
@testing.numpy_cupy_allclose()
195194
def test_ptp_multiple_axes_keepdims(self, xp, dtype):
196195
a = testing.shaped_random((2, 3, 4), xp, dtype)
197-
return a.ptp(axis=(1, 2), keepdims=True)
196+
return xp.ptp(a, axis=(1, 2), keepdims=True)
198197

199198
@testing.for_float_dtypes()
200199
@testing.numpy_cupy_allclose()
201200
def test_ptp_nan(self, xp, dtype):
202201
a = xp.array([float("nan"), 1, -1], dtype)
203-
return a.ptp()
202+
return xp.ptp(a)
204203

205204
@testing.for_complex_dtypes()
206205
@testing.numpy_cupy_allclose()
207206
def test_ptp_nan_real(self, xp, dtype):
208207
a = xp.array([float("nan"), 1, -1], dtype)
209-
return a.ptp()
208+
return xp.ptp(a)
210209

211210
@testing.for_complex_dtypes()
212211
@testing.numpy_cupy_allclose()
213212
def test_ptp_nan_imag(self, xp, dtype):
214213
a = xp.array([float("nan") * 1.0j, 1.0j, -1.0j], dtype)
215-
return a.ptp()
214+
return xp.ptp(a)
216215

217216

218217
@testing.parameterize(

0 commit comments

Comments
 (0)