From 4159a7fb1fc60c21ba8086dab710c8cc1b4c031e Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 22 Aug 2023 14:19:15 +0200 Subject: [PATCH 01/10] Leverage dpctl.tensor.expand_dims impl --- dpnp/dpnp_algo/dpnp_algo_manipulation.pxi | 30 --------------- dpnp/dpnp_iface_manipulation.py | 38 ++++++++++++++++--- .../cupy/manipulation_tests/test_dims.py | 5 +++ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi b/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi index 94a58b057bf..98ffc34bf07 100644 --- a/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi @@ -39,7 +39,6 @@ __all__ += [ "dpnp_atleast_2d", "dpnp_atleast_3d", "dpnp_copyto", - "dpnp_expand_dims", "dpnp_repeat", "dpnp_reshape", ] @@ -144,35 +143,6 @@ cpdef dpnp_copyto(utils.dpnp_descriptor dst, utils.dpnp_descriptor src, where=Tr c_dpctl.DPCTLEvent_Delete(event_ref) -cpdef utils.dpnp_descriptor dpnp_expand_dims(utils.dpnp_descriptor in_array, axis): - axis_tuple = utils._object_to_tuple(axis) - result_ndim = len(axis_tuple) + in_array.ndim - - if len(axis_tuple) == 0: - axis_ndim = 0 - else: - axis_ndim = max(-min(0, min(axis_tuple)), max(0, max(axis_tuple))) + 1 - - axis_norm = utils._object_to_tuple(utils.normalize_axis(axis_tuple, result_ndim)) - - if axis_ndim - len(axis_norm) > in_array.ndim: - utils.checker_throw_axis_error("dpnp_expand_dims", "axis", axis, axis_ndim) - - if len(axis_norm) > len(set(axis_norm)): - utils.checker_throw_value_error("dpnp_expand_dims", "axis", axis, "no repeated axis") - - cdef shape_type_c shape_list - axis_idx = 0 - for i in range(result_ndim): - if i in axis_norm: - shape_list.push_back(1) - else: - shape_list.push_back(in_array.shape[axis_idx]) - axis_idx = axis_idx + 1 - - return dpnp_reshape(in_array, shape_list) - - cpdef utils.dpnp_descriptor dpnp_repeat(utils.dpnp_descriptor array1, repeats, axes=None): cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 5f5dcb3617d..81351160246 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -373,7 +373,7 @@ def copyto(dst, src, casting="same_kind", where=True): ) -def expand_dims(x1, axis): +def expand_dims(x, axis): """ Expand the shape of an array. @@ -382,6 +382,30 @@ def expand_dims(x1, axis): For full documentation refer to :obj:`numpy.expand_dims`. + Returns + ------- + dpnp.ndarray + An array with the number of dimensions increased. + A view is returned whenever possible. + + Limitations + ----------- + Parameters `x` is supported either as :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. + Input array data types are limited by supported DPNP :ref:`Data types`. + Otherwise ``TypeError`` exception will be raised. + + Notes + ----- + If `x` has rank (i.e, number of dimensions) `N`, a valid `axis` must reside + in the closed-interval `[-N-1, N]`. + If provided a negative `axis`, the `axis` position at which to insert a + singleton dimension is computed as `N + axis + 1`. + Hence, if provided `-1`, the resolved axis position is `N` (i.e., + a singleton dimension must be appended to the input array `x`). + If provided `-N-1`, the resolved axis position is `0` (i.e., a + singleton dimension is prepended to the input array `x`). + See Also -------- :obj:`dpnp.squeeze` : The inverse operation, removing singleton dimensions @@ -431,11 +455,15 @@ def expand_dims(x1, axis): """ - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if x1_desc: - return dpnp_expand_dims(x1_desc, axis).get_pyobj() + if not dpnp.is_supported_array_type(x): + raise TypeError( + f"An array must be any of supported type, but got {type(x)}" + ) - return call_origin(numpy.expand_dims, x1, axis) + dpt_array = dpnp.get_usm_ndarray(x) + return dpnp_array._create_from_usm_ndarray( + dpt.expand_dims(dpt_array, axis=axis) + ) def hstack(tup): diff --git a/tests/third_party/cupy/manipulation_tests/test_dims.py b/tests/third_party/cupy/manipulation_tests/test_dims.py index 6d59f064051..a781b064b84 100644 --- a/tests/third_party/cupy/manipulation_tests/test_dims.py +++ b/tests/third_party/cupy/manipulation_tests/test_dims.py @@ -159,6 +159,11 @@ def test_expand_dims_repeated_axis(self): with pytest.raises(ValueError): xp.expand_dims(a, (1, 1)) + def test_expand_dims_invalid_type(self): + a = testing.shaped_arange((2, 2), numpy) + with pytest.raises(TypeError): + cupy.expand_dims(a, 1) + @testing.numpy_cupy_array_equal() def test_squeeze1(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) From 17b8392c57e4b3355b92c869138028049eaf6eec Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Tue, 22 Aug 2023 15:24:45 +0200 Subject: [PATCH 02/10] Leverage dpctl.tensor.swapaxes impl --- dpnp/dpnp_array.py | 9 +++- dpnp/dpnp_iface_manipulation.py | 44 +++++++++++-------- .../cupy/linalg_tests/test_eigenvalue.py | 9 +--- .../cupy/manipulation_tests/test_transpose.py | 6 ++- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 717cb9c4f52..0c33e1a25c3 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -1059,7 +1059,14 @@ def sum( where=where, ) - # 'swapaxes', + def swapaxes(self, axis1, axis2): + """ + Interchange two axes of an array. + + For full documentation refer to :obj:`numpy.swapaxes`. + """ + + return dpnp.swapaxes(self, axis1=axis1, axis2=axis2) def take(self, indices, /, *, axis=None, out=None, mode="wrap"): """ diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 81351160246..1ba1868bd83 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -934,12 +934,17 @@ def stack(arrays, /, *, axis=0, out=None, dtype=None, **kwargs): ) -def swapaxes(x1, axis1, axis2): +def swapaxes(x, axis1, axis2): """ Interchange two axes of an array. For full documentation refer to :obj:`numpy.swapaxes`. + Returns + ------- + dpnp.ndarray + An array with with swapped axes. + Limitations ----------- Input array is supported as :obj:`dpnp.ndarray`. @@ -948,6 +953,18 @@ def swapaxes(x1, axis1, axis2): Parameter ``axis2`` is limited by ``axis2 < x1.ndim``. Input array data types are limited by supported DPNP :ref:`Data types`. + Limitations + ----------- + Parameters `x` is supported either as :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. + Input array data types are limited by supported DPNP :ref:`Data types`. + Otherwise ``TypeError`` exception will be raised. + + Notes + ----- + If `x` has rank (i.e., number of dimensions) `N`, + a valid `axis` must be in the half-open interval `[-N, N)`. + Examples -------- >>> import dpnp as np @@ -960,24 +977,15 @@ def swapaxes(x1, axis1, axis2): """ - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if x1_desc: - if axis1 >= x1_desc.ndim: - pass - elif axis2 >= x1_desc.ndim: - pass - else: - # 'do nothing' pattern for transpose() - input_permute = [i for i in range(x1.ndim)] - # swap axes - input_permute[axis1], input_permute[axis2] = ( - input_permute[axis2], - input_permute[axis1], - ) - - return transpose(x1_desc.get_pyobj(), axes=input_permute) + if not dpnp.is_supported_array_type(x): + raise TypeError( + f"An array must be any of supported type, but got {type(x)}" + ) - return call_origin(numpy.swapaxes, x1, axis1, axis2) + dpt_array = dpnp.get_usm_ndarray(x) + return dpnp_array._create_from_usm_ndarray( + dpt.swapaxes(dpt_array, axis1=axis1, axis2=axis2) + ) def transpose(a, axes=None): diff --git a/tests/third_party/cupy/linalg_tests/test_eigenvalue.py b/tests/third_party/cupy/linalg_tests/test_eigenvalue.py index b5a73c25e95..c67fd1baee6 100644 --- a/tests/third_party/cupy/linalg_tests/test_eigenvalue.py +++ b/tests/third_party/cupy/linalg_tests/test_eigenvalue.py @@ -8,15 +8,10 @@ def _get_hermitian(xp, a, UPLO): - # TODO: remove wrapping, but now there is no dpnp_array.swapaxes() - a = _wrap_as_numpy_array(xp, a) - _xp = numpy - if UPLO == "U": - _a = _xp.triu(a) + _xp.triu(a, k=1).swapaxes(-2, -1).conj() + return xp.triu(a) + xp.triu(a, k=1).swapaxes(-2, -1).conj() else: - _a = _xp.tril(a) + _xp.tril(a, k=-1).swapaxes(-2, -1).conj() - return xp.array(_a) + return xp.tril(a) + xp.tril(a, k=-1).swapaxes(-2, -1).conj() # TODO: remove once all required functionality is supported diff --git a/tests/third_party/cupy/manipulation_tests/test_transpose.py b/tests/third_party/cupy/manipulation_tests/test_transpose.py index ad71ad41b4b..0301419dc4d 100644 --- a/tests/third_party/cupy/manipulation_tests/test_transpose.py +++ b/tests/third_party/cupy/manipulation_tests/test_transpose.py @@ -115,13 +115,17 @@ def test_swapaxes(self, xp): a = testing.shaped_arange((2, 3, 4), xp) return xp.swapaxes(a, 2, 0) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_swapaxes_failure(self): for xp in (numpy, cupy): a = testing.shaped_arange((2, 3, 4), xp) with pytest.raises(ValueError): xp.swapaxes(a, 3, 0) + def test_swapaxes_invalid_type(self): + a = testing.shaped_arange((2, 3, 4), numpy) + with pytest.raises(TypeError): + cupy.swapaxes(a, 1, 0) + @testing.numpy_cupy_array_equal() def test_transpose(self, xp): a = testing.shaped_arange((2, 3, 4), xp) From d178fa6d492cb3374c00cbb9231528674f57779d Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 11:03:57 +0200 Subject: [PATCH 03/10] Apply review remarks --- dpnp/dpnp_iface_manipulation.py | 42 ++++++++----------- tests/test_manipulation.py | 12 ++++++ .../cupy/manipulation_tests/test_dims.py | 5 --- .../cupy/manipulation_tests/test_transpose.py | 5 --- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index efe1f3e101c..b58c1365697 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -425,7 +425,7 @@ def expand_dims(x, axis): -------- :obj:`dpnp.squeeze` : The inverse operation, removing singleton dimensions :obj:`dpnp.reshape` : Insert, remove, and combine dimensions, and resize existing ones - :obj:`dpnp.indexing`, :obj:`dpnp.atleast_1d`, :obj:`dpnp.atleast_2d`, :obj:`dpnp.atleast_3d` + :obj:`dpnp.atleast_1d`, :obj:`dpnp.atleast_2d`, :obj:`dpnp.atleast_3d` Examples -------- @@ -470,11 +470,6 @@ def expand_dims(x, axis): """ - if not dpnp.is_supported_array_type(x): - raise TypeError( - f"An array must be any of supported type, but got {type(x)}" - ) - dpt_array = dpnp.get_usm_ndarray(x) return dpnp_array._create_from_usm_ndarray( dpt.expand_dims(dpt_array, axis=axis) @@ -959,14 +954,7 @@ def swapaxes(x, axis1, axis2): ------- dpnp.ndarray An array with with swapped axes. - - Limitations - ----------- - Input array is supported as :obj:`dpnp.ndarray`. - Otherwise the function will be executed sequentially on CPU. - Parameter ``axis1`` is limited by ``axis1 < x1.ndim``. - Parameter ``axis2`` is limited by ``axis2 < x1.ndim``. - Input array data types are limited by supported DPNP :ref:`Data types`. + A view is returned whenever possible. Limitations ----------- @@ -984,19 +972,25 @@ def swapaxes(x, axis1, axis2): -------- >>> import dpnp as np >>> x = np.array([[1, 2, 3]]) - >>> out = np.swapaxes(x, 0, 1) - >>> out.shape - (3, 1) - >>> [i for i in out] - [1, 2, 3] + >>> np.swapaxes(x, 0, 1) + array([[1], + [2], + [3]]) + + >>> x = np.array([[[0,1],[2,3]],[[4,5],[6,7]]]) + >>> x + array([[[0, 1], + [2, 3]], + [[4, 5], + [6, 7]]]) + >>> np.swapaxes(x,0,2) + array([[[0, 4], + [2, 6]], + [[1, 5], + [3, 7]]]) """ - if not dpnp.is_supported_array_type(x): - raise TypeError( - f"An array must be any of supported type, but got {type(x)}" - ) - dpt_array = dpnp.get_usm_ndarray(x) return dpnp_array._create_from_usm_ndarray( dpt.swapaxes(dpt_array, axis1=axis1, axis2=axis2) diff --git a/tests/test_manipulation.py b/tests/test_manipulation.py index 576229b1d56..4d9c6d0e159 100644 --- a/tests/test_manipulation.py +++ b/tests/test_manipulation.py @@ -136,3 +136,15 @@ def test_none_axes(self, shape): assert_array_equal(na.transpose(), da.transpose()) assert_array_equal(na.transpose(None), da.transpose(None)) + + +def test_expand_dims_invalid_type(): + na = numpy.ones((2, 2)) + with pytest.raises(TypeError): + numpy.expand_dims(na, 1) + + +def test_swapaxes_invalid_type(): + na = numpy.ones((2, 3, 4)) + with pytest.raises(TypeError): + dpnp.swapaxes(na, 1, 0) diff --git a/tests/third_party/cupy/manipulation_tests/test_dims.py b/tests/third_party/cupy/manipulation_tests/test_dims.py index a781b064b84..6d59f064051 100644 --- a/tests/third_party/cupy/manipulation_tests/test_dims.py +++ b/tests/third_party/cupy/manipulation_tests/test_dims.py @@ -159,11 +159,6 @@ def test_expand_dims_repeated_axis(self): with pytest.raises(ValueError): xp.expand_dims(a, (1, 1)) - def test_expand_dims_invalid_type(self): - a = testing.shaped_arange((2, 2), numpy) - with pytest.raises(TypeError): - cupy.expand_dims(a, 1) - @testing.numpy_cupy_array_equal() def test_squeeze1(self, xp): a = testing.shaped_arange((1, 2, 1, 3, 1, 1, 4, 1), xp) diff --git a/tests/third_party/cupy/manipulation_tests/test_transpose.py b/tests/third_party/cupy/manipulation_tests/test_transpose.py index 0301419dc4d..07cbf4eb31c 100644 --- a/tests/third_party/cupy/manipulation_tests/test_transpose.py +++ b/tests/third_party/cupy/manipulation_tests/test_transpose.py @@ -121,11 +121,6 @@ def test_swapaxes_failure(self): with pytest.raises(ValueError): xp.swapaxes(a, 3, 0) - def test_swapaxes_invalid_type(self): - a = testing.shaped_arange((2, 3, 4), numpy) - with pytest.raises(TypeError): - cupy.swapaxes(a, 1, 0) - @testing.numpy_cupy_array_equal() def test_transpose(self, xp): a = testing.shaped_arange((2, 3, 4), xp) From 44c7fb2644e725380bee189d6eda22f6c6eb12a1 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 11:27:03 +0200 Subject: [PATCH 04/10] Align args names to numpy --- dpnp/dpnp_iface_manipulation.py | 118 ++++++++++++++++---------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index b58c1365697..7f327cb91c6 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -75,7 +75,7 @@ ] -def asfarray(x1, dtype=None): +def asfarray(a, dtype=None): """ Return an array converted to a float type. @@ -89,18 +89,18 @@ def asfarray(x1, dtype=None): """ - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if x1_desc: + a_desc = dpnp.get_dpnp_descriptor(a, copy_when_nondefault_queue=False) + if a_desc: if dtype is None or not numpy.issubdtype(dtype, dpnp.inexact): - dtype = dpnp.default_float_type(sycl_queue=x1.sycl_queue) + dtype = dpnp.default_float_type(sycl_queue=a.sycl_queue) # if type is the same then same object should be returned - if x1_desc.dtype == dtype: - return x1 + if a_desc.dtype == dtype: + return a - return array(x1, dtype=dtype) + return array(a, dtype=dtype) - return call_origin(numpy.asfarray, x1, dtype) + return call_origin(numpy.asfarray, a, dtype) def atleast_1d(*arys): @@ -197,7 +197,7 @@ def atleast_3d(*arys): return call_origin(numpy.atleast_3d, *arys) -def broadcast_to(x, /, shape, subok=False): +def broadcast_to(array, /, shape, subok=False): """ Broadcast an array to a new shape. @@ -206,15 +206,15 @@ def broadcast_to(x, /, shape, subok=False): Returns ------- y : dpnp.ndarray - An array having a specified shape. Must have the same data type as `x`. + An array having a specified shape. Must have the same data type as `array`. Limitations ----------- - Parameter `x` is supported as either :class:`dpnp.ndarray` + Parameter `array` is supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Parameter `subok` is supported with default value. Otherwise the function will be executed sequentially on CPU. - Input array data types of `x` is limited by supported DPNP :ref:`Data types`. + Input array data types of `array` is limited by supported DPNP :ref:`Data types`. Examples -------- @@ -229,12 +229,14 @@ def broadcast_to(x, /, shape, subok=False): if subok is not False: pass - elif isinstance(x, dpnp_array) or isinstance(x, dpt.usm_ndarray): - dpt_array = x.get_array() if isinstance(x, dpnp_array) else x + elif isinstance(array, dpnp_array) or isinstance(array, dpt.usm_ndarray): + dpt_array = ( + array.get_array() if isinstance(array, dpnp_array) else array + ) new_array = dpt.broadcast_to(dpt_array, shape) return dpnp_array._create_from_usm_ndarray(new_array) - return call_origin(numpy.broadcast_to, x, shape=shape, subok=subok) + return call_origin(numpy.broadcast_to, array, shape=shape, subok=subok) def concatenate(arrays, /, *, axis=0, out=None, dtype=None, **kwargs): @@ -388,7 +390,7 @@ def copyto(dst, src, casting="same_kind", where=True): dst_usm[mask_usm] = src_usm[mask_usm] -def expand_dims(x, axis): +def expand_dims(a, axis): """ Expand the shape of an array. @@ -405,21 +407,21 @@ def expand_dims(x, axis): Limitations ----------- - Parameters `x` is supported either as :class:`dpnp.ndarray` + Parameters `a` is supported either as :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Input array data types are limited by supported DPNP :ref:`Data types`. Otherwise ``TypeError`` exception will be raised. Notes ----- - If `x` has rank (i.e, number of dimensions) `N`, a valid `axis` must reside + If `a` has rank (i.e, number of dimensions) `N`, a valid `axis` must reside in the closed-interval `[-N-1, N]`. If provided a negative `axis`, the `axis` position at which to insert a singleton dimension is computed as `N + axis + 1`. Hence, if provided `-1`, the resolved axis position is `N` (i.e., - a singleton dimension must be appended to the input array `x`). + a singleton dimension must be appended to the input array `a`). If provided `-N-1`, the resolved axis position is `0` (i.e., a - singleton dimension is prepended to the input array `x`). + singleton dimension is prepended to the input array `a`). See Also -------- @@ -470,7 +472,7 @@ def expand_dims(x, axis): """ - dpt_array = dpnp.get_usm_ndarray(x) + dpt_array = dpnp.get_usm_ndarray(a) return dpnp_array._create_from_usm_ndarray( dpt.expand_dims(dpt_array, axis=axis) ) @@ -495,7 +497,7 @@ def hstack(tup): return call_origin(numpy.hstack, tup_new) -def moveaxis(x, source, destination): +def moveaxis(a, source, destination): """ Move axes of an array to new positions. Other axes remain in their original order. @@ -506,11 +508,11 @@ def moveaxis(x, source, destination): out : dpnp.ndarray Array with moved axes. The returned array will have the same data and - the same USM allocation type as `x`. + the same USM allocation type as `a`. Limitations ----------- - Parameters `x` is supported as either :class:`dpnp.ndarray` + Parameters `a` is supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Otherwise the function will be executed sequentially on CPU. Input array data types are limited by supported DPNP :ref:`Data types`. @@ -531,16 +533,16 @@ def moveaxis(x, source, destination): """ - if isinstance(x, dpnp_array) or isinstance(x, dpt.usm_ndarray): - dpt_array = x.get_array() if isinstance(x, dpnp_array) else x + if isinstance(a, dpnp_array) or isinstance(a, dpt.usm_ndarray): + dpt_array = a.get_array() if isinstance(a, dpnp_array) else a return dpnp_array._create_from_usm_ndarray( dpt.moveaxis(dpt_array, source, destination) ) - return call_origin(numpy.moveaxis, x, source, destination) + return call_origin(numpy.moveaxis, a, source, destination) -def ravel(x1, order="C"): +def ravel(a, order="C"): """ Return a contiguous flattened array. @@ -562,14 +564,14 @@ def ravel(x1, order="C"): """ - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if x1_desc: - return dpnp_flatten(x1_desc).get_pyobj() + a_desc = dpnp.get_dpnp_descriptor(a, copy_when_nondefault_queue=False) + if a_desc: + return dpnp_flatten(a_desc).get_pyobj() - return call_origin(numpy.ravel, x1, order=order) + return call_origin(numpy.ravel, a, order=order) -def repeat(x1, repeats, axis=None): +def repeat(a, repeats, axis=None): """ Repeat elements of an array. @@ -595,22 +597,22 @@ def repeat(x1, repeats, axis=None): """ - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if x1_desc: + a_desc = dpnp.get_dpnp_descriptor(a, copy_when_nondefault_queue=False) + if a_desc: if axis is not None and axis != 0: pass - elif x1_desc.ndim >= 2: + elif a_desc.ndim >= 2: pass elif not dpnp.isscalar(repeats) and len(repeats) > 1: pass else: repeat_val = repeats if dpnp.isscalar(repeats) else repeats[0] - return dpnp_repeat(x1_desc, repeat_val, axis).get_pyobj() + return dpnp_repeat(a_desc, repeat_val, axis).get_pyobj() - return call_origin(numpy.repeat, x1, repeats, axis) + return call_origin(numpy.repeat, a, repeats, axis) -def reshape(x, /, newshape, order="C", copy=None): +def reshape(a, /, newshape, order="C", copy=None): """ Gives a new shape to an array without changing its data. @@ -618,7 +620,7 @@ def reshape(x, /, newshape, order="C", copy=None): Parameters ---------- - x : {dpnp_array, usm_ndarray} + a : {dpnp_array, usm_ndarray} Array to be reshaped. newshape : int or tuple of ints The new shape should be compatible with the original shape. If @@ -626,7 +628,7 @@ def reshape(x, /, newshape, order="C", copy=None): One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions. order : {'C', 'F'}, optional - Read the elements of `x` using this index order, and place the + Read the elements of `a` using this index order, and place the elements into the reshaped array using this index order. 'C' means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first @@ -637,10 +639,10 @@ def reshape(x, /, newshape, order="C", copy=None): the underlying array, and only refer to the order of indexing. copy : bool, optional Boolean indicating whether or not to copy the input array. - If ``True``, the result array will always be a copy of input `x`. + If ``True``, the result array will always be a copy of input `a`. If ``False``, the result array can never be a copy and a ValueError exception will be raised in case the copy is necessary. - If ``None``, the result array will reuse existing memory buffer of `x` + If ``None``, the result array will reuse existing memory buffer of `a` if possible and copy otherwise. Default: None. Returns @@ -675,14 +677,14 @@ def reshape(x, /, newshape, order="C", copy=None): """ if newshape is None: - newshape = x.shape + newshape = a.shape if order is None: order = "C" elif order not in "cfCF": raise ValueError(f"order must be one of 'C' or 'F' (got {order})") - usm_arr = dpnp.get_usm_ndarray(x) + usm_arr = dpnp.get_usm_ndarray(a) usm_arr = dpt.reshape(usm_arr, shape=newshape, order=order, copy=copy) return dpnp_array._create_from_usm_ndarray(usm_arr) @@ -823,9 +825,9 @@ def shape(a): return numpy.shape(a) -def squeeze(x, /, axis=None): +def squeeze(a, /, axis=None): """ - Removes singleton dimensions (axes) from array `x`. + Removes singleton dimensions (axes) from array `a`. For full documentation refer to :obj:`numpy.squeeze`. @@ -837,11 +839,11 @@ def squeeze(x, /, axis=None): dimensions of length 1 removed. Output has the same data type as the input, is allocated on the same device as the input and has the same USM allocation type as the input - array `x`. + array `a`. Limitations ----------- - Parameters `x` is supported as either :class:`dpnp.ndarray` + Parameters `a` is supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Otherwise the function will be executed sequentially on CPU. @@ -864,11 +866,11 @@ def squeeze(x, /, axis=None): """ - if isinstance(x, dpnp_array) or isinstance(x, dpt.usm_ndarray): - dpt_array = x.get_array() if isinstance(x, dpnp_array) else x + if isinstance(a, dpnp_array) or isinstance(a, dpt.usm_ndarray): + dpt_array = a.get_array() if isinstance(a, dpnp_array) else a return dpnp_array._create_from_usm_ndarray(dpt.squeeze(dpt_array, axis)) - return call_origin(numpy.squeeze, x, axis) + return call_origin(numpy.squeeze, a, axis) def stack(arrays, /, *, axis=0, out=None, dtype=None, **kwargs): @@ -944,7 +946,7 @@ def stack(arrays, /, *, axis=0, out=None, dtype=None, **kwargs): ) -def swapaxes(x, axis1, axis2): +def swapaxes(a, axis1, axis2): """ Interchange two axes of an array. @@ -958,14 +960,14 @@ def swapaxes(x, axis1, axis2): Limitations ----------- - Parameters `x` is supported either as :class:`dpnp.ndarray` + Parameters `a` is supported either as :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Input array data types are limited by supported DPNP :ref:`Data types`. Otherwise ``TypeError`` exception will be raised. Notes ----- - If `x` has rank (i.e., number of dimensions) `N`, + If `a` has rank (i.e., number of dimensions) `N`, a valid `axis` must be in the half-open interval `[-N, N)`. Examples @@ -991,7 +993,7 @@ def swapaxes(x, axis1, axis2): """ - dpt_array = dpnp.get_usm_ndarray(x) + dpt_array = dpnp.get_usm_ndarray(a) return dpnp_array._create_from_usm_ndarray( dpt.swapaxes(dpt_array, axis1=axis1, axis2=axis2) ) @@ -1060,7 +1062,7 @@ def transpose(a, axes=None): return array.transpose(*axes) -def unique(x1, **kwargs): +def unique(ar, **kwargs): """ Find the unique elements of an array. @@ -1076,7 +1078,7 @@ def unique(x1, **kwargs): """ - return call_origin(numpy.unique, x1, **kwargs) + return call_origin(numpy.unique, ar, **kwargs) def vstack(tup): From 0a0cb0fcc9ec9eb55c2d3377d0ba72eecad00e11 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 11:32:35 +0200 Subject: [PATCH 05/10] Replace check for broadcast_to --- dpnp/dpnp_iface_manipulation.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 7f327cb91c6..5e28194fd9d 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -229,10 +229,8 @@ def broadcast_to(array, /, shape, subok=False): if subok is not False: pass - elif isinstance(array, dpnp_array) or isinstance(array, dpt.usm_ndarray): - dpt_array = ( - array.get_array() if isinstance(array, dpnp_array) else array - ) + elif dpnp.is_supported_array_type(array): + dpt_array = dpnp.get_usm_ndarray(array) new_array = dpt.broadcast_to(dpt_array, shape) return dpnp_array._create_from_usm_ndarray(new_array) From acf7f259225a780666872b53e6d742d306a2c07c Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 11:37:10 +0200 Subject: [PATCH 06/10] Remove call_origin for moveaxis --- dpnp/dpnp_iface_manipulation.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 5e28194fd9d..ea37ed8be43 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -512,8 +512,8 @@ def moveaxis(a, source, destination): ----------- Parameters `a` is supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. - Otherwise the function will be executed sequentially on CPU. Input array data types are limited by supported DPNP :ref:`Data types`. + Otherwise ``TypeError`` exception will be raised. See Also -------- @@ -531,13 +531,10 @@ def moveaxis(a, source, destination): """ - if isinstance(a, dpnp_array) or isinstance(a, dpt.usm_ndarray): - dpt_array = a.get_array() if isinstance(a, dpnp_array) else a - return dpnp_array._create_from_usm_ndarray( - dpt.moveaxis(dpt_array, source, destination) - ) - - return call_origin(numpy.moveaxis, a, source, destination) + dpt_array = dpnp.get_usm_ndarray(a) + return dpnp_array._create_from_usm_ndarray( + dpt.moveaxis(dpt_array, source, destination) + ) def ravel(a, order="C"): From 03fc1f17edd83044bbd931eabc7f3d5f56180a50 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 11:41:24 +0200 Subject: [PATCH 07/10] Remove call_origin for squeeze --- dpnp/dpnp_iface_manipulation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index ea37ed8be43..a7ce7fb560e 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -840,7 +840,8 @@ def squeeze(a, /, axis=None): ----------- Parameters `a` is supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. - Otherwise the function will be executed sequentially on CPU. + Input array data types are limited by supported DPNP :ref:`Data types`. + Otherwise ``TypeError`` exception will be raised. Examples -------- @@ -861,11 +862,10 @@ def squeeze(a, /, axis=None): """ - if isinstance(a, dpnp_array) or isinstance(a, dpt.usm_ndarray): - dpt_array = a.get_array() if isinstance(a, dpnp_array) else a - return dpnp_array._create_from_usm_ndarray(dpt.squeeze(dpt_array, axis)) - - return call_origin(numpy.squeeze, a, axis) + dpt_array = dpnp.get_usm_ndarray(a) + return dpnp_array._create_from_usm_ndarray( + dpt.squeeze(dpt_array, axis=axis) + ) def stack(arrays, /, *, axis=0, out=None, dtype=None, **kwargs): From 9afafbe48edeb60cb068fb7341b66cfcc4d331e6 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 12:39:39 +0200 Subject: [PATCH 08/10] Refresh tests for dpnp.swapaxes --- tests/skipped_tests.tbl | 44 ----------------- tests/skipped_tests_gpu.tbl | 47 ------------------- tests/test_manipulation.py | 12 ----- .../cupy/manipulation_tests/test_basic.py | 5 +- 4 files changed, 1 insertion(+), 107 deletions(-) diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index a78de781e3b..c7627f9c9d0 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -201,61 +201,17 @@ tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_pa tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_max tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_min tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2 tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity3_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_huge_size tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_huge_size_fill0 tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_int_huge_size tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_int_huge_size_fill0 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity3 tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_invalid_order tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_K_strides tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_subok diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 79ca0610e32..2bc46082245 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -331,61 +331,14 @@ tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_pa tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_max tests/third_party/cupy/core_tests/test_ndarray_reduction.py::TestCubReduction_param_7_{order='F', shape=(10, 20, 30, 40)}::test_cub_min tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_0_{shape=4}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_1_{shape=(4,)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_2_{shape=(4, 2)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_3_{shape=(4, 2, 3)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_K_strides_reshape -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity2_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity3 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity3_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_contiguity_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_empty_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_full_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_ones_like_reshape_cupy_only -tests/third_party/cupy/creation_tests/test_basic.py::TestBasicReshape_param_4_{shape=(5, 4, 2, 3)}::test_zeros_like_reshape_cupy_only tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_huge_size tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_huge_size_fill0 tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_int_huge_size tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_int_huge_size_fill0 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity2 -tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_contiguity3 tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_invalid_order tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_K_strides tests/third_party/cupy/creation_tests/test_basic.py::TestBasic::test_empty_like_subok diff --git a/tests/test_manipulation.py b/tests/test_manipulation.py index 4d9c6d0e159..576229b1d56 100644 --- a/tests/test_manipulation.py +++ b/tests/test_manipulation.py @@ -136,15 +136,3 @@ def test_none_axes(self, shape): assert_array_equal(na.transpose(), da.transpose()) assert_array_equal(na.transpose(None), da.transpose(None)) - - -def test_expand_dims_invalid_type(): - na = numpy.ones((2, 2)) - with pytest.raises(TypeError): - numpy.expand_dims(na, 1) - - -def test_swapaxes_invalid_type(): - na = numpy.ones((2, 3, 4)) - with pytest.raises(TypeError): - dpnp.swapaxes(na, 1, 0) diff --git a/tests/third_party/cupy/manipulation_tests/test_basic.py b/tests/third_party/cupy/manipulation_tests/test_basic.py index 0712f88a736..46c3533a74f 100644 --- a/tests/third_party/cupy/manipulation_tests/test_basic.py +++ b/tests/third_party/cupy/manipulation_tests/test_basic.py @@ -120,10 +120,7 @@ def test_copyto_where_multidevice_raises(self, dtype): @testing.for_all_dtypes() def test_copyto_noncontinguous(self, dtype): src = testing.shaped_arange((2, 3, 4), cupy, dtype) - # TODO: replace with - # src = src.swapaxes(0, 1) - # once dpnp.ndarray.swapaxes() is fully implemented - src = cupy.swapaxes(src, 0, 1) + src = src.swapaxes(0, 1) dst = cupy.empty_like(src) cupy.copyto(dst, src) From 9281bd5d8e31f30b094ccc6fde571960839e560e Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 12:48:21 +0200 Subject: [PATCH 09/10] Update TODO for test_eigenvalue --- tests/third_party/cupy/linalg_tests/test_eigenvalue.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/third_party/cupy/linalg_tests/test_eigenvalue.py b/tests/third_party/cupy/linalg_tests/test_eigenvalue.py index c67fd1baee6..2345a1be0d3 100644 --- a/tests/third_party/cupy/linalg_tests/test_eigenvalue.py +++ b/tests/third_party/cupy/linalg_tests/test_eigenvalue.py @@ -14,7 +14,8 @@ def _get_hermitian(xp, a, UPLO): return xp.tril(a) + xp.tril(a, k=-1).swapaxes(-2, -1).conj() -# TODO: remove once all required functionality is supported +# TODO: +# remove once dpnp.dot and dpnp.matmul support complex types def _wrap_as_numpy_array(xp, a): return a.asnumpy() if xp is cupy else a From ecb48a85a9b32d560187aac50d2adb1213ef09b3 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 23 Aug 2023 16:07:57 +0200 Subject: [PATCH 10/10] Remove dpnp_reshape --- dpnp/dpnp_algo/dpnp_algo_manipulation.pxi | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi b/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi index 204fbd84caa..4280bd621ce 100644 --- a/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi +++ b/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi @@ -39,7 +39,6 @@ __all__ += [ "dpnp_atleast_2d", "dpnp_atleast_3d", "dpnp_repeat", - "dpnp_reshape", ] @@ -135,17 +134,3 @@ cpdef utils.dpnp_descriptor dpnp_repeat(utils.dpnp_descriptor array1, repeats, a c_dpctl.DPCTLEvent_Delete(event_ref) return result - - -cpdef utils.dpnp_descriptor dpnp_reshape(utils.dpnp_descriptor array1, newshape, order="C"): - # return dpnp.get_dpnp_descriptor(dpctl.tensor.usm_ndarray(newshape, dtype=numpy.dtype(array1.dtype).name, buffer=array1.get_pyobj())) - # return dpnp.get_dpnp_descriptor(dpctl.tensor.reshape(array1.get_pyobj(), newshape)) - array1_obj = array1.get_array() - array_obj = dpctl.tensor.reshape(array1_obj, newshape, order=order) - return dpnp.get_dpnp_descriptor(dpnp_array(array_obj.shape, - buffer=array_obj, - order=order, - device=array1_obj.sycl_device, - usm_type=array1_obj.usm_type, - sycl_queue=array1_obj.sycl_queue), - copy_when_nondefault_queue=False)