From fabf886e1afe9ce03877fefb39cf00d8a39541a5 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Tue, 19 Sep 2023 13:28:11 -0500 Subject: [PATCH 01/13] Add dtype functions --- dpnp/dpnp_iface.py | 29 ++++-------- dpnp/dpnp_iface_manipulation.py | 25 ++++++++++ dpnp/dpnp_iface_types.py | 83 +++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 21 deletions(-) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index c131bf733ce1..4c6082dd6b14 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -151,29 +151,16 @@ def asnumpy(input, order="C"): def astype(x1, dtype, order="K", casting="unsafe", subok=True, copy=True): """Copy the array with data type casting.""" - if isinstance(x1, dpnp_array): - return x1.astype(dtype, order=order, casting=casting, copy=copy) - - if isinstance(x1, dpt.usm_ndarray): - return dpt.astype(x1, dtype, order=order, casting=casting, copy=copy) - - x1_desc = get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if not x1_desc: - pass - elif order != "K": - pass - elif casting != "unsafe": - pass - elif not subok: - pass - elif not copy: - pass - elif x1_desc.dtype == numpy.complex128 or dtype == numpy.complex128: - pass - elif x1_desc.dtype == numpy.complex64 or dtype == numpy.complex64: + if subok is not True: pass else: - return dpnp_astype(x1_desc, dtype).get_pyobj() + if isinstance(x1, dpnp_array): + return x1.astype(dtype, order=order, casting=casting, copy=copy) + + if isinstance(x1, dpt.usm_ndarray): + return dpt.astype( + x1, dtype, order=order, casting=casting, copy=copy + ) return call_origin( numpy.ndarray.astype, diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index f71aa751cb2c..4f5c9a78c2c5 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -55,6 +55,7 @@ "atleast_2d", "atleast_3d", "broadcast_to", + "can_cast", "concatenate", "copyto", "expand_dims", @@ -293,6 +294,30 @@ def broadcast_to(array, /, shape, subok=False): return call_origin(numpy.broadcast_to, array, shape=shape, subok=subok) +def can_cast(from_, to, casting="safe"): + """can_cast(from, to, casting="safe") + + Returns True if cast between data types can occur according to the casting rule. If from is a scalar or array scalar, also returns True if the scalar value can be cast without overflow or truncation to an integer. + + Parameters: + from (dpnp_array, dtype): source data type + to (dtype): target data type + casting ({'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional): + controls what kind of data casting may occur. + + Returns: + bool: + Gives `True` if cast can occur according to the casting rule. + """ + if isinstance(to, dpnp_array): + raise TypeError("Expected dtype type.") + + dtype_from = ( + from_.dtype if isinstance(from_, dpnp_array) else dpnp.dtype(from_) + ) + return dpt.can_cast(dtype_from, to, casting) + + def concatenate( arrays, /, *, axis=0, out=None, dtype=None, casting="same_kind" ): diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index 68da06583fec..24e5ff1e50de 100644 --- a/dpnp/dpnp_iface_types.py +++ b/dpnp/dpnp_iface_types.py @@ -34,8 +34,11 @@ This module provides public type interface file for the library """ +import dpctl.tensor as dpt import numpy +import dpnp.dpnp_array as dpnp_array + __all__ = [ "bool", "bool_", @@ -50,12 +53,14 @@ "dtype", "e", "euler_gamma", + "finfo", "float", "float_", "float16", "float32", "float64", "floating", + "iinfo", "inexact", "Inf", "inf", @@ -67,6 +72,7 @@ "int64", "integer", "intc", + "isdtype", "isscalar", "issubdtype", "issubsctype", @@ -140,6 +146,83 @@ PZERO = numpy.PZERO +def finfo(dtype): + """finfo(type) + + Returns machine limits for floating-point data types. + + For full documentation refer to :obj:`numpy.finfo`. + + Parameters: + dtype (dtype, dpnp_array): floating-point dtype or + an array with floating point data type. + If complex, the information is about its component + data type. + + Returns: + finfo_object: + an object have the following attributes + * bits: int + number of bits occupied by dtype. + * eps: float + difference between 1.0 and the next smallest representable + real-valued floating-point number larger than 1.0 according + to the IEEE-754 standard. + * max: float + largest representable real-valued number. + * min: float + smallest representable real-valued number. + * smallest_normal: float + smallest positive real-valued floating-point number with + full precision. + * dtype: dtype + real-valued floating-point data type. + + """ + if isinstance(dtype, dpnp_array): + dtype = dtype.dtype + return dpt.finfo(dtype) + + +def isdtype(dtype_, kind): + """isdtype(dtype, kind) + + Returns a boolean indicating whether a provided `dtype` is + of a specified data type `kind`. + """ + + return dpt.isdtype(dtype_, kind) + + +def iinfo(dtype): + """iinfo(dtype) + + Returns machine limits for integer data types. + + For full documentation refer to :obj:`numpy.iinfo`. + + Parameters: + dtype (dtype, dpnp_array): + integer dtype or + an array with integer dtype. + + Returns: + iinfo_object: + An object with the following attributes + * bits: int + number of bits occupied by the data type + * max: int + largest representable number. + * min: int + smallest representable number. + * dtype: dtype + integer data type. + """ + if isinstance(dtype, dpnp_array): + dtype = dtype.dtype + return dpt.iinfo(dtype) + + def isscalar(obj): """ Returns True if the type of `obj` is a scalar type. From c02823f310eb77208562863ee083ad4a6000dbd2 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 21 Sep 2023 11:14:26 -0500 Subject: [PATCH 02/13] Add atleast 2d and 3d, vstack, repeat, and broadcast_arrays functions --- dpnp/dpnp_algo/dpnp_algo.pyx | 1 - dpnp/dpnp_algo/dpnp_algo_manipulation.pxi | 136 --------- dpnp/dpnp_iface_manipulation.py | 268 +++++++++++------ tests/test_arraymanipulation.py | 340 +++++++++++++++++++++- 4 files changed, 510 insertions(+), 235 deletions(-) delete mode 100644 dpnp/dpnp_algo/dpnp_algo_manipulation.pxi diff --git a/dpnp/dpnp_algo/dpnp_algo.pyx b/dpnp/dpnp_algo/dpnp_algo.pyx index 0bde1b25fb2e..305088927075 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pyx +++ b/dpnp/dpnp_algo/dpnp_algo.pyx @@ -65,7 +65,6 @@ include "dpnp_algo_counting.pxi" include "dpnp_algo_indexing.pxi" include "dpnp_algo_linearalgebra.pxi" include "dpnp_algo_logic.pxi" -include "dpnp_algo_manipulation.pxi" include "dpnp_algo_mathematical.pxi" include "dpnp_algo_searching.pxi" include "dpnp_algo_sorting.pxi" diff --git a/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi b/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi deleted file mode 100644 index 4280bd621ce9..000000000000 --- a/dpnp/dpnp_algo/dpnp_algo_manipulation.pxi +++ /dev/null @@ -1,136 +0,0 @@ -# cython: language_level=3 -# cython: linetrace=True -# -*- coding: utf-8 -*- -# ***************************************************************************** -# Copyright (c) 2016-2023, Intel Corporation -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# - Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. -# ***************************************************************************** - -"""Module Backend (Array manipulation routines) - -This module contains interface functions between C backend layer -and the rest of the library - -""" - -# NO IMPORTs here. All imports must be placed into main "dpnp_algo.pyx" file - -__all__ += [ - "dpnp_atleast_2d", - "dpnp_atleast_3d", - "dpnp_repeat", -] - - -# C function pointer to the C library template functions -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_repeat_t)(c_dpctl.DPCTLSyclQueueRef, - const void *, void * , const size_t , const size_t, - const c_dpctl.DPCTLEventVectorRef) - - -cpdef utils.dpnp_descriptor dpnp_atleast_2d(utils.dpnp_descriptor arr): - # it looks like it should be dpnp.copy + dpnp.reshape - cdef utils.dpnp_descriptor result - cdef size_t arr_ndim = arr.ndim - cdef long arr_size = arr.size - if arr_ndim == 1: - arr_obj = arr.get_array() - result = utils_py.create_output_descriptor_py((1, arr_size), - arr.dtype, - None, - device=arr_obj.sycl_device, - usm_type=arr_obj.usm_type, - sycl_queue=arr_obj.sycl_queue) - for i in range(arr_size): - result.get_pyobj()[0, i] = arr.get_pyobj()[i] - return result - else: - return arr - - -cpdef utils.dpnp_descriptor dpnp_atleast_3d(utils.dpnp_descriptor arr): - # it looks like it should be dpnp.copy + dpnp.reshape - cdef utils.dpnp_descriptor result - cdef size_t arr_ndim = arr.ndim - cdef shape_type_c arr_shape = arr.shape - cdef long arr_size = arr.size - - arr_obj = arr.get_array() - - if arr_ndim == 1: - result = utils_py.create_output_descriptor_py((1, 1, arr_size), - arr.dtype, - None, - device=arr_obj.sycl_device, - usm_type=arr_obj.usm_type, - sycl_queue=arr_obj.sycl_queue) - for i in range(arr_size): - result.get_pyobj()[0, 0, i] = arr.get_pyobj()[i] - return result - elif arr_ndim == 2: - result = utils_py.create_output_descriptor_py((1, arr_shape[0], arr_shape[1]), - arr.dtype, - None, - device=arr_obj.sycl_device, - usm_type=arr_obj.usm_type, - sycl_queue=arr_obj.sycl_queue) - for i in range(arr_shape[0]): - for j in range(arr_shape[1]): - result.get_pyobj()[0, i, j] = arr.get_pyobj()[i, j] - return result - else: - return arr - - -cpdef utils.dpnp_descriptor dpnp_repeat(utils.dpnp_descriptor array1, repeats, axes=None): - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype) - - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_REPEAT_EXT, param1_type, param1_type) - - array1_obj = array1.get_array() - - # ceate result array with type given by FPTR data - cdef shape_type_c result_shape = (array1.size * repeats, ) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, - kernel_data.return_type, - None, - device=array1_obj.sycl_device, - usm_type=array1_obj.usm_type, - sycl_queue=array1_obj.sycl_queue) - result_sycl_queue = result.get_array().sycl_queue - - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_repeat_t func = kernel_data.ptr - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, - array1.get_data(), - result.get_data(), - repeats, - array1.size, - NULL) # dep_events_ref - - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) - c_dpctl.DPCTLEvent_Delete(event_ref) - - return result diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 4f5c9a78c2c5..bba628405bc0 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -54,6 +54,7 @@ "atleast_1d", "atleast_2d", "atleast_3d", + "broadcast_arrays", "broadcast_to", "can_cast", "concatenate", @@ -184,36 +185,52 @@ def atleast_2d(*arys): For full documentation refer to :obj:`numpy.atleast_2d`. - Limitations - ----------- - Input arrays is supported as :obj:`dpnp.ndarray`. + Parameters + ---------- + arys : {dpnp_array, usm_ndarray} + One or more array-like sequences. Non-array inputs are converted + to arrays. Arrays that already have two or more dimensions are + preserved. + + Returns + ------- + out : dpnp.ndarray + An array, or list of arrays, each with ``a.ndim >= 2``. + Copies are avoided where possible, and views with two or more + dimensions are returned. + + See Also + -------- + atleast_1d, atleast_3d + + Examples + -------- + >>> import dpnp as np + >>> np.atleast_2d(3.0) + array([[3.]]) + + >>> x = np.arange(3.0) + >>> np.atleast_2d(x) + array([[0., 1., 2.]]) + + >>> np.atleast_2d(1, [1, 2], [[1, 2]]) + [array([[1]]), array([[1, 2]]), array([[1, 2]])] """ - all_is_array = True - arys_desc = [] + res = [] for ary in arys: - if not dpnp.isscalar(ary): - ary_desc = dpnp.get_dpnp_descriptor( - ary, copy_when_nondefault_queue=False - ) - if ary_desc: - arys_desc.append(ary_desc) - continue - all_is_array = False - break - - if not use_origin_backend(arys[0]) and all_is_array: - result = [] - for ary_desc in arys_desc: - res = dpnp_atleast_2d(ary_desc).get_pyobj() - result.append(res) - - if len(result) == 1: - return result[0] + ary = dpnp.asanyarray(ary) + if ary.ndim == 0: + result = ary.reshape(1, 1) + elif ary.ndim == 1: + result = ary[dpnp.newaxis, :] else: - return result - - return call_origin(numpy.atleast_2d, *arys) + result = ary + res.append(result) + if len(res) == 1: + return res[0] + else: + return res def atleast_3d(*arys): @@ -222,36 +239,74 @@ def atleast_3d(*arys): For full documentation refer to :obj:`numpy.atleast_3d`. - Limitations - ----------- - Input arrays is supported as :obj:`dpnp.ndarray`. + Parameters + ---------- + arys : {dpnp_array, usm_ndarray} + One or more array-like sequences. Non-array inputs are converted to + arrays. Arrays that already have three or more dimensions are + preserved. + + Returns + ------- + out : dpnp.ndarray + An array, or list of arrays, each with ``a.ndim >= 3``. Copies are + avoided where possible, and views with three or more dimensions are + returned. For example, a 1-D array of shape ``(N,)`` becomes a view + of shape ``(1, N, 1)``, and a 2-D array of shape ``(M, N)`` becomes a + view of shape ``(M, N, 1)``. + + Examples + -------- + >>> import dpnp as np + >>> np.atleast_3d(3.0) + array([[[3.]]]) + + >>> x = np.arange(3.0) + >>> np.atleast_3d(x).shape + (1, 3, 1) + + >>> x = np.arange(12.0).reshape(4,3) + >>> np.atleast_3d(x).shape + (4, 3, 1) """ - all_is_array = True - arys_desc = [] + res = [] for ary in arys: - if not dpnp.isscalar(ary): - ary_desc = dpnp.get_dpnp_descriptor( - ary, copy_when_nondefault_queue=False - ) - if ary_desc: - arys_desc.append(ary_desc) - continue - all_is_array = False - break - - if not use_origin_backend(arys[0]) and all_is_array: - result = [] - for ary_desc in arys_desc: - res = dpnp_atleast_3d(ary_desc).get_pyobj() - result.append(res) - - if len(result) == 1: - return result[0] + ary = dpnp.asanyarray(ary) + if ary.ndim == 0: + result = ary.reshape(1, 1, 1) + elif ary.ndim == 1: + result = ary[dpnp.newaxis, :, dpnp.newaxis] + elif ary.ndim == 2: + result = ary[:, :, dpnp.newaxis] else: - return result + result = ary + res.append(result) + if len(res) == 1: + return res[0] + else: + return res - return call_origin(numpy.atleast_3d, *arys) + +def broadcast_arrays(*args, subok=False): + """ + Broadcast any number of arrays against each other. + + For full documentation refer to :obj:`numpy.broadcast_arrays`. + """ + + if subok is not False: + pass + elif all(dpnp.is_supported_array_type(array) for array in args): + dpt_arrays = dpt.broadcast_arrays( + *[dpnp.get_usm_ndarray(array) for array in args] + ) + new_arrays = [] + for array in dpt_arrays: + new_arrays.append(dpnp_array._create_from_usm_ndarray(array)) + return new_arrays + + return call_origin(numpy.broadcast_arrays, args, subok=subok) def broadcast_to(array, /, shape, subok=False): @@ -295,19 +350,23 @@ def broadcast_to(array, /, shape, subok=False): def can_cast(from_, to, casting="safe"): - """can_cast(from, to, casting="safe") - - Returns True if cast between data types can occur according to the casting rule. If from is a scalar or array scalar, also returns True if the scalar value can be cast without overflow or truncation to an integer. + """ + Returns True if cast between data types can occur according to the casting rule. Parameters: - from (dpnp_array, dtype): source data type - to (dtype): target data type - casting ({'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional): - controls what kind of data casting may occur. + from (dpnp_array, dtype): source data type + to (dtype): target data type + casting ({'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional): + controls what kind of data casting may occur. Returns: - bool: - Gives `True` if cast can occur according to the casting rule. + bool: True if cast can occur according to the casting rule. + + Notes + ----------- + If from is a scalar or array scalar, also returns True if the scalar value can + be cast without overflow or truncation to an integer. + """ if isinstance(to, dpnp_array): raise TypeError("Expected dtype type.") @@ -872,39 +931,47 @@ def repeat(a, repeats, axis=None): For full documentation refer to :obj:`numpy.repeat`. + Parameters: + x (usm_ndarray): input array + + repeat (Union[int, Tuple[int, ...]]): + The number of repetitions for each element. + `repeats` is broadcasted to fit the shape of the given axis. + + axis (Optional[int]): + The axis along which to repeat values. The `axis` is required + if input array has more than one dimension. + + Returns: + dpnp_array: + Array with repeated elements. + The returned array must have the same data type as `x`, + is created on the same device as `x` and has the same USM + allocation type as `x`. + Limitations ----------- - Input array is supported as :obj:`dpnp.ndarray`. - Parameter ``axis`` is supported with value either ``None`` or ``0``. - Dimension of input array are supported to be less than ``2``. + Parameter `a` is supported as either :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. + Otherwise ``TypeError`` exception will be raised. Otherwise the function will be executed sequentially on CPU. - If ``repeats`` is ``tuple`` or ``list``, should be ``len(repeats) > 1``. Input array data types are limited by supported DPNP :ref:`Data types`. - .. seealso:: :obj:`numpy.tile` tile an array. - Examples -------- >>> import dpnp as np - >>> x = np.repeat(3, 4) - >>> [i for i in x] - [3, 3, 3, 3] + >>> x = np.array([3]) + >>> np.repeat(x, 4) + array([3, 3, 3, 3]) """ - 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 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(a_desc, repeat_val, axis).get_pyobj() - - return call_origin(numpy.repeat, a, repeats, axis) + usm_arr = dpnp.get_usm_ndarray(a) + rep = repeats + if isinstance(repeats, dpnp_array): + rep = dpnp.get_usm_ndarray(repeats) + usm_arr = dpt.repeat(usm_arr, rep, axis=axis) + return dpnp_array._create_from_usm_ndarray(usm_arr) def reshape(a, /, newshape, order="C", copy=None): @@ -1439,20 +1506,37 @@ def unique(ar, **kwargs): return call_origin(numpy.unique, ar, **kwargs) -def vstack(tup): +def vstack(tup, *, dtype=None, casting="same_kind"): """ Stack arrays in sequence vertically (row wise). For full documentation refer to :obj:`numpy.vstack`. - """ + Examples + -------- + >>> import dpnp as np + >>> a = np.array([1, 2, 3]) + >>> b = np.array([4, 5, 6]) + >>> np.vstack((a, b)) + array([[1, 2, 3], + [4, 5, 6]]) - # TODO: - # `call_origin` cannot convert sequence of array to sequence of - # nparray - tup_new = [] - for tp in tup: - tpx = dpnp.asnumpy(tp) if not isinstance(tp, numpy.ndarray) else tp - tup_new.append(tpx) + >>> a = np.array([[1], [2], [3]]) + >>> b = np.array([[4], [5], [6]]) + >>> np.vstack((a, b)) + array([[1], + [2], + [3], + [4], + [5], + [6]]) - return call_origin(numpy.vstack, tup_new) + """ + if not hasattr(tup, "__getitem__"): + raise TypeError( + "Arrays to stack must be passed as a sequence type such as list or tuple." + ) + arrs = atleast_2d(*tup) + if not isinstance(arrs, list): + arrs = [arrs] + return dpnp.concatenate(arrs, axis=0, dtype=dtype, casting=casting) diff --git a/tests/test_arraymanipulation.py b/tests/test_arraymanipulation.py index 1c98c487dfc2..df384fe39035 100644 --- a/tests/test_arraymanipulation.py +++ b/tests/test_arraymanipulation.py @@ -583,11 +583,9 @@ class TestVstack: def test_non_iterable(self): assert_raises(TypeError, dpnp.vstack, 1) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_empty_input(self): - assert_raises(ValueError, dpnp.vstack, ()) + assert_raises(TypeError, dpnp.vstack, ()) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_0D_array(self): a = dpnp.array(1) b = dpnp.array(2) @@ -595,7 +593,6 @@ def test_0D_array(self): desired = dpnp.array([[1], [2]]) assert_array_equal(res, desired) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_1D_array(self): a = dpnp.array([1]) b = dpnp.array([2]) @@ -603,7 +600,6 @@ def test_1D_array(self): desired = dpnp.array([[1], [2]]) assert_array_equal(res, desired) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_2D_array(self): a = dpnp.array([[1], [2]]) b = dpnp.array([[1], [2]]) @@ -611,7 +607,6 @@ def test_2D_array(self): desired = dpnp.array([[1], [2], [1], [2]]) assert_array_equal(res, desired) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_2D_array2(self): a = dpnp.array([1, 2]) b = dpnp.array([1, 2]) @@ -725,3 +720,336 @@ def test_results(self): jp = j + 1 if j < 4 else j res = dpnp.rollaxis(dp_a, axis=-ip, start=-jp) exp = numpy.rollaxis(np_a, axis=-ip, start=-jp) + + +class TestAtleast2d: + def test_0D_array(self): + a = dpnp.array(1) + b = dpnp.array(2) + res = [dpnp.atleast_2d(a), dpnp.atleast_2d(b)] + desired = [dpnp.array([[1]]), dpnp.array([[2]])] + assert_array_equal(res, desired) + + def test_1D_array(self): + a = dpnp.array([1, 2]) + b = dpnp.array([2, 3]) + res = [dpnp.atleast_2d(a), dpnp.atleast_2d(b)] + desired = [dpnp.array([[1, 2]]), dpnp.array([[2, 3]])] + assert_array_equal(res, desired) + + def test_2D_array(self): + a = dpnp.array([[1, 2], [1, 2]]) + b = dpnp.array([[2, 3], [2, 3]]) + res = [dpnp.atleast_2d(a), dpnp.atleast_2d(b)] + desired = [a, b] + assert_array_equal(res, desired) + + def test_3D_array(self): + a = dpnp.array([[1, 2], [1, 2]]) + b = dpnp.array([[2, 3], [2, 3]]) + a = dpnp.array([a, a]) + b = dpnp.array([b, b]) + res = [dpnp.atleast_2d(a), dpnp.atleast_2d(b)] + desired = [a, b] + assert_array_equal(res, desired) + + def test_r2array(self): + """Test to make sure equivalent Travis O's r2array function""" + assert dpnp.atleast_2d(3).shape == (1, 1) + assert dpnp.atleast_2d([3j, 1]).shape == (1, 2) + array = dpnp.atleast_2d([[[3, 1], [4, 5]], [[3, 5], [1, 2]]]) + assert array.shape == (2, 2, 2) + + +class TestAtleast3d: + def test_0D_array(self): + a = dpnp.array(1) + b = dpnp.array(2) + res = [dpnp.atleast_3d(a), dpnp.atleast_3d(b)] + desired = [dpnp.array([[[1]]]), dpnp.array([[[2]]])] + assert_array_equal(res, desired) + + def test_1D_array(self): + a = dpnp.array([1, 2]) + b = dpnp.array([2, 3]) + res = [dpnp.atleast_3d(a), dpnp.atleast_3d(b)] + desired = [dpnp.array([[[1], [2]]]), dpnp.array([[[2], [3]]])] + assert_array_equal(res, desired) + + def test_2D_array(self): + a = dpnp.array([[1, 2], [1, 2]]) + b = dpnp.array([[2, 3], [2, 3]]) + res = [dpnp.atleast_3d(a), dpnp.atleast_3d(b)] + desired = [a[:, :, dpnp.newaxis], b[:, :, dpnp.newaxis]] + assert_array_equal(res, desired) + + def test_3D_array(self): + a = dpnp.array([[1, 2], [1, 2]]) + b = dpnp.array([[2, 3], [2, 3]]) + a = dpnp.array([a, a]) + b = dpnp.array([b, b]) + res = [dpnp.atleast_3d(a), dpnp.atleast_3d(b)] + desired = [a, b] + assert_array_equal(res, desired) + + +def test_repeat_scalar_sequence_agreement(): + x = dpnp.arange(5, dtype="i4") + expected_res = dpnp.empty(10, dtype="i4") + expected_res[1::2], expected_res[::2] = x, x + + # scalar case + reps = 2 + res = dpnp.repeat(x, reps) + assert dpnp.all(res == expected_res) + + # tuple + reps = (2, 2, 2, 2, 2) + res = dpnp.repeat(x, reps) + assert dpnp.all(res == expected_res) + + +def test_repeat_as_broadcasting(): + reps = 5 + x = dpnp.arange(reps, dtype="i4") + x1 = x[:, dpnp.newaxis] + expected_res = dpnp.broadcast_to(x1, (reps, reps)) + + res = dpnp.repeat(x1, reps, axis=1) + assert dpnp.all(res == expected_res) + + x2 = x[dpnp.newaxis, :] + expected_res = dpnp.broadcast_to(x2, (reps, reps)) + + res = dpnp.repeat(x2, reps, axis=0) + assert dpnp.all(res == expected_res) + + +def test_repeat_axes(): + reps = 2 + x = dpnp.reshape(dpnp.arange(5 * 10, dtype="i4"), (5, 10)) + expected_res = dpnp.empty((x.shape[0] * 2, x.shape[1]), dtype=x.dtype) + expected_res[::2, :], expected_res[1::2] = x, x + res = dpnp.repeat(x, reps, axis=0) + assert dpnp.all(res == expected_res) + + expected_res = dpnp.empty((x.shape[0], x.shape[1] * 2), dtype=x.dtype) + expected_res[:, ::2], expected_res[:, 1::2] = x, x + res = dpnp.repeat(x, reps, axis=1) + assert dpnp.all(res == expected_res) + + +def test_repeat_size_0_outputs(): + x = dpnp.ones((3, 0, 5), dtype="i4") + reps = 10 + res = dpnp.repeat(x, reps, axis=0) + assert res.size == 0 + assert res.shape == (30, 0, 5) + + res = dpnp.repeat(x, reps, axis=1) + assert res.size == 0 + assert res.shape == (3, 0, 5) + + res = dpnp.repeat(x, (2, 2, 2), axis=0) + assert res.size == 0 + assert res.shape == (6, 0, 5) + + x = dpnp.ones((3, 2, 5)) + res = dpnp.repeat(x, 0, axis=1) + assert res.size == 0 + assert res.shape == (3, 0, 5) + + x = dpnp.ones((3, 2, 5)) + res = dpnp.repeat(x, (0, 0), axis=1) + assert res.size == 0 + assert res.shape == (3, 0, 5) + + +def test_repeat_strides(): + reps = 2 + x = dpnp.reshape(dpnp.arange(10 * 10, dtype="i4"), (10, 10)) + x1 = x[:, ::-2] + expected_res = dpnp.empty((10, 10), dtype="i4") + expected_res[:, ::2], expected_res[:, 1::2] = x1, x1 + res = dpnp.repeat(x1, reps, axis=1) + assert dpnp.all(res == expected_res) + res = dpnp.repeat(x1, (reps,) * x1.shape[1], axis=1) + assert dpnp.all(res == expected_res) + + x1 = x[::-2, :] + expected_res = dpnp.empty((10, 10), dtype="i4") + expected_res[::2, :], expected_res[1::2, :] = x1, x1 + res = dpnp.repeat(x1, reps, axis=0) + assert dpnp.all(res == expected_res) + res = dpnp.repeat(x1, (reps,) * x1.shape[0], axis=0) + assert dpnp.all(res == expected_res) + + +def test_repeat_casting(): + x = dpnp.arange(5, dtype="i4") + # i4 is cast to i8 + reps = dpnp.ones(5, dtype="i4") + res = dpnp.repeat(x, reps) + assert res.shape == x.shape + assert dpnp.all(res == x) + + +def test_repeat_strided_repeats(): + x = dpnp.arange(5, dtype="i4") + reps = dpnp.ones(10, dtype="i8") + reps[::2] = 0 + reps = reps[::-2] + res = dpnp.repeat(x, reps) + assert res.shape == x.shape + assert dpnp.all(res == x) + + +def test_can_cast(): + # incorrect input + X = dpnp.ones((2, 2), dtype=dpnp.int64) + pytest.raises(TypeError, dpnp.can_cast, X, 1) + pytest.raises(TypeError, dpnp.can_cast, X, X) + X_np = numpy.ones((2, 2), dtype=numpy.int64) + + assert dpnp.can_cast(X, "float32") == numpy.can_cast(X_np, "float32") + assert dpnp.can_cast(X, dpnp.int32) == numpy.can_cast(X_np, numpy.int32) + assert dpnp.can_cast(X, dpnp.int64) == numpy.can_cast(X_np, numpy.int64) + + +def assert_broadcast_correct(input_shapes): + np_arrays = [numpy.zeros(s, dtype="i1") for s in input_shapes] + out_np_arrays = numpy.broadcast_arrays(*np_arrays) + usm_arrays = [dpnp.asarray(Xnp) for Xnp in np_arrays] + out_usm_arrays = dpnp.broadcast_arrays(*usm_arrays) + for Xnp, X in zip(out_np_arrays, out_usm_arrays): + assert_array_equal( + Xnp, dpnp.asnumpy(X), err_msg=f"Failed for {input_shapes})" + ) + + +def assert_broadcast_arrays_raise(input_shapes): + usm_arrays = [dpnp.asarray(numpy.zeros(s)) for s in input_shapes] + pytest.raises(ValueError, dpnp.broadcast_arrays, *usm_arrays) + + +def test_broadcast_arrays_same(): + Xnp = numpy.arange(10) + Ynp = numpy.arange(10) + res_Xnp, res_Ynp = numpy.broadcast_arrays(Xnp, Ynp) + X = dpnp.asarray(Xnp) + Y = dpnp.asarray(Ynp) + res_X, res_Y = dpnp.broadcast_arrays(X, Y) + assert_array_equal(res_Xnp, dpnp.asnumpy(res_X)) + assert_array_equal(res_Ynp, dpnp.asnumpy(res_Y)) + + +def test_broadcast_arrays_one_off(): + Xnp = numpy.array([[1, 2, 3]]) + Ynp = numpy.array([[1], [2], [3]]) + res_Xnp, res_Ynp = numpy.broadcast_arrays(Xnp, Ynp) + X = dpnp.asarray(Xnp) + Y = dpnp.asarray(Ynp) + res_X, res_Y = dpnp.broadcast_arrays(X, Y) + assert_array_equal(res_Xnp, dpnp.asnumpy(res_X)) + assert_array_equal(res_Ynp, dpnp.asnumpy(res_Y)) + + +@pytest.mark.parametrize( + "shapes", + [ + (), + (1,), + (3,), + (0, 1), + (0, 3), + (1, 0), + (3, 0), + (1, 3), + (3, 1), + (3, 3), + ], +) +def test_broadcast_arrays_same_shapes(shapes): + for shape in shapes: + single_input_shapes = [shape] + assert_broadcast_correct(single_input_shapes) + double_input_shapes = [shape, shape] + assert_broadcast_correct(double_input_shapes) + triple_input_shapes = [shape, shape, shape] + assert_broadcast_correct(triple_input_shapes) + + +@pytest.mark.parametrize( + "shapes", + [ + [[(1,), (3,)]], + [[(1, 3), (3, 3)]], + [[(3, 1), (3, 3)]], + [[(1, 3), (3, 1)]], + [[(1, 1), (3, 3)]], + [[(1, 1), (1, 3)]], + [[(1, 1), (3, 1)]], + [[(1, 0), (0, 0)]], + [[(0, 1), (0, 0)]], + [[(1, 0), (0, 1)]], + [[(1, 1), (0, 0)]], + [[(1, 1), (1, 0)]], + [[(1, 1), (0, 1)]], + ], +) +def test_broadcast_arrays_same_len_shapes(shapes): + # Check that two different input shapes of the same length, but some have + # ones, broadcast to the correct shape. + + for input_shapes in shapes: + assert_broadcast_correct(input_shapes) + assert_broadcast_correct(input_shapes[::-1]) + + +@pytest.mark.parametrize( + "shapes", + [ + [[(), (3,)]], + [[(3,), (3, 3)]], + [[(3,), (3, 1)]], + [[(1,), (3, 3)]], + [[(), (3, 3)]], + [[(1, 1), (3,)]], + [[(1,), (3, 1)]], + [[(1,), (1, 3)]], + [[(), (1, 3)]], + [[(), (3, 1)]], + [[(), (0,)]], + [[(0,), (0, 0)]], + [[(0,), (0, 1)]], + [[(1,), (0, 0)]], + [[(), (0, 0)]], + [[(1, 1), (0,)]], + [[(1,), (0, 1)]], + [[(1,), (1, 0)]], + [[(), (1, 0)]], + [[(), (0, 1)]], + ], +) +def test_broadcast_arrays_different_len_shapes(shapes): + # Check that two different input shapes (of different lengths) broadcast + # to the correct shape. + + for input_shapes in shapes: + assert_broadcast_correct(input_shapes) + assert_broadcast_correct(input_shapes[::-1]) + + +@pytest.mark.parametrize( + "shapes", + [ + [[(3,), (4,)]], + [[(2, 3), (2,)]], + [[(3,), (3,), (4,)]], + [[(1, 3, 4), (2, 3, 3)]], + ], +) +def test_incompatible_shapes_raise_valueerror(shapes): + for input_shapes in shapes: + assert_broadcast_arrays_raise(input_shapes) + assert_broadcast_arrays_raise(input_shapes[::-1]) From f6738ff36395f833419824c150338d67334d6cf7 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Fri, 22 Sep 2023 13:54:15 -0500 Subject: [PATCH 03/13] address comments --- dpnp/dpnp_algo/CMakeLists.txt | 1 - dpnp/dpnp_algo/dpnp_algo.pxd | 5 -- dpnp/dpnp_iface_manipulation.py | 71 +++++++++++++++--------- dpnp/dpnp_iface_types.py | 95 ++++++++++++++++----------------- tests/skipped_tests.tbl | 3 -- tests/skipped_tests_gpu.tbl | 1 - tests/test_arraymanipulation.py | 14 ++--- 7 files changed, 97 insertions(+), 93 deletions(-) diff --git a/dpnp/dpnp_algo/CMakeLists.txt b/dpnp/dpnp_algo/CMakeLists.txt index 8aa419220def..ad91b4babf97 100644 --- a/dpnp/dpnp_algo/CMakeLists.txt +++ b/dpnp/dpnp_algo/CMakeLists.txt @@ -1,7 +1,6 @@ set(dpnp_algo_pyx_deps ${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_linearalgebra.pxi - ${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_manipulation.pxi ${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_counting.pxi ${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_statistics.pxi ${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_trigonometric.pxi diff --git a/dpnp/dpnp_algo/dpnp_algo.pxd b/dpnp/dpnp_algo/dpnp_algo.pxd index a512737ef31e..ffafd0d62550 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -391,11 +391,6 @@ cpdef dpnp_descriptor dpnp_maximum(dpnp_descriptor x1_obj, dpnp_descriptor x2_ob cpdef dpnp_descriptor dpnp_minimum(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*, dpnp_descriptor out=*, object where=*) -""" -Array manipulation routines -""" -cpdef dpnp_descriptor dpnp_repeat(dpnp_descriptor array1, repeats, axes=*) - """ Statistics functions diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index bba628405bc0..76b36f6e6158 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -353,19 +353,22 @@ def can_cast(from_, to, casting="safe"): """ Returns True if cast between data types can occur according to the casting rule. - Parameters: - from (dpnp_array, dtype): source data type - to (dtype): target data type - casting ({'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional): - controls what kind of data casting may occur. + If `from` is a scalar or array scalar, also returns `True` if the scalar value can + be cast without overflow or truncation to an integer. - Returns: - bool: True if cast can occur according to the casting rule. + Parameters + ---------- + from : dpnp.array, dtype + Source data type. + to : dtype + Target data type. + casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional + Controls what kind of data casting may occur. - Notes - ----------- - If from is a scalar or array scalar, also returns True if the scalar value can - be cast without overflow or truncation to an integer. + Returns + ------- + out: bool + True if cast can occur according to the casting rule. """ if isinstance(to, dpnp_array): @@ -395,7 +398,7 @@ def concatenate( Each array in `arrays` is supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exception will be raised. - Parameters `out` and `dtype are supported with default value. + Parameters `out` and `dtype` are supported with default value. Otherwise the function will be executed sequentially on CPU. See Also @@ -931,32 +934,27 @@ def repeat(a, repeats, axis=None): For full documentation refer to :obj:`numpy.repeat`. - Parameters: - x (usm_ndarray): input array + Parameters + ---------- + x : {dpnp_array, usm_ndarray} + Input array. - repeat (Union[int, Tuple[int, ...]]): + repeat : Union[int, Tuple[int, ...]] The number of repetitions for each element. `repeats` is broadcasted to fit the shape of the given axis. - axis (Optional[int]): + axis : Optional[int] The axis along which to repeat values. The `axis` is required if input array has more than one dimension. - Returns: - dpnp_array: + Returns + ------- + out : dpnp_array Array with repeated elements. The returned array must have the same data type as `x`, is created on the same device as `x` and has the same USM allocation type as `x`. - Limitations - ----------- - Parameter `a` is supported as either :class:`dpnp.ndarray` - or :class:`dpctl.tensor.usm_ndarray`. - Otherwise ``TypeError`` exception will be raised. - Otherwise the function will be executed sequentially on CPU. - Input array data types are limited by supported DPNP :ref:`Data types`. - Examples -------- >>> import dpnp as np @@ -1512,6 +1510,27 @@ def vstack(tup, *, dtype=None, casting="same_kind"): For full documentation refer to :obj:`numpy.vstack`. + Returns + ------- + out : dpnp.ndarray + The stacked array which has one more dimension than the input arrays. + + Limitations + ----------- + Each array in `tup` is supported as either :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exception + will be raised. + Parameters `dtype` and `casting` are supported with default value. + Otherwise the function will be executed sequentially on CPU. + + See Also + -------- + :obj:`dpnp.concatenate` : Join a sequence of arrays along an existing axis. + :obj:`dpnp.stack` : Join a sequence of arrays along a new axis. + :obj:`dpnp.hstack` : Stack arrays in sequence horizontally (column wise). + :obj:`dpnp.block` : Assemble an nd-array from nested lists of blocks. + :obj:`dpnp.split` : Split array into a list of multiple sub-arrays of equal size. + Examples -------- >>> import dpnp as np diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index 24e5ff1e50de..86627115d4fa 100644 --- a/dpnp/dpnp_iface_types.py +++ b/dpnp/dpnp_iface_types.py @@ -147,36 +147,36 @@ def finfo(dtype): - """finfo(type) - + """ Returns machine limits for floating-point data types. For full documentation refer to :obj:`numpy.finfo`. - Parameters: - dtype (dtype, dpnp_array): floating-point dtype or - an array with floating point data type. - If complex, the information is about its component - data type. - - Returns: - finfo_object: - an object have the following attributes - * bits: int - number of bits occupied by dtype. - * eps: float - difference between 1.0 and the next smallest representable - real-valued floating-point number larger than 1.0 according - to the IEEE-754 standard. - * max: float - largest representable real-valued number. - * min: float - smallest representable real-valued number. - * smallest_normal: float - smallest positive real-valued floating-point number with - full precision. - * dtype: dtype - real-valued floating-point data type. + Parameters + ---------- + dtype : dtype, dpnp_array) + Floating-point dtype or an array with floating point data type. + If complex, the information is about its component data type. + + Returns + ------- + out : finfo_object + An object have the following attributes + * bits: int + number of bits occupied by dtype. + * eps: float + difference between 1.0 and the next smallest representable + real-valued floating-point number larger than 1.0 according + to the IEEE-754 standard. + * max: float + largest representable real-valued number. + * min: float + smallest representable real-valued number. + * smallest_normal: float + smallest positive real-valued floating-point number with + full precision. + * dtype: dtype + real-valued floating-point data type. """ if isinstance(dtype, dpnp_array): @@ -185,38 +185,33 @@ def finfo(dtype): def isdtype(dtype_, kind): - """isdtype(dtype, kind) - - Returns a boolean indicating whether a provided `dtype` is - of a specified data type `kind`. - """ - + """Returns a boolean indicating whether a provided `dtype` is of a specified data type `kind`.""" return dpt.isdtype(dtype_, kind) def iinfo(dtype): - """iinfo(dtype) - + """ Returns machine limits for integer data types. For full documentation refer to :obj:`numpy.iinfo`. - Parameters: - dtype (dtype, dpnp_array): - integer dtype or - an array with integer dtype. - - Returns: - iinfo_object: - An object with the following attributes - * bits: int - number of bits occupied by the data type - * max: int - largest representable number. - * min: int - smallest representable number. - * dtype: dtype - integer data type. + Parameters + ---------- + dtype : dtype, dpnp_array + Integer dtype or an array with integer dtype. + + Returns + ------- + out : iinfo_object + An object with the following attributes + * bits: int + number of bits occupied by the data type + * max: int + largest representable number. + * min: int + smallest representable number. + * dtype: dtype + integer data type. """ if isinstance(dtype, dpnp_array): dtype = dtype.dtype diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index 128b7f7f5da2..08e606c09ca0 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -33,9 +33,6 @@ tests/third_party/cupy/fft_tests/test_fft.py::TestFftn_param_22_{axes=None, norm tests/third_party/cupy/fft_tests/test_fft.py::TestFftn_param_23_{axes=None, norm=None, s=None, shape=(0, 0, 5)}::test_fftn tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpctl_memory - -tests/test_arraymanipulation.py::TestVstack::test_generator - tests/test_linalg.py::test_cond[-1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[-2-[[1, 0, -1], [0, 1, 0], [1, 0, 1]]] diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 081f0b72350b..fad53428334a 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -216,7 +216,6 @@ tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsMult tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsMultivariateNormal_param_3_{d=4, shape=(3, 2)}::test_normal tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpctl_memory -tests/test_arraymanipulation.py::TestVstack::test_generator tests/test_linalg.py::test_cond[-1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] tests/test_linalg.py::test_cond[1-[[1, 2, 3], [4, 5, 6], [7, 8, 9]]] diff --git a/tests/test_arraymanipulation.py b/tests/test_arraymanipulation.py index df384fe39035..842391d53346 100644 --- a/tests/test_arraymanipulation.py +++ b/tests/test_arraymanipulation.py @@ -615,8 +615,8 @@ def test_2D_array2(self): assert_array_equal(res, desired) def test_generator(self): - with assert_warns(FutureWarning): - dpnp.vstack((numpy.arange(3) for _ in range(2))) + with pytest.raises(TypeError): + dpnp.vstack((dpnp.arange(3) for _ in range(2))) class TestAtleast1d: @@ -919,17 +919,17 @@ def test_can_cast(): def assert_broadcast_correct(input_shapes): np_arrays = [numpy.zeros(s, dtype="i1") for s in input_shapes] out_np_arrays = numpy.broadcast_arrays(*np_arrays) - usm_arrays = [dpnp.asarray(Xnp) for Xnp in np_arrays] - out_usm_arrays = dpnp.broadcast_arrays(*usm_arrays) - for Xnp, X in zip(out_np_arrays, out_usm_arrays): + dpnp_arrays = [dpnp.asarray(Xnp) for Xnp in np_arrays] + out_dpnp_arrays = dpnp.broadcast_arrays(*dpnp_arrays) + for Xnp, X in zip(out_np_arrays, out_dpnp_arrays): assert_array_equal( Xnp, dpnp.asnumpy(X), err_msg=f"Failed for {input_shapes})" ) def assert_broadcast_arrays_raise(input_shapes): - usm_arrays = [dpnp.asarray(numpy.zeros(s)) for s in input_shapes] - pytest.raises(ValueError, dpnp.broadcast_arrays, *usm_arrays) + dpnp_arrays = [dpnp.asarray(numpy.zeros(s)) for s in input_shapes] + pytest.raises(ValueError, dpnp.broadcast_arrays, *dpnp_arrays) def test_broadcast_arrays_same(): From 86e052cdb3b52a84078ac737deb12d462407ff2d Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Fri, 22 Sep 2023 17:02:15 -0500 Subject: [PATCH 04/13] Add more tests --- dpnp/dpnp_iface_manipulation.py | 5 ++++- tests/skipped_tests.tbl | 14 +++++++++++++- tests/skipped_tests_gpu.tbl | 14 +++++++++++++- .../cupy/manipulation_tests/test_dims.py | 2 -- .../cupy/manipulation_tests/test_join.py | 18 +++--------------- .../cupy/manipulation_tests/test_tiling.py | 4 ---- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 76b36f6e6158..bac5356acfea 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -964,10 +964,13 @@ def repeat(a, repeats, axis=None): """ - usm_arr = dpnp.get_usm_ndarray(a) rep = repeats if isinstance(repeats, dpnp_array): rep = dpnp.get_usm_ndarray(repeats) + if axis is None and a.ndim > 1: + usm_arr = dpnp.get_usm_ndarray(a.flatten()) + else: + usm_arr = dpnp.get_usm_ndarray(a) usm_arr = dpt.repeat(usm_arr, rep, axis=axis) return dpnp_array._create_from_usm_ndarray(usm_arr) diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index 4dcb41f6ccf3..0b3427674fbc 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -3,7 +3,6 @@ tests/test_histograms.py::TestHistogram::test_density tests/test_random.py::TestDistributionsMultivariateNormal::test_moments tests/test_random.py::TestDistributionsMultivariateNormal::test_output_shape_check tests/test_random.py::TestDistributionsMultivariateNormal::test_seed -tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.vstack([x, x]).T] tests/test_sycl_queue.py::test_1in_1out[opencl:gpu:0-trapz-data19] tests/test_sycl_queue.py::test_1in_1out[opencl:cpu:0-trapz-data19] @@ -496,6 +495,19 @@ tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_2_{reps tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_3_{reps=(0, 1)}::test_array_tile tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_4_{reps=(2, 3)}::test_array_tile tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_5_{reps=(2, 3, 4, 5)}::test_array_tile +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_4_{axis=1, repeats=[0, 0, 0]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_5_{axis=1, repeats=[1, 2, 3]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_6_{axis=-2, repeats=[1, 2, 3]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatListBroadcast_param_0_{axis=None, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatListBroadcast_param_1_{axis=1, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1D_param_3_{axis=None, repeats=[1, 2, 3, 4]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1D_param_4_{axis=0, repeats=[1, 2, 3, 4]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1DListBroadcast_param_0_{axis=None, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1DListBroadcast_param_1_{axis=0, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatFailure_param_1_{axis=0, repeats=[-3, -3]}::test_repeat_failure +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatFailure_param_2_{axis=None, repeats=[1, 2, 3]}::test_repeat_failure +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatFailure_param_3_{axis=1, repeats=[1, 2]}::test_repeat_failure + tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticBinary2_param_457_{arg1=array([[1, 2, 3], [4, 5, 6]], dtype=int32), arg2=array([[0, 1, 2], [3, 4, 5]], dtype=int32), dtype=float64, name='fmod', use_dtype=False}::test_binary tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticBinary2_param_465_{arg1=array([[1, 2, 3], [4, 5, 6]], dtype=int32), arg2=array([[0, 1, 2], [3, 4, 5]]), dtype=float64, name='fmod', use_dtype=False}::test_binary tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticBinary2_param_537_{arg1=array([[1, 2, 3], [4, 5, 6]]), arg2=array([[0, 1, 2], [3, 4, 5]], dtype=int32), dtype=float64, name='fmod', use_dtype=False}::test_binary diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index fad53428334a..9e83902d7a1a 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -143,7 +143,6 @@ tests/test_histograms.py::TestHistogram::test_density tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.astype(dpnp.asarray(x), dpnp.int8)] tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.astype(dpnp.asarray(x), object)] -tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.vstack([x, x]).T] tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItemRaise_param_0_{shape=(0,)}::test_item tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItemRaise_param_1_{shape=(2, 3)}::test_item tests/third_party/cupy/core_tests/test_ndarray_conversion.py::TestNdarrayItemRaise_param_2_{shape=(1, 0, 1)}::test_item @@ -639,6 +638,19 @@ tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_3_{reps tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_4_{reps=(2, 3)}::test_array_tile tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_5_{reps=(2, 3, 4, 5)}::test_array_tile +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_4_{axis=1, repeats=[0, 0, 0]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_5_{axis=1, repeats=[1, 2, 3]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_6_{axis=-2, repeats=[1, 2, 3]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatListBroadcast_param_0_{axis=None, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatListBroadcast_param_1_{axis=1, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1D_param_3_{axis=None, repeats=[1, 2, 3, 4]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1D_param_4_{axis=0, repeats=[1, 2, 3, 4]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1DListBroadcast_param_0_{axis=None, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat1DListBroadcast_param_1_{axis=0, repeats=[2]}::test_array_repeat +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatFailure_param_1_{axis=0, repeats=[-3, -3]}::test_repeat_failure +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatFailure_param_2_{axis=None, repeats=[1, 2, 3]}::test_repeat_failure +tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatFailure_param_3_{axis=1, repeats=[1, 2]}::test_repeat_failure + tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticRaisesWithNumpyInput_param_3_{name='angle', nargs=1}::test_raises_with_numpy_input tests/third_party/cupy/math_tests/test_explog.py::TestExplog::test_logaddexp diff --git a/tests/third_party/cupy/manipulation_tests/test_dims.py b/tests/third_party/cupy/manipulation_tests/test_dims.py index 461c0bb2ec2b..d0e815e3f0a2 100644 --- a/tests/third_party/cupy/manipulation_tests/test_dims.py +++ b/tests/third_party/cupy/manipulation_tests/test_dims.py @@ -27,7 +27,6 @@ def test_atleast_1d2(self, xp): a = testing.shaped_arange((1, 3, 2), xp) return xp.atleast_1d(a) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_atleast_2d1(self, xp): return self.check_atleast(xp.atleast_2d, xp) @@ -37,7 +36,6 @@ def test_atleast_2d2(self, xp): a = testing.shaped_arange((1, 3, 2), xp) return xp.atleast_2d(a) - @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.numpy_cupy_array_equal() def test_atleast_3d1(self, xp): return self.check_atleast(xp.atleast_3d, xp) diff --git a/tests/third_party/cupy/manipulation_tests/test_join.py b/tests/third_party/cupy/manipulation_tests/test_join.py index 8bffce98d875..e82258b84a52 100644 --- a/tests/third_party/cupy/manipulation_tests/test_join.py +++ b/tests/third_party/cupy/manipulation_tests/test_join.py @@ -312,27 +312,24 @@ def test_hstack_casting(self, xp, dtype1, dtype2, casting): # may raise TypeError or ComplexWarning return xp.hstack((a, b), dtype=dtype2, casting=casting) - @pytest.mark.skip("dpnp.vstack() is not implemented yet") @testing.numpy_cupy_array_equal() def test_vstack_vectors(self, xp): a = xp.arange(3) b = xp.arange(2, -1, -1) return xp.vstack((a, b)) - @pytest.mark.skip("dpnp.vstack() is not implemented yet") @testing.numpy_cupy_array_equal() def test_vstack_single_element(self, xp): a = xp.arange(3) return xp.vstack((a,)) - @pytest.mark.skip("dpnp.vstack() is not implemented yet") def test_vstack_wrong_ndim(self): a = cupy.empty((3,)) b = cupy.empty((3, 1)) with pytest.raises(ValueError): cupy.vstack((a, b)) - @pytest.mark.skip("dpnp.vstack() is not implemented yet") + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.with_requires("numpy>=1.24.0") @testing.for_all_dtypes_combination(names=["dtype1", "dtype2"]) @testing.numpy_cupy_array_equal(accept_error=TypeError) @@ -341,18 +338,9 @@ def test_vstack_dtype(self, xp, dtype1, dtype2): b = testing.shaped_arange((3, 4), xp, dtype1) return xp.vstack((a, b), dtype=dtype2) - @pytest.mark.skip("dpnp.vstack() is not implemented yet") + @pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.with_requires("numpy>=1.24.0") - @pytest.mark.parametrize( - "casting", - [ - "no", - "equiv", - "safe", - "same_kind", - "unsafe", - ], - ) + @testing.for_castings() @testing.for_all_dtypes_combination(names=["dtype1", "dtype2"]) @testing.numpy_cupy_array_equal( accept_error=(TypeError, numpy.ComplexWarning) diff --git a/tests/third_party/cupy/manipulation_tests/test_tiling.py b/tests/third_party/cupy/manipulation_tests/test_tiling.py index 575be6fe0afb..3a3bff5309c3 100644 --- a/tests/third_party/cupy/manipulation_tests/test_tiling.py +++ b/tests/third_party/cupy/manipulation_tests/test_tiling.py @@ -16,7 +16,6 @@ {"repeats": [1, 2, 3], "axis": 1}, {"repeats": [1, 2, 3], "axis": -2}, ) -@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeat(unittest.TestCase): @testing.numpy_cupy_array_equal() @@ -43,7 +42,6 @@ def test_method(self): {"repeats": [2], "axis": None}, {"repeats": [2], "axis": 1}, ) -@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeatListBroadcast(unittest.TestCase): @@ -65,7 +63,6 @@ def test_array_repeat(self, xp): {"repeats": [1, 2, 3, 4], "axis": None}, {"repeats": [1, 2, 3, 4], "axis": 0}, ) -@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeat1D(unittest.TestCase): @testing.numpy_cupy_array_equal() @@ -97,7 +94,6 @@ def test_array_repeat(self, xp): {"repeats": 2, "axis": -4}, {"repeats": 2, "axis": 3}, ) -@pytest.mark.usefixtures("allow_fall_back_on_numpy") @testing.gpu class TestRepeatFailure(unittest.TestCase): def test_repeat_failure(self): From c442a9e3497c2d1908889bb80561ee4b362e4d44 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Fri, 22 Sep 2023 18:29:30 -0500 Subject: [PATCH 05/13] Skip test with random on Iris Xe --- tests/skipped_tests_gpu_no_fp64.tbl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/skipped_tests_gpu_no_fp64.tbl b/tests/skipped_tests_gpu_no_fp64.tbl index 21aad4100b52..6fa021be82dd 100644 --- a/tests/skipped_tests_gpu_no_fp64.tbl +++ b/tests/skipped_tests_gpu_no_fp64.tbl @@ -15,6 +15,8 @@ tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[3.5-array0] tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[3.5-array1] tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[3.5-array2] +tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.vstack([x, x]).T] + tests/test_strides.py::test_strides_1arg[(10,)-int32-cbrt] tests/test_strides.py::test_strides_1arg[(10,)-int32-degrees] tests/test_strides.py::test_strides_1arg[(10,)-int32-exp] From fa06664eacdc8f0925e4a70b5917445bfb1a4913 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Mon, 25 Sep 2023 12:56:15 -0500 Subject: [PATCH 06/13] Removed broadcast_arrays tests from skip list --- tests/skipped_tests.tbl | 15 --------------- tests/skipped_tests_gpu.tbl | 15 --------------- 2 files changed, 30 deletions(-) diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index 0b3427674fbc..9e96a6491815 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -448,36 +448,21 @@ tests/third_party/cupy/logic_tests/test_comparison.py::TestArrayEqual::test_arra tests/third_party/cupy/logic_tests/test_comparison.py::TestArrayEqual::test_array_equal_is_equal tests/third_party/cupy/logic_tests/test_comparison.py::TestArrayEqual::test_array_equal_not_equal tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_0_{shapes=[(), ()]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_0_{shapes=[(), ()]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_10_{shapes=[(0, 1, 1, 0, 3), (5, 2, 0, 1, 0, 0, 3), (2, 1, 0, 0, 0, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_10_{shapes=[(0, 1, 1, 0, 3), (5, 2, 0, 1, 0, 0, 3), (2, 1, 0, 0, 0, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_1_{shapes=[(0,), (0,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_1_{shapes=[(0,), (0,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_2_{shapes=[(1,), (1,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_2_{shapes=[(1,), (1,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_3_{shapes=[(2,), (2,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_3_{shapes=[(2,), (2,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_4_{shapes=[(0,), (1,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_4_{shapes=[(0,), (1,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_5_{shapes=[(2, 3), (1, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_5_{shapes=[(2, 3), (1, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_6_{shapes=[(2, 1, 3, 4), (3, 1, 4)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_6_{shapes=[(2, 1, 3, 4), (3, 1, 4)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_7_{shapes=[(4, 3, 2, 3), (2, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_7_{shapes=[(4, 3, 2, 3), (2, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_8_{shapes=[(2, 0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_8_{shapes=[(2, 0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_9_{shapes=[(0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_9_{shapes=[(0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_0_{shapes=[(3,), (2,)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_0_{shapes=[(3,), (2,)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_1_{shapes=[(3, 2), (2, 3)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_1_{shapes=[(3, 2), (2, 3)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_2_{shapes=[(3, 2), (3, 4)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_2_{shapes=[(3, 2), (3, 4)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_3_{shapes=[(0,), (2,)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_3_{shapes=[(0,), (2,)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel2 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel3 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_external_ravel diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 9e83902d7a1a..4f282dc041d1 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -590,36 +590,21 @@ tests/third_party/cupy/logic_tests/test_comparison.py::TestArrayEqual::test_arra tests/third_party/cupy/logic_tests/test_comparison.py::TestArrayEqual::test_array_equal_not_equal tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_0_{shapes=[(), ()]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_0_{shapes=[(), ()]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_10_{shapes=[(0, 1, 1, 0, 3), (5, 2, 0, 1, 0, 0, 3), (2, 1, 0, 0, 0, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_10_{shapes=[(0, 1, 1, 0, 3), (5, 2, 0, 1, 0, 0, 3), (2, 1, 0, 0, 0, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_1_{shapes=[(0,), (0,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_1_{shapes=[(0,), (0,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_2_{shapes=[(1,), (1,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_2_{shapes=[(1,), (1,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_3_{shapes=[(2,), (2,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_3_{shapes=[(2,), (2,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_4_{shapes=[(0,), (1,)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_4_{shapes=[(0,), (1,)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_5_{shapes=[(2, 3), (1, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_5_{shapes=[(2, 3), (1, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_6_{shapes=[(2, 1, 3, 4), (3, 1, 4)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_6_{shapes=[(2, 1, 3, 4), (3, 1, 4)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_7_{shapes=[(4, 3, 2, 3), (2, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_7_{shapes=[(4, 3, 2, 3), (2, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_8_{shapes=[(2, 0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_8_{shapes=[(2, 0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_9_{shapes=[(0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestBroadcast_param_9_{shapes=[(0, 1, 1, 3), (2, 1, 0, 0, 3)]}::test_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_0_{shapes=[(3,), (2,)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_0_{shapes=[(3,), (2,)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_1_{shapes=[(3, 2), (2, 3)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_1_{shapes=[(3, 2), (2, 3)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_2_{shapes=[(3, 2), (3, 4)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_2_{shapes=[(3, 2), (3, 4)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_3_{shapes=[(0,), (2,)]}::test_invalid_broadcast -tests/third_party/cupy/manipulation_tests/test_dims.py::TestInvalidBroadcast_param_3_{shapes=[(0,), (2,)]}::test_invalid_broadcast_arrays tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel2 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel3 tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_external_ravel From 485fb608c13bd774e234951c1a0635b09ba577ed Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 28 Sep 2023 16:14:50 -0500 Subject: [PATCH 07/13] Clean up dpnp_astype and dpnp_flatten functions --- dpnp/dparray.pxd | 1 - dpnp/dparray.pyx | 137 +++++------------- dpnp/dpnp_algo/dpnp_algo.pxd | 5 - dpnp/dpnp_algo/dpnp_algo.pyx | 92 ------------ dpnp/dpnp_array.py | 61 ++++---- dpnp/dpnp_iface.py | 41 +++++- dpnp/dpnp_iface_manipulation.py | 24 +-- dpnp/dpnp_iface_types.py | 2 +- dpnp/linalg/dpnp_algo_linalg.pyx | 6 +- dpnp/random/dpnp_algo_random.pyx | 6 +- dpnp/random/dpnp_iface_random.py | 2 +- dpnp/random/dpnp_random_state.py | 14 +- tests/skipped_tests.tbl | 4 + tests/skipped_tests_gpu.tbl | 4 + tests/test_random_state.py | 48 +++--- .../cupy/creation_tests/test_ranges.py | 4 +- 16 files changed, 155 insertions(+), 296 deletions(-) diff --git a/dpnp/dparray.pxd b/dpnp/dparray.pxd index 9f94db42f40d..95a2963c7d00 100644 --- a/dpnp/dparray.pxd +++ b/dpnp/dparray.pxd @@ -50,4 +50,3 @@ cdef class dparray: cdef void * get_data(self) cpdef item(self, id=*) - cpdef dparray astype(self, dtype, order=*, casting=*, subok=*, copy=*) diff --git a/dpnp/dparray.pyx b/dpnp/dparray.pyx index e8d9dd2e345e..d64ae9a82457 100644 --- a/dpnp/dparray.pyx +++ b/dpnp/dparray.pyx @@ -40,13 +40,8 @@ from libcpp cimport bool as cpp_bool import numpy -from dpnp.dpnp_algo import ( - dpnp_astype, - dpnp_flatten, -) - # to avoid interference with Python internal functions -from dpnp.dpnp_iface import asnumpy +from dpnp.dpnp_iface import asnumpy, astype from dpnp.dpnp_iface import get_dpnp_descriptor as iface_get_dpnp_descriptor from dpnp.dpnp_iface import prod as iface_prod from dpnp.dpnp_iface import sum as iface_sum @@ -110,7 +105,9 @@ from dpnp.dpnp_iface_logic import ( # TODO do the same as for iface_sum ) from dpnp.dpnp_iface_manipulation import ( copyto, + ravel, repeat, + reshape, squeeze, transpose, ) @@ -584,11 +581,10 @@ cdef class dparray: Parameters ---------- - order: {'C', 'F', 'A', 'K'}, optional + order: {'C', 'F'}, optional 'C' means to flatten in row-major (C-style) order. 'F' means to flatten in column-major (Fortran- style) order. - 'A' means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. - 'K' means to flatten a in the order the elements occur in memory. The default is 'C'. + The default is 'C'. Returns ------- @@ -601,30 +597,7 @@ cdef class dparray: """ - if not utils.use_origin_backend(self): - c_order, fortran_order = self.flags.c_contiguous, self.flags.f_contiguous - - if order not in {'C', 'F', 'A', 'K'}: - pass - elif order == 'K' and not c_order and not fortran_order: - # skip dpnp backend if both C-style and Fortran-style order not found in flags - pass - else: - if order == 'K': - # either C-style or Fortran-style found in flags - order = 'C' if c_order else 'F' - elif order == 'A': - order = 'F' if fortran_order else 'C' - - if order == 'F': - return self.transpose().reshape(self.size) - - self_desc = iface_get_dpnp_descriptor(self) - return dpnp_flatten(self_desc).get_pyobj() - - result = dp2nd_array(self).flatten(order=order) - - return nd2dp_array(result) + return ravel(self, order=order) def ravel(self, order='C'): """ @@ -632,11 +605,10 @@ cdef class dparray: Parameters ---------- - order: {'C', 'F', 'A', 'K'}, optional + order: {'C', 'F'}, optional 'C' means to flatten in row-major (C-style) order. 'F' means to flatten in column-major (Fortran- style) order. - 'A' means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. - 'K' means to flatten a in the order the elements occur in memory. The default is 'C'. + The default is 'C'. Returns ------- @@ -654,8 +626,8 @@ cdef class dparray: :obj:`dpnp.ravel`, :obj:`dpnp.flat` """ - # TODO: don't copy the input array - return self.flatten(order=order) + + return ravel(self, order=order) def reshape(self, d0, *dn, order=b'C'): """Change the shape of the array. @@ -665,39 +637,7 @@ cdef class dparray: """ - if order is not b'C': - utils.checker_throw_value_error("dparray::reshape", "order", order, b'C') - - if dn: - if not isinstance(d0, int): - msg_tmpl = "'{}' object cannot be interpreted as an integer" - raise TypeError(msg_tmpl.format(type(d0).__name__)) - shape = [d0, *dn] - else: - shape = d0 - - cdef long shape_it = 0 - cdef tuple shape_tup = utils._object_to_tuple(shape) - cdef size_previous = self.size - - cdef long size_new = 1 - cdef shape_type_c shape_new - shape_new.reserve(len(shape_tup)) - - for shape_it in shape_tup: - if shape_it < 0: - utils.checker_throw_value_error("dparray::reshape", "shape", shape_it, ">=0") - - shape_new.push_back(shape_it) - size_new *= shape_it - - if size_new != size_previous: - utils.checker_throw_value_error("dparray::reshape", "shape", size_new, size_previous) - - self._dparray_shape = shape_new - self._dparray_size = size_new - - return self + return reshape(self, d0, *dn, order=b'C') def repeat(self, *args, **kwds): """ Repeat elements of an array. @@ -870,47 +810,36 @@ cdef class dparray: def __truediv__(self, other): return divide(self, other) - cpdef dparray astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True): - """Copy the array with data type casting. + def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True): + """ + Copy the array with data type casting. - Args: - dtype: Target type. - order ({'C', 'F', 'A', 'K'}): Row-major (C-style) or column-major (Fortran-style) order. - When ``order`` is 'A', it uses 'F' if ``a`` is column-major and uses 'C' otherwise. - And when ``order`` is 'K', it keeps strides as closely as possible. - copy (bool): If it is False and no cast happens, then this method returns the array itself. - Otherwise, a copy is returned. + Parameters + ---------- + dtype : dtype + Target data type. + order : {'C', 'F', 'A', 'K'} + Row-major (C-style) or column-major (Fortran-style) order. + When ``order`` is 'A', it uses 'F' if ``a`` is column-major and uses 'C' otherwise. + And when ``order`` is 'K', it keeps strides as closely as possible. + copy : bool + If it is False and no cast happens, then this method returns the array itself. + Otherwise, a copy is returned. - Returns: + Returns + ------- + out : dpnp.array If ``copy`` is False and no cast is required, then the array itself is returned. Otherwise, it returns a (possibly casted) copy of the array. - .. note:: - This method currently does not support `order``, `casting``, ``copy``, and ``subok`` arguments. - - .. seealso:: :meth:`numpy.ndarray.astype` + Limitations + ----------- + Parameter `subok` is supported with default value. + Otherwise the function will be executed sequentially on CPU. """ - if casting is not 'unsafe': - pass - elif subok is not True: - pass - elif copy is not True: - pass - elif order is not 'K': - pass - elif self.dtype == numpy.complex128 or dtype == numpy.complex128: - pass - elif self.dtype == numpy.complex64 or dtype == numpy.complex64: - pass - else: - self_desc = iface_get_dpnp_descriptor(self) - return dpnp_astype(self_desc, dtype).get_pyobj() - - result = dp2nd_array(self).astype(dtype=dtype, order=order, casting=casting, subok=subok, copy=copy) - - return nd2dp_array(result) + return astype(self, dtype, order=order, casting=casting, subok=subok, copy=copy) def conj(self): """ diff --git a/dpnp/dpnp_algo/dpnp_algo.pxd b/dpnp/dpnp_algo/dpnp_algo.pxd index ffafd0d62550..c55b04feebb5 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -45,7 +45,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_ARGSORT DPNP_FN_ARGSORT_EXT DPNP_FN_ASTYPE - DPNP_FN_ASTYPE_EXT DPNP_FN_CBRT DPNP_FN_CBRT_EXT DPNP_FN_CHOLESKY @@ -103,7 +102,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_FILL_DIAGONAL DPNP_FN_FILL_DIAGONAL_EXT DPNP_FN_FLATTEN - DPNP_FN_FLATTEN_EXT DPNP_FN_FMOD DPNP_FN_FMOD_EXT DPNP_FN_FULL @@ -351,9 +349,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*dpnp_reduction_c_t)(c_dpctl.DPCTLSyclQueueRe const long*, const c_dpctl.DPCTLEventVectorRef) -cpdef dpnp_descriptor dpnp_astype(dpnp_descriptor x1, dtype) -cpdef dpnp_descriptor dpnp_flatten(dpnp_descriptor x1) - """ Internal functions diff --git a/dpnp/dpnp_algo/dpnp_algo.pyx b/dpnp/dpnp_algo/dpnp_algo.pyx index 305088927075..54e58220717d 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pyx +++ b/dpnp/dpnp_algo/dpnp_algo.pyx @@ -54,8 +54,6 @@ import operator import numpy __all__ = [ - "dpnp_astype", - "dpnp_flatten", "dpnp_queue_initialize", ] @@ -73,96 +71,6 @@ include "dpnp_algo_statistics.pxi" include "dpnp_algo_trigonometric.pxi" -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_astype_t)(c_dpctl.DPCTLSyclQueueRef, - const void *, void * , const size_t, - const c_dpctl.DPCTLEventVectorRef) -ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_flatten_t)(c_dpctl.DPCTLSyclQueueRef, - void *, const size_t, const size_t, - const shape_elem_type * , const shape_elem_type * , - void *, const size_t, const size_t, - const shape_elem_type * , const shape_elem_type * , - const long * , - const c_dpctl.DPCTLEventVectorRef) - - -cpdef utils.dpnp_descriptor dpnp_astype(utils.dpnp_descriptor x1, dtype): - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype) - cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(dtype) - - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_ASTYPE_EXT, param1_type, param2_type) - - x1_obj = x1.get_array() - - # ceate result array with type given by FPTR data - cdef shape_type_c result_shape = x1.shape - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, - kernel_data.return_type, - None, - device=x1_obj.sycl_device, - usm_type=x1_obj.usm_type, - sycl_queue=x1_obj.sycl_queue) - - result_sycl_queue = result.get_array().sycl_queue - - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef fptr_dpnp_astype_t func = kernel_data.ptr - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, x1.get_data(), result.get_data(), x1.size, NULL) - - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) - c_dpctl.DPCTLEvent_Delete(event_ref) - - return result - - -cpdef utils.dpnp_descriptor dpnp_flatten(utils.dpnp_descriptor x1): - cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype) - - cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_FLATTEN_EXT, param1_type, param1_type) - - cdef shape_type_c x1_shape = x1.shape - cdef shape_type_c x1_strides = utils.strides_to_vector(x1.strides, x1_shape) - - x1_obj = x1.get_array() - - # ceate result array with type given by FPTR data - cdef shape_type_c result_shape = (x1.size,) - cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, - kernel_data.return_type, - None, - device=x1_obj.sycl_device, - usm_type=x1_obj.usm_type, - sycl_queue=x1_obj.sycl_queue) - - result_sycl_queue = result.get_array().sycl_queue - - cdef c_dpctl.SyclQueue q = result_sycl_queue - cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref() - - cdef shape_type_c result_strides = utils.strides_to_vector(result.strides, result_shape) - - cdef fptr_dpnp_flatten_t func = kernel_data.ptr - cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref, - result.get_data(), - result.size, - result.ndim, - result_shape.data(), - result_strides.data(), - x1.get_data(), - x1.size, - x1.ndim, - x1_shape.data(), - x1_strides.data(), - NULL, - NULL) # dep_events_ref - - with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref) - c_dpctl.DPCTLEvent_Delete(event_ref) - - return result - - cpdef dpnp_queue_initialize(): """ Initialize SYCL queue which will be used for any library operations. diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 252fa17c5b43..915273c43efe 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -595,32 +595,37 @@ def asnumpy(self): return dpt.asnumpy(self._array_obj) def astype(self, dtype, order="K", casting="unsafe", subok=True, copy=True): - """Copy the array with data type casting. + """ + Copy the array with data type casting. - Args: - dtype: Target type. - order ({'C', 'F', 'A', 'K'}): Row-major (C-style) or column-major (Fortran-style) order. - When ``order`` is 'A', it uses 'F' if ``a`` is column-major and uses 'C' otherwise. - And when ``order`` is 'K', it keeps strides as closely as possible. - copy (bool): If it is False and no cast happens, then this method returns the array itself. - Otherwise, a copy is returned. + Parameters + ---------- + dtype : dtype + Target data type. + order : {'C', 'F', 'A', 'K'} + Row-major (C-style) or column-major (Fortran-style) order. + When ``order`` is 'A', it uses 'F' if ``a`` is column-major and uses 'C' otherwise. + And when ``order`` is 'K', it keeps strides as closely as possible. + copy : bool + If it is False and no cast happens, then this method returns the array itself. + Otherwise, a copy is returned. - Returns: + Returns + ------- + out : dpnp.array If ``copy`` is False and no cast is required, then the array itself is returned. Otherwise, it returns a (possibly casted) copy of the array. - .. note:: - This method currently does not support `order``, `casting``, ``copy``, and ``subok`` arguments. - - .. seealso:: :meth:`numpy.ndarray.astype` + Limitations + ----------- + Parameter `subok` is supported with default value. + Otherwise the function will be executed sequentially on CPU. """ - new_array = self.__new__(dpnp_array) - new_array._array_obj = dpt.astype( - self._array_obj, dtype, order=order, casting=casting, copy=copy + return dpnp.astype( + self, dtype, order=order, casting=casting, subok=subok, copy=copy ) - return new_array # 'base', # 'byteswap', @@ -784,11 +789,10 @@ def flatten(self, order="C"): Parameters ---------- - order: {'C', 'F', 'A', 'K'}, optional + order: {'C', 'F'}, optional 'C' means to flatten in row-major (C-style) order. 'F' means to flatten in column-major (Fortran- style) order. - 'A' means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. - 'K' means to flatten a in the order the elements occur in memory. The default is 'C'. + The default is 'C'. Returns ------- @@ -800,23 +804,8 @@ def flatten(self, order="C"): :obj:`dpnp.ravel`, :obj:`dpnp.flat` """ - new_arr = self.__new__(dpnp_array) - new_arr._array_obj = dpt.empty( - self.shape, - dtype=self.dtype, - order=order, - device=self._array_obj.sycl_device, - usm_type=self._array_obj.usm_type, - sycl_queue=self._array_obj.sycl_queue, - ) - - if self.size > 0: - dpt._copy_utils._copy_from_usm_ndarray_to_usm_ndarray( - new_arr._array_obj, self._array_obj - ) - new_arr._array_obj = dpt.reshape(new_arr._array_obj, (self.size,)) - return new_arr + return self.reshape(-1, order=order) # 'getfield', diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index 4c6082dd6b14..80809914ad5b 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -46,6 +46,7 @@ import dpctl.tensor as dpt import numpy +import dpnp from dpnp.dpnp_algo import * from dpnp.dpnp_array import dpnp_array from dpnp.dpnp_utils import * @@ -150,17 +151,41 @@ def asnumpy(input, order="C"): def astype(x1, dtype, order="K", casting="unsafe", subok=True, copy=True): - """Copy the array with data type casting.""" + """ + Copy the array with data type casting. + + Parameters + ---------- + dtype : dtype + Target data type. + order : {'C', 'F', 'A', 'K'} + Row-major (C-style) or column-major (Fortran-style) order. + When ``order`` is 'A', it uses 'F' if ``a`` is column-major and uses 'C' otherwise. + And when ``order`` is 'K', it keeps strides as closely as possible. + copy : bool + If it is False and no cast happens, then this method returns the array itself. + Otherwise, a copy is returned. + + Returns + ------- + out : dpnp.array + If ``copy`` is False and no cast is required, then the array itself is returned. + Otherwise, it returns a (possibly casted) copy of the array. + + Limitations + ----------- + Parameter `subok` is supported with default value. + Otherwise the function will be executed sequentially on CPU. + + """ if subok is not True: pass else: - if isinstance(x1, dpnp_array): - return x1.astype(dtype, order=order, casting=casting, copy=copy) - - if isinstance(x1, dpt.usm_ndarray): - return dpt.astype( - x1, dtype, order=order, casting=casting, copy=copy - ) + usm_arr = dpnp.get_usm_ndarray(x1) + usm_arr = dpt.astype( + usm_arr, dtype, order=order, casting=casting, copy=copy + ) + return dpnp_array._create_from_usm_ndarray(usm_arr) return call_origin( numpy.ndarray.astype, diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index bac5356acfea..c2e35a6807b7 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -293,6 +293,14 @@ def broadcast_arrays(*args, subok=False): Broadcast any number of arrays against each other. For full documentation refer to :obj:`numpy.broadcast_arrays`. + + Limitations + ----------- + Parameter `args` 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. + """ if subok is not False: @@ -907,25 +915,21 @@ def ravel(a, order="C"): Limitations ----------- - Input array is supported as :obj:`dpnp.ndarray`. - Otherwise the function will be executed sequentially on CPU. + Parameters `a` is supported as either :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. Otherwise ``TypeError`` exception + will be raised. Input array data types are limited by supported DPNP :ref:`Data types`. Examples -------- >>> import dpnp as np >>> x = np.array([[1, 2, 3], [4, 5, 6]]) - >>> out = np.ravel(x) - >>> [i for i in out] - [1, 2, 3, 4, 5, 6] + >>> np.ravel(x) + array([1, 2, 3, 4, 5, 6]) """ - 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, a, order=order) + return dpnp.reshape(a, -1, order=order) def repeat(a, repeats, axis=None): diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index 86627115d4fa..1a2c118feb27 100644 --- a/dpnp/dpnp_iface_types.py +++ b/dpnp/dpnp_iface_types.py @@ -37,7 +37,7 @@ import dpctl.tensor as dpt import numpy -import dpnp.dpnp_array as dpnp_array +from dpnp.dpnp_array import dpnp_array __all__ = [ "bool", diff --git a/dpnp/linalg/dpnp_algo_linalg.pyx b/dpnp/linalg/dpnp_algo_linalg.pyx index 39ba81bac593..3598a05d9f4f 100644 --- a/dpnp/linalg/dpnp_algo_linalg.pyx +++ b/dpnp/linalg/dpnp_algo_linalg.pyx @@ -118,7 +118,8 @@ cpdef utils.dpnp_descriptor dpnp_cholesky(utils.dpnp_descriptor input_): cpdef object dpnp_cond(object input, object p): if p in ('f', 'fro'): - input = dpnp.ravel(input, order='K') + # TODO: change order='K' when support is implemented + input = dpnp.ravel(input, order='C') sqnorm = dpnp.dot(input, input) res = dpnp.sqrt(sqnorm) ret = dpnp.array([res]) @@ -374,7 +375,8 @@ cpdef object dpnp_norm(object input, ord=None, axis=None): (ord in ('f', 'fro') and ndim == 2) or (ord == 2 and ndim == 1)): - input = dpnp.ravel(input, order='K') + # TODO: change order='K' when support is implemented + input = dpnp.ravel(input, order='C') sqnorm = dpnp.dot(input, input) ret = dpnp.sqrt([sqnorm], dtype=res_type) return dpnp.array(ret.reshape(1, *ret.shape), dtype=res_type) diff --git a/dpnp/random/dpnp_algo_random.pyx b/dpnp/random/dpnp_algo_random.pyx index e9206bd6682c..0422cfa0c2fa 100644 --- a/dpnp/random/dpnp_algo_random.pyx +++ b/dpnp/random/dpnp_algo_random.pyx @@ -462,7 +462,7 @@ cdef class MT19937(_Engine): if value < 0: return False - max_val = numpy.iinfo(numpy.uint32).max + max_val = dpnp.iinfo(numpy.uint32).max if isinstance(value, dpnp_array): max_val = dpnp.array(max_val, dtype=numpy.uint32) return value <= max_val @@ -499,7 +499,7 @@ cdef class MCG59(_Engine): if value < 0: return False - max_val = numpy.iinfo(numpy.uint64).max + max_val = dpnp.iinfo(numpy.uint64).max if isinstance(value, dpnp_array): max_val = dpnp.array(max_val, dtype=numpy.uint64) return value <= max_val @@ -1052,7 +1052,7 @@ cpdef utils.dpnp_descriptor dpnp_rng_negative_binomial(double a, double p, size) result_shape = utils._object_to_tuple(size) if p == 0.0: - filled_val = numpy.iinfo(dtype).min + filled_val = dpnp.iinfo(dtype).min return utils.dpnp_descriptor(dpnp.full(result_shape, filled_val, dtype=dtype)) elif p == 1.0: return utils.dpnp_descriptor(dpnp.full(result_shape, 0, dtype=dtype)) diff --git a/dpnp/random/dpnp_iface_random.py b/dpnp/random/dpnp_iface_random.py index 7a7f981f0945..efdeac14c194 100644 --- a/dpnp/random/dpnp_iface_random.py +++ b/dpnp/random/dpnp_iface_random.py @@ -674,7 +674,7 @@ def multinomial(n, pvals, size=None): d = len(pvals) if n < 0: pass - elif n > numpy.iinfo(dpnp.int32).max: + elif n > dpnp.iinfo(dpnp.int32).max: pass elif pvals_sum > 1.0: pass diff --git a/dpnp/random/dpnp_random_state.py b/dpnp/random/dpnp_random_state.py index 4d6f8d22a716..a3d8d7be9a90 100644 --- a/dpnp/random/dpnp_random_state.py +++ b/dpnp/random/dpnp_random_state.py @@ -81,7 +81,7 @@ def __init__(self, seed=None, device=None, sycl_queue=None): is_cpu = self._sycl_device.is_cpu if seed is None: low = 0 - high = numpy.iinfo(numpy.int32).max + 1 + high = dpnp.iinfo(dpnp.int32).max + 1 if is_cpu: # ask NumPy to generate an array of three random integers as default seed value @@ -237,8 +237,8 @@ def normal( dtype = self._validate_float_dtype( dtype, (dpnp.float32, dpnp.float64) ) - min_floating = numpy.finfo(dtype).min - max_floating = numpy.finfo(dtype).max + min_floating = dpnp.finfo(dtype).min + max_floating = dpnp.finfo(dtype).max if ( loc >= max_floating or loc <= min_floating @@ -371,8 +371,8 @@ def randint(self, low, high=None, size=None, dtype=int, usm_type="device"): high = low low = 0 - min_int = numpy.iinfo("int32").min - max_int = numpy.iinfo("int32").max + min_int = dpnp.iinfo("int32").min + max_int = dpnp.iinfo("int32").max if ( not self._is_finite_scalar(low) @@ -587,8 +587,8 @@ def uniform( elif not dpnp.isscalar(high): pass else: - min_double = numpy.finfo("double").min - max_double = numpy.finfo("double").max + min_double = dpnp.finfo("double").min + max_double = dpnp.finfo("double").max if ( not self._is_finite_scalar(low) diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index ba58858b331d..fc91751734b1 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -203,6 +203,10 @@ tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_cons tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_extraction_from_nested_list tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_extraction_from_nested_tuple +tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diagflat_from_scalar +tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diagflat_from_scalar_with_k0 +tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diagflat_from_scalar_with_k1 + tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_0_{copy=False, indexing='xy', sparse=False}::test_meshgrid0 tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_0_{copy=False, indexing='xy', sparse=False}::test_meshgrid1 tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_0_{copy=False, indexing='xy', sparse=False}::test_meshgrid2 diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 1e8f8e492838..bcd23b65273f 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -158,6 +158,10 @@ tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_cons tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_extraction_from_nested_list tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diag_extraction_from_nested_tuple +tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diagflat_from_scalar +tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diagflat_from_scalar_with_k0 +tests/third_party/cupy/creation_tests/test_matrix.py::TestMatrix::test_diagflat_from_scalar_with_k1 + tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_4_{shape=(3, 3), val=(2,), wrap=True}::test_1darray tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_4_{shape=(3, 3), val=(2,), wrap=True}::test_fill_diagonal tests/third_party/cupy/indexing_tests/test_insert.py::TestFillDiagonal_param_5_{shape=(3, 3), val=(2,), wrap=False}::test_1darray diff --git a/tests/test_random_state.py b/tests/test_random_state.py index f6be26202fbb..cbc4299cd9ce 100644 --- a/tests/test_random_state.py +++ b/tests/test_random_state.py @@ -91,9 +91,9 @@ def test_distr(self, dtype, usm_type): ) # TODO: discuss with opneMKL: there is a difference between CPU and GPU # generated samples since 9 digit while precision=15 for float64 - # precision = numpy.finfo(dtype=dtype).precision + # precision = dpnp.finfo(dtype=dtype).precision precision = ( - 8 if dtype == dpnp.float64 else numpy.finfo(dtype=dtype).precision + 8 if dtype == dpnp.float64 else dpnp.finfo(dtype=dtype).precision ) assert_array_almost_equal( dpnp_data.asnumpy(), expected, decimal=precision @@ -170,8 +170,8 @@ def test_inf_loc_scale(self, loc): def test_extreme_bounds(self): dtype = get_default_floating() - fmin = numpy.finfo(dtype).min - fmax = numpy.finfo(dtype).max + fmin = dpnp.finfo(dtype).min + fmax = dpnp.finfo(dtype).max size = 1000 func = RandomState(34567).normal @@ -228,7 +228,7 @@ def test_fallback(self, loc, scale): ) dtype = get_default_floating() - precision = numpy.finfo(dtype=dtype).precision + precision = dpnp.finfo(dtype=dtype).precision assert_array_almost_equal(actual, expected, decimal=precision) # check if compute follows data isn't broken @@ -310,7 +310,7 @@ def test_distr(self, usm_type): dtype=dtype, ) - precision = numpy.finfo(dtype=dtype).precision + precision = dpnp.finfo(dtype=dtype).precision assert_array_almost_equal(data.asnumpy(), expected, decimal=precision) assert_cfd(data, sycl_queue, usm_type) @@ -464,8 +464,8 @@ def test_negative_interval(self): def test_bounds_checking(self): dtype = dpnp.int32 func = RandomState().randint - low = numpy.iinfo(dtype).min - high = numpy.iinfo(dtype).max + low = dpnp.iinfo(dtype).min + high = dpnp.iinfo(dtype).max # inf can't be converted to int boundary assert_raises(OverflowError, func, -numpy.inf, 0) @@ -486,8 +486,8 @@ def test_bounds_checking(self): def test_rng_zero_and_extremes(self): dtype = dpnp.int32 func = RandomState().randint - low = numpy.iinfo(dtype).min - high = numpy.iinfo(dtype).max + low = dpnp.iinfo(dtype).min + high = dpnp.iinfo(dtype).max sycl_device = dpctl.SyclQueue().sycl_device if sycl_device.has_aspect_gpu and not sycl_device.has_aspect_fp64: @@ -507,8 +507,8 @@ def test_rng_zero_and_extremes(self): def test_full_range(self): dtype = dpnp.int32 - low = numpy.iinfo(dtype).min - high = numpy.iinfo(dtype).max + low = dpnp.iinfo(dtype).min + high = dpnp.iinfo(dtype).max try: RandomState().randint(low, high) @@ -642,8 +642,8 @@ def test_distr(self, usm_type): # TODO: discuss with opneMKL: there is a difference between CPU and GPU # generated samples since 9 digit while precision=15 for float64 - # precision = numpy.finfo(dtype=numpy.float64).precision - precision = numpy.finfo(dtype=numpy.float32).precision + # precision = dpnp.finfo(dtype=dpnp.float64).precision + precision = dpnp.finfo(dtype=dpnp.float32).precision assert_array_almost_equal(data.asnumpy(), expected, decimal=precision) # call with the same seed has to draw the same values @@ -707,7 +707,7 @@ def test_scalar(self, func): rs = RandomState(seed) a2 = getattr(rs, func)(size=size).asnumpy() - precision = numpy.finfo(dtype=numpy.float64).precision + precision = dpnp.finfo(dtype=dpnp.float64).precision assert_array_almost_equal(a1, a2, decimal=precision) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @@ -879,8 +879,8 @@ def test_distr(self, usm_type): # TODO: discuss with opneMKL: there is a difference between CPU and GPU # generated samples since 9 digit while precision=15 for float64 - # precision = numpy.finfo(dtype=numpy.float64).precision - precision = numpy.finfo(dtype=numpy.float32).precision + # precision = dpnp.finfo(dtype=dpnp.float64).precision + precision = dpnp.finfo(dtype=dpnp.float32).precision assert_array_almost_equal(data.asnumpy(), expected, decimal=precision) # call with the same seed has to draw the same values @@ -957,7 +957,7 @@ def test_distr(self, usm_type): dtype=dtype, ) - precision = numpy.finfo(dtype=dtype).precision + precision = dpnp.finfo(dtype=dtype).precision assert_array_almost_equal(data.asnumpy(), expected, decimal=precision) # call with omitted dimensions has to draw the first element from expected @@ -1042,7 +1042,7 @@ def test_distr(self, bounds, dtype, usm_type): ] ) assert_array_almost_equal( - actual, expected, decimal=numpy.finfo(dtype=dtype).precision + actual, expected, decimal=dpnp.finfo(dtype=dtype).precision ) else: expected = numpy.array([[3, 8], [2, 4], [1, 4]]) @@ -1057,7 +1057,7 @@ def test_distr(self, bounds, dtype, usm_type): ] ) assert_array_almost_equal( - actual, expected, decimal=numpy.finfo(dtype=dtype).precision + actual, expected, decimal=dpnp.finfo(dtype=dtype).precision ) else: expected = numpy.array([[1, 4], [5, 1], [3, 7]]) @@ -1101,13 +1101,13 @@ def test_low_high_equal(self, dtype, usm_type): assert_array_equal(actual, expected) else: assert_array_almost_equal( - actual, expected, decimal=numpy.finfo(dtype=dtype).precision + actual, expected, decimal=dpnp.finfo(dtype=dtype).precision ) @pytest.mark.usefixtures("allow_fall_back_on_numpy") def test_range_bounds(self): - fmin = numpy.finfo("double").min - fmax = numpy.finfo("double").max + fmin = dpnp.finfo("double").min + fmax = dpnp.finfo("double").max func = RandomState().uniform assert_raises(OverflowError, func, -numpy.inf, 0) @@ -1146,7 +1146,7 @@ def test_fallback(self, low, high): ) dtype = get_default_floating() - precision = numpy.finfo(dtype=dtype).precision + precision = dpnp.finfo(dtype=dtype).precision assert_array_almost_equal(actual, expected, decimal=precision) # check if compute follows data isn't broken diff --git a/tests/third_party/cupy/creation_tests/test_ranges.py b/tests/third_party/cupy/creation_tests/test_ranges.py index c165b4e94a29..be2f113a3181 100644 --- a/tests/third_party/cupy/creation_tests/test_ranges.py +++ b/tests/third_party/cupy/creation_tests/test_ranges.py @@ -141,13 +141,13 @@ def test_linspace_neg_num(self): @testing.numpy_cupy_allclose() def test_linspace_float_overflow(self, xp): dtype = cupy.default_float_type() - return xp.linspace(0.0, numpy.finfo(dtype).max / 5, 10, dtype=dtype) + return xp.linspace(0.0, xp.finfo(dtype).max / 5, 10, dtype=dtype) @testing.numpy_cupy_allclose() def test_linspace_float_underflow(self, xp): # find minimum subnormal number dtype = cupy.default_float_type() - x = numpy.finfo(dtype).min + x = xp.finfo(dtype).min while x / 2 > 0: x /= 2 return xp.linspace(0.0, x, 10, dtype=dtype) From 201a8a3f3b498a4f240c411f498b2b5a034a35bd Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Tue, 3 Oct 2023 01:03:26 -0500 Subject: [PATCH 08/13] Old implementation removed --- dpnp/backend/include/dpnp_iface_fptr.hpp | 38 +++------- dpnp/backend/kernels/dpnp_krnl_common.cpp | 65 ----------------- dpnp/backend/kernels/dpnp_krnl_elemwise.cpp | 19 +---- dpnp/backend/kernels/dpnp_krnl_logic.cpp | 56 ++------------ .../kernels/dpnp_krnl_manipulation.cpp | 18 ----- .../kernels/dpnp_krnl_mathematical.cpp | 20 +---- dpnp/dpnp_algo/dpnp_algo.pxd | 2 - dpnp/dpnp_array.py | 18 +++++ dpnp/dpnp_iface_manipulation.py | 73 +++++++++++++++++++ dpnp/dpnp_iface_types.py | 6 -- tests/skipped_tests.tbl | 9 --- tests/skipped_tests_gpu.tbl | 9 --- 12 files changed, 114 insertions(+), 219 deletions(-) diff --git a/dpnp/backend/include/dpnp_iface_fptr.hpp b/dpnp/backend/include/dpnp_iface_fptr.hpp index dd9a9a97df37..408ab8843ab4 100644 --- a/dpnp/backend/include/dpnp_iface_fptr.hpp +++ b/dpnp/backend/include/dpnp_iface_fptr.hpp @@ -88,8 +88,6 @@ enum class DPNPFuncName : size_t parameters */ DPNP_FN_AROUND, /**< Used in numpy.around() impl */ DPNP_FN_ASTYPE, /**< Used in numpy.astype() impl */ - DPNP_FN_ASTYPE_EXT, /**< Used in numpy.astype() impl, requires extra - parameters */ DPNP_FN_BITWISE_AND, /**< Used in numpy.bitwise_and() impl */ DPNP_FN_BITWISE_OR, /**< Used in numpy.bitwise_or() impl */ DPNP_FN_BITWISE_XOR, /**< Used in numpy.bitwise_xor() impl */ @@ -160,8 +158,6 @@ enum class DPNPFuncName : size_t DPNP_FN_EIGVALS, /**< Used in numpy.linalg.eigvals() impl */ DPNP_FN_EIGVALS_EXT, /**< Used in numpy.linalg.eigvals() impl, requires extra parameters */ - DPNP_FN_EQUAL_EXT, /**< Used in numpy.equal() impl, requires extra - parameters */ DPNP_FN_ERF, /**< Used in scipy.special.erf impl */ DPNP_FN_ERF_EXT, /**< Used in scipy.special.erf impl, requires extra parameters */ @@ -187,25 +183,17 @@ enum class DPNPFuncName : size_t DPNP_FN_FILL_DIAGONAL_EXT, /**< Used in numpy.fill_diagonal() impl, requires extra parameters */ DPNP_FN_FLATTEN, /**< Used in numpy.flatten() impl */ - DPNP_FN_FLATTEN_EXT, /**< Used in numpy.flatten() impl, requires extra - parameters */ DPNP_FN_FLOOR, /**< Used in numpy.floor() impl */ DPNP_FN_FLOOR_DIVIDE, /**< Used in numpy.floor_divide() impl */ - DPNP_FN_FLOOR_DIVIDE_EXT, /**< Used in numpy.floor_divide() impl, requires - extra parameters */ DPNP_FN_FMOD, /**< Used in numpy.fmod() impl */ DPNP_FN_FMOD_EXT, /**< Used in numpy.fmod() impl, requires extra parameters */ DPNP_FN_FULL, /**< Used in numpy.full() impl */ DPNP_FN_FULL_LIKE, /**< Used in numpy.full_like() impl */ - DPNP_FN_GREATER_EXT, /**< Used in numpy.greater() impl, requires extra - parameters */ - DPNP_FN_GREATER_EQUAL_EXT, /**< Used in numpy.greater_equal() impl, requires - extra parameters */ - DPNP_FN_HYPOT, /**< Used in numpy.hypot() impl */ - DPNP_FN_HYPOT_EXT, /**< Used in numpy.hypot() impl, requires extra - parameters */ - DPNP_FN_IDENTITY, /**< Used in numpy.identity() impl */ + DPNP_FN_HYPOT, /**< Used in numpy.hypot() impl */ + DPNP_FN_HYPOT_EXT, /**< Used in numpy.hypot() impl, requires extra + parameters */ + DPNP_FN_IDENTITY, /**< Used in numpy.identity() impl */ DPNP_FN_IDENTITY_EXT, /**< Used in numpy.identity() impl, requires extra parameters */ DPNP_FN_INITVAL, /**< Used in numpy ones, ones_like, zeros, zeros_like impls @@ -220,15 +208,11 @@ enum class DPNPFuncName : size_t DPNP_FN_KRON_EXT, /**< Used in numpy.kron() impl, requires extra parameters */ DPNP_FN_LEFT_SHIFT, /**< Used in numpy.left_shift() impl */ - DPNP_FN_LESS_EXT, /**< Used in numpy.less() impl, requires extra parameters - */ - DPNP_FN_LESS_EQUAL_EXT, /**< Used in numpy.less_equal() impl, requires extra - parameters */ - DPNP_FN_LOG, /**< Used in numpy.log() impl */ - DPNP_FN_LOG10, /**< Used in numpy.log10() impl */ - DPNP_FN_LOG10_EXT, /**< Used in numpy.log10() impl, requires extra - parameters */ - DPNP_FN_LOG2, /**< Used in numpy.log2() impl */ + DPNP_FN_LOG, /**< Used in numpy.log() impl */ + DPNP_FN_LOG10, /**< Used in numpy.log10() impl */ + DPNP_FN_LOG10_EXT, /**< Used in numpy.log10() impl, requires extra + parameters */ + DPNP_FN_LOG2, /**< Used in numpy.log2() impl */ DPNP_FN_LOG2_EXT, /**< Used in numpy.log2() impl, requires extra parameters */ DPNP_FN_LOG1P, /**< Used in numpy.log1p() impl */ @@ -265,8 +249,6 @@ enum class DPNPFuncName : size_t parameters */ DPNP_FN_NEGATIVE, /**< Used in numpy.negative() impl */ DPNP_FN_NONZERO, /**< Used in numpy.nonzero() impl */ - DPNP_FN_NOT_EQUAL_EXT, /**< Used in numpy.not_equal() impl, requires extra - parameters */ DPNP_FN_ONES, /**< Used in numpy.ones() impl */ DPNP_FN_ONES_LIKE, /**< Used in numpy.ones_like() impl */ DPNP_FN_PARTITION, /**< Used in numpy.partition() impl */ @@ -294,8 +276,6 @@ enum class DPNPFuncName : size_t DPNP_FN_RECIP_EXT, /**< Used in numpy.recip() impl, requires extra parameters */ DPNP_FN_REPEAT, /**< Used in numpy.repeat() impl */ - DPNP_FN_REPEAT_EXT, /**< Used in numpy.repeat() impl, requires extra - parameters */ DPNP_FN_RIGHT_SHIFT, /**< Used in numpy.right_shift() impl */ DPNP_FN_RNG_BETA, /**< Used in numpy.random.beta() impl */ DPNP_FN_RNG_BETA_EXT, /**< Used in numpy.random.beta() impl, requires extra diff --git a/dpnp/backend/kernels/dpnp_krnl_common.cpp b/dpnp/backend/kernels/dpnp_krnl_common.cpp index dd6c8119c1b8..358fe693f59c 100644 --- a/dpnp/backend/kernels/dpnp_krnl_common.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_common.cpp @@ -101,14 +101,6 @@ template void (*dpnp_astype_default_c)(const void *, void *, const size_t) = dpnp_astype_c<_DataType, _ResultType>; -template -DPCTLSyclEventRef (*dpnp_astype_ext_c)(DPCTLSyclQueueRef, - const void *, - void *, - const size_t, - const DPCTLEventVectorRef) = - dpnp_astype_c<_DataType, _ResultType>; - template @@ -1035,63 +1027,6 @@ void func_map_init_linalg(func_map_t &fmap) (void *) dpnp_astype_default_c, std::complex>}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_BLN][eft_BLN] = { - eft_BLN, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_BLN][eft_INT] = { - eft_INT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_BLN][eft_LNG] = { - eft_LNG, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_BLN][eft_FLT] = { - eft_FLT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_BLN][eft_DBL] = { - eft_DBL, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_INT][eft_BLN] = { - eft_BLN, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_INT][eft_INT] = { - eft_INT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_INT][eft_LNG] = { - eft_LNG, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_INT][eft_FLT] = { - eft_FLT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_INT][eft_DBL] = { - eft_DBL, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_LNG][eft_BLN] = { - eft_BLN, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_LNG][eft_INT] = { - eft_INT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_LNG][eft_LNG] = { - eft_LNG, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_LNG][eft_FLT] = { - eft_FLT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_LNG][eft_DBL] = { - eft_DBL, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_FLT][eft_BLN] = { - eft_BLN, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_FLT][eft_INT] = { - eft_INT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_FLT][eft_LNG] = { - eft_LNG, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_FLT][eft_FLT] = { - eft_FLT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_FLT][eft_DBL] = { - eft_DBL, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_DBL][eft_BLN] = { - eft_BLN, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_DBL][eft_INT] = { - eft_INT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_DBL][eft_LNG] = { - eft_LNG, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_DBL][eft_FLT] = { - eft_FLT, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_DBL][eft_DBL] = { - eft_DBL, (void *)dpnp_astype_ext_c}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_C64][eft_C64] = { - eft_C64, - (void *)dpnp_astype_ext_c, std::complex>}; - fmap[DPNPFuncName::DPNP_FN_ASTYPE_EXT][eft_C128][eft_C128] = { - eft_C128, - (void *)dpnp_astype_ext_c, std::complex>}; - fmap[DPNPFuncName::DPNP_FN_DOT][eft_INT][eft_INT] = { eft_INT, (void *)dpnp_dot_default_c}; fmap[DPNPFuncName::DPNP_FN_DOT][eft_INT][eft_LNG] = { diff --git a/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp b/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp index 4b26da44853e..d9e574846290 100644 --- a/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp @@ -949,19 +949,6 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap) fmap[DPNPFuncName::DPNP_FN_FLATTEN][eft_C128][eft_C128] = { eft_C128, (void *)dpnp_copy_c_default>}; - fmap[DPNPFuncName::DPNP_FN_FLATTEN_EXT][eft_BLN][eft_BLN] = { - eft_BLN, (void *)dpnp_copy_c_ext}; - fmap[DPNPFuncName::DPNP_FN_FLATTEN_EXT][eft_INT][eft_INT] = { - eft_INT, (void *)dpnp_copy_c_ext}; - fmap[DPNPFuncName::DPNP_FN_FLATTEN_EXT][eft_LNG][eft_LNG] = { - eft_LNG, (void *)dpnp_copy_c_ext}; - fmap[DPNPFuncName::DPNP_FN_FLATTEN_EXT][eft_FLT][eft_FLT] = { - eft_FLT, (void *)dpnp_copy_c_ext}; - fmap[DPNPFuncName::DPNP_FN_FLATTEN_EXT][eft_DBL][eft_DBL] = { - eft_DBL, (void *)dpnp_copy_c_ext}; - fmap[DPNPFuncName::DPNP_FN_FLATTEN_EXT][eft_C128][eft_C128] = { - eft_C128, (void *)dpnp_copy_c_ext>}; - fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_INT][eft_INT] = { eft_INT, (void *)dpnp_negative_c_default}; fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_LNG][eft_LNG] = { @@ -1251,7 +1238,8 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap) sg.get_group_id()[0] * max_sg_size); \ \ if (start + static_cast(vec_sz) * max_sg_size < \ - result_size) { \ + result_size) \ + { \ auto input1_multi_ptr = sycl::address_space_cast< \ sycl::access::address_space::global_space, \ sycl::access::decorated::yes>( \ @@ -1313,7 +1301,8 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap) } \ else { \ for (size_t k = start + sg.get_local_id()[0]; \ - k < result_size; k += max_sg_size) { \ + k < result_size; k += max_sg_size) \ + { \ const _DataType_output input1_elem = \ input1_data[k]; \ const _DataType_output input2_elem = \ diff --git a/dpnp/backend/kernels/dpnp_krnl_logic.cpp b/dpnp/backend/kernels/dpnp_krnl_logic.cpp index 429f9d96f1ea..16e494b33e17 100644 --- a/dpnp/backend/kernels/dpnp_krnl_logic.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_logic.cpp @@ -181,17 +181,20 @@ static sycl::event dpnp_allclose(sycl::queue &q, continue; } else if (array1[i] == - -std::numeric_limits<_DataType1>::infinity()) { + -std::numeric_limits<_DataType1>::infinity()) + { partial &= (array1[i] == array2[i]); continue; } else if (array2[i] == - std::numeric_limits<_DataType2>::infinity()) { + std::numeric_limits<_DataType2>::infinity()) + { partial &= (array1[i] == array2[i]); continue; } else if (array2[i] == - -std::numeric_limits<_DataType2>::infinity()) { + -std::numeric_limits<_DataType2>::infinity()) + { partial &= (array1[i] == array2[i]); continue; } @@ -611,7 +614,8 @@ DPCTLSyclEventRef (*dpnp_any_ext_c)(DPCTLSyclQueueRef, sg.get_group_id()[0] * max_sg_size); \ \ if (start + static_cast(vec_sz) * max_sg_size < \ - result_size) { \ + result_size) \ + { \ auto input1_multi_ptr = sycl::address_space_cast< \ sycl::access::address_space::global_space, \ sycl::access::decorated::yes>(&input1_data[start]); \ @@ -667,47 +671,6 @@ DPCTLSyclEventRef (*dpnp_any_ext_c)(DPCTLSyclQueueRef, const DPCTLEventVectorRef) = \ __name__<_DataType_input1, _DataType_input2>; -#include - -template -static void func_map_logic_2arg_2type_core(func_map_t &fmap) -{ - ((fmap[DPNPFuncName::DPNP_FN_EQUAL_EXT][FT1][FTs] = - {eft_BLN, (void *)dpnp_equal_c_ext, - func_type_map_t::find_type>}), - ...); - ((fmap[DPNPFuncName::DPNP_FN_GREATER_EXT][FT1][FTs] = - {eft_BLN, - (void *)dpnp_greater_c_ext, - func_type_map_t::find_type>}), - ...); - ((fmap[DPNPFuncName::DPNP_FN_GREATER_EQUAL_EXT][FT1][FTs] = - {eft_BLN, - (void *)dpnp_greater_equal_c_ext, - func_type_map_t::find_type>}), - ...); - ((fmap[DPNPFuncName::DPNP_FN_LESS_EXT][FT1][FTs] = - {eft_BLN, (void *)dpnp_less_c_ext, - func_type_map_t::find_type>}), - ...); - ((fmap[DPNPFuncName::DPNP_FN_LESS_EQUAL_EXT][FT1][FTs] = - {eft_BLN, - (void *)dpnp_less_equal_c_ext, - func_type_map_t::find_type>}), - ...); - ((fmap[DPNPFuncName::DPNP_FN_NOT_EQUAL_EXT][FT1][FTs] = - {eft_BLN, - (void *)dpnp_not_equal_c_ext, - func_type_map_t::find_type>}), - ...); -} - -template -static void func_map_logic_2arg_2type_helper(func_map_t &fmap) -{ - ((func_map_logic_2arg_2type_core(fmap)), ...); -} - void func_map_init_logic(func_map_t &fmap) { fmap[DPNPFuncName::DPNP_FN_ALL][eft_BLN][eft_BLN] = { @@ -798,8 +761,5 @@ void func_map_init_logic(func_map_t &fmap) fmap[DPNPFuncName::DPNP_FN_ANY][eft_DBL][eft_DBL] = { eft_DBL, (void *)dpnp_any_default_c}; - func_map_logic_2arg_2type_helper(fmap); - return; } diff --git a/dpnp/backend/kernels/dpnp_krnl_manipulation.cpp b/dpnp/backend/kernels/dpnp_krnl_manipulation.cpp index 12e275e90b90..315e1c211f96 100644 --- a/dpnp/backend/kernels/dpnp_krnl_manipulation.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_manipulation.cpp @@ -103,15 +103,6 @@ void (*dpnp_repeat_default_c)(const void *, const size_t, const size_t) = dpnp_repeat_c<_DataType>; -template -DPCTLSyclEventRef (*dpnp_repeat_ext_c)(DPCTLSyclQueueRef, - const void *, - void *, - const size_t, - const size_t, - const DPCTLEventVectorRef) = - dpnp_repeat_c<_DataType>; - template class dpnp_elemwise_transpose_c_kernel; @@ -232,15 +223,6 @@ void func_map_init_manipulation(func_map_t &fmap) fmap[DPNPFuncName::DPNP_FN_REPEAT][eft_DBL][eft_DBL] = { eft_DBL, (void *)dpnp_repeat_default_c}; - fmap[DPNPFuncName::DPNP_FN_REPEAT_EXT][eft_INT][eft_INT] = { - eft_INT, (void *)dpnp_repeat_ext_c}; - fmap[DPNPFuncName::DPNP_FN_REPEAT_EXT][eft_LNG][eft_LNG] = { - eft_LNG, (void *)dpnp_repeat_ext_c}; - fmap[DPNPFuncName::DPNP_FN_REPEAT_EXT][eft_FLT][eft_FLT] = { - eft_FLT, (void *)dpnp_repeat_ext_c}; - fmap[DPNPFuncName::DPNP_FN_REPEAT_EXT][eft_DBL][eft_DBL] = { - eft_DBL, (void *)dpnp_repeat_ext_c}; - fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_INT][eft_INT] = { eft_INT, (void *)dpnp_elemwise_transpose_default_c}; fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_LNG][eft_LNG] = { diff --git a/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp b/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp index b4f5cd96b4d0..9eef64bd9233 100644 --- a/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp @@ -181,7 +181,8 @@ DPCTLSyclEventRef } else { for (size_t k = start + sg.get_local_id()[0]; k < size; - k += max_sg_size) { + k += max_sg_size) + { result[k] = std::abs(array1[k]); } } @@ -726,23 +727,6 @@ void (*dpnp_floor_divide_default_c)(void *, const size_t *) = dpnp_floor_divide_c<_DataType_output, _DataType_input1, _DataType_input2>; -template -DPCTLSyclEventRef (*dpnp_floor_divide_ext_c)(DPCTLSyclQueueRef, - void *, - const void *, - const size_t, - const shape_elem_type *, - const size_t, - const void *, - const size_t, - const shape_elem_type *, - const size_t, - const size_t *, - const DPCTLEventVectorRef) = - dpnp_floor_divide_c<_DataType_output, _DataType_input1, _DataType_input2>; - template class dpnp_modf_c_kernel; diff --git a/dpnp/dpnp_algo/dpnp_algo.pxd b/dpnp/dpnp_algo/dpnp_algo.pxd index c55b04feebb5..2ce4115beb97 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -86,7 +86,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_ERF DPNP_FN_ERF_EXT DPNP_FN_EYE - DPNP_FN_EYE_EXT DPNP_FN_EXP DPNP_FN_EXP_EXT DPNP_FN_EXP2 @@ -155,7 +154,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_RECIP DPNP_FN_RECIP_EXT DPNP_FN_REPEAT - DPNP_FN_REPEAT_EXT DPNP_FN_RNG_BETA DPNP_FN_RNG_BETA_EXT DPNP_FN_RNG_BINOMIAL diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 915273c43efe..536dad159603 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -621,6 +621,15 @@ def astype(self, dtype, order="K", casting="unsafe", subok=True, copy=True): Parameter `subok` is supported with default value. Otherwise the function will be executed sequentially on CPU. + Examples + -------- + >>> import dpnp as np + >>> x = np.array([1, 2, 2.5]) + >>> x + array([1. , 2. , 2.5]) + >>> x.astype(int) + array([1, 2, 2]) + """ return dpnp.astype( @@ -803,6 +812,15 @@ def flatten(self, order="C"): -------- :obj:`dpnp.ravel`, :obj:`dpnp.flat` + Examples + -------- + >>> import dpnp as np + >>> a = np.array([[1,2], [3,4]]) + >>> a.flatten() + array([1, 2, 3, 4]) + >>> a.flatten('F') + array([1, 3, 2, 4]) + """ return self.reshape(-1, order=order) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index c2e35a6807b7..3277f7140567 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -75,6 +75,7 @@ "squeeze", "stack", "swapaxes", + "tile", "transpose", "unique", "vstack", @@ -1429,6 +1430,78 @@ def swapaxes(a, axis1, axis2): ) +def tile(a, reps): + """ + Construct an array by repeating A the number of times given by reps. + + If `reps` has length ``d``, the result will have dimension of + ``max(d, A.ndim)``. + + If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new + axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication, + or shape (1, 1, 3) for 3-D replication. If this is not the desired + behavior, promote `A` to d-dimensions manually before calling this + function. + + If ``A.ndim > d``, `reps` is promoted to `A`.ndim by prepending 1's to it. + Thus for an `A` of shape (2, 3, 4, 5), a `reps` of (2, 2) is treated as + (1, 1, 2, 2). + + Note : Although tile may be used for broadcasting, it is strongly + recommended to use numpy's broadcasting operations and functions. + + Parameters + ---------- + A : dpnp_array + The input array. + reps : array_like + The number of repetitions of `a` along each axis. + + Returns + ------- + c : dpnp_array + The tiled output array. + + See Also + -------- + :obj:`dpnp.repeat` : Repeat elements of an array. + :obj:`dpnp.broadcast_to` : Broadcast an array to a new shape + + Examples + -------- + >>> import dpnp as np + >>> a = np.array([0, 1, 2]) + >>> np.tile(a, 2) + array([0, 1, 2, 0, 1, 2]) + >>> np.tile(a, (2, 2)) + array([[0, 1, 2, 0, 1, 2], + [0, 1, 2, 0, 1, 2]]) + >>> np.tile(a, (2, 1, 2)) + array([[[0, 1, 2, 0, 1, 2]], + [[0, 1, 2, 0, 1, 2]]]) + + >>> b = np.array([[1, 2], [3, 4]]) + >>> np.tile(b, 2) + array([[1, 2, 1, 2], + [3, 4, 3, 4]]) + >>> np.tile(b, (2, 1)) + array([[1, 2], + [3, 4], + [1, 2], + [3, 4]]) + + >>> c = np.array([1, 2, 3, 4]) + >>> np.tile(c, (4, 1)) + array([[1, 2, 3, 4], + [1, 2, 3, 4], + [1, 2, 3, 4], + [1, 2, 3, 4]]) + """ + + dpt_array = dpnp.get_usm_ndarray(a) + return dpnp_array._create_from_usm_ndarray(dpt.tile(dpt_array, reps)) + + def transpose(a, axes=None): """ Returns an array with axes transposed. diff --git a/dpnp/dpnp_iface_types.py b/dpnp/dpnp_iface_types.py index 1a2c118feb27..85db8d31a2cc 100644 --- a/dpnp/dpnp_iface_types.py +++ b/dpnp/dpnp_iface_types.py @@ -72,7 +72,6 @@ "int64", "integer", "intc", - "isdtype", "isscalar", "issubdtype", "issubsctype", @@ -184,11 +183,6 @@ def finfo(dtype): return dpt.finfo(dtype) -def isdtype(dtype_, kind): - """Returns a boolean indicating whether a provided `dtype` is of a specified data type `kind`.""" - return dpt.isdtype(dtype_, kind) - - def iinfo(dtype): """ Returns machine limits for integer data types. diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index fc91751734b1..94bb5984c4dd 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -461,16 +461,7 @@ tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize2 -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_func tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_method -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTileFailure_param_0_{reps=-1}::test_tile_failure -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTileFailure_param_1_{reps=(-1, -2)}::test_tile_failure -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_0_{reps=0}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_1_{reps=1}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_2_{reps=2}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_3_{reps=(0, 1)}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_4_{reps=(2, 3)}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_5_{reps=(2, 3, 4, 5)}::test_array_tile tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_4_{axis=1, repeats=[0, 0, 0]}::test_array_repeat tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_5_{axis=1, repeats=[1, 2, 3]}::test_array_repeat tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_6_{axis=-2, repeats=[1, 2, 3]}::test_array_repeat diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index bcd23b65273f..32ff5e165823 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -603,16 +603,7 @@ tests/third_party/cupy/manipulation_tests/test_shape.py::TestRavel::test_ravel tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize tests/third_party/cupy/manipulation_tests/test_shape.py::TestReshape::test_reshape_zerosize2 -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_func tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeatRepeatsNdarray::test_method -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTileFailure_param_0_{reps=-1}::test_tile_failure -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTileFailure_param_1_{reps=(-1, -2)}::test_tile_failure -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_0_{reps=0}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_1_{reps=1}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_2_{reps=2}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_3_{reps=(0, 1)}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_4_{reps=(2, 3)}::test_array_tile -tests/third_party/cupy/manipulation_tests/test_tiling.py::TestTile_param_5_{reps=(2, 3, 4, 5)}::test_array_tile tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_4_{axis=1, repeats=[0, 0, 0]}::test_array_repeat tests/third_party/cupy/manipulation_tests/test_tiling.py::TestRepeat_param_5_{axis=1, repeats=[1, 2, 3]}::test_array_repeat From 589f9475e826c295c521dc64856a060dc7165f75 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 5 Oct 2023 11:31:31 -0500 Subject: [PATCH 09/13] address comments --- dpnp/dpnp_algo/dpnp_algo.pxd | 4 ---- dpnp/dpnp_iface_manipulation.py | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_algo.pxd b/dpnp/dpnp_algo/dpnp_algo.pxd index 2ce4115beb97..fb998bc5e3ad 100644 --- a/dpnp/dpnp_algo/dpnp_algo.pxd +++ b/dpnp/dpnp_algo/dpnp_algo.pxd @@ -44,7 +44,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_ARGMIN_EXT DPNP_FN_ARGSORT DPNP_FN_ARGSORT_EXT - DPNP_FN_ASTYPE DPNP_FN_CBRT DPNP_FN_CBRT_EXT DPNP_FN_CHOLESKY @@ -85,7 +84,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_EIGVALS_EXT DPNP_FN_ERF DPNP_FN_ERF_EXT - DPNP_FN_EYE DPNP_FN_EXP DPNP_FN_EXP_EXT DPNP_FN_EXP2 @@ -100,7 +98,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_FFT_RFFT_EXT DPNP_FN_FILL_DIAGONAL DPNP_FN_FILL_DIAGONAL_EXT - DPNP_FN_FLATTEN DPNP_FN_FMOD DPNP_FN_FMOD_EXT DPNP_FN_FULL @@ -153,7 +150,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na DPNP_FN_RADIANS_EXT DPNP_FN_RECIP DPNP_FN_RECIP_EXT - DPNP_FN_REPEAT DPNP_FN_RNG_BETA DPNP_FN_RNG_BETA_EXT DPNP_FN_RNG_BINOMIAL diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 3277f7140567..fdcb0456612e 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -1430,9 +1430,9 @@ def swapaxes(a, axis1, axis2): ) -def tile(a, reps): +def tile(A, reps): """ - Construct an array by repeating A the number of times given by reps. + Construct an array by repeating `A` the number of times given by reps. If `reps` has length ``d``, the result will have dimension of ``max(d, A.ndim)``. @@ -1455,7 +1455,7 @@ def tile(a, reps): A : dpnp_array The input array. reps : array_like - The number of repetitions of `a` along each axis. + The number of repetitions of `A` along each axis. Returns ------- @@ -1498,7 +1498,7 @@ def tile(a, reps): [1, 2, 3, 4]]) """ - dpt_array = dpnp.get_usm_ndarray(a) + dpt_array = dpnp.get_usm_ndarray(A) return dpnp_array._create_from_usm_ndarray(dpt.tile(dpt_array, reps)) From 5164a7b572a6e259b38c0705142af89156b5c30a Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 5 Oct 2023 09:47:11 -0700 Subject: [PATCH 10/13] fix pre-commit --- dpnp/backend/include/dpnp_iface_fptr.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpnp/backend/include/dpnp_iface_fptr.hpp b/dpnp/backend/include/dpnp_iface_fptr.hpp index c8a462aec0cc..b8a879659bb1 100644 --- a/dpnp/backend/include/dpnp_iface_fptr.hpp +++ b/dpnp/backend/include/dpnp_iface_fptr.hpp @@ -190,8 +190,8 @@ enum class DPNPFuncName : size_t */ DPNP_FN_FULL, /**< Used in numpy.full() impl */ DPNP_FN_FULL_LIKE, /**< Used in numpy.full_like() impl */ - DPNP_FN_HYPOT, /**< Used in numpy.hypot() impl */ - DPNP_FN_IDENTITY, /**< Used in numpy.identity() impl */ + DPNP_FN_HYPOT, /**< Used in numpy.hypot() impl */ + DPNP_FN_IDENTITY, /**< Used in numpy.identity() impl */ DPNP_FN_IDENTITY_EXT, /**< Used in numpy.identity() impl, requires extra parameters */ DPNP_FN_INITVAL, /**< Used in numpy ones, ones_like, zeros, zeros_like impls From ab8e482ede86cb27b1d2dd36f9b33126af6e5ab7 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 5 Oct 2023 09:49:48 -0700 Subject: [PATCH 11/13] fix pre-commit --- dpnp/backend/kernels/dpnp_krnl_elemwise.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp b/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp index 5237889c5e9d..f11705c8f95a 100644 --- a/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_elemwise.cpp @@ -1238,8 +1238,7 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap) sg.get_group_id()[0] * max_sg_size); \ \ if (start + static_cast(vec_sz) * max_sg_size < \ - result_size) \ - { \ + result_size) { \ auto input1_multi_ptr = sycl::address_space_cast< \ sycl::access::address_space::global_space, \ sycl::access::decorated::yes>( \ @@ -1301,8 +1300,7 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap) } \ else { \ for (size_t k = start + sg.get_local_id()[0]; \ - k < result_size; k += max_sg_size) \ - { \ + k < result_size; k += max_sg_size) { \ const _DataType_output input1_elem = \ input1_data[k]; \ const _DataType_output input2_elem = \ From 91827677b0f2ccd6b590f79a1a9b54117562be97 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 5 Oct 2023 09:51:55 -0700 Subject: [PATCH 12/13] fix pre-commit --- dpnp/backend/kernels/dpnp_krnl_logic.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/dpnp/backend/kernels/dpnp_krnl_logic.cpp b/dpnp/backend/kernels/dpnp_krnl_logic.cpp index 16e494b33e17..fc28b5f05fb4 100644 --- a/dpnp/backend/kernels/dpnp_krnl_logic.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_logic.cpp @@ -181,20 +181,17 @@ static sycl::event dpnp_allclose(sycl::queue &q, continue; } else if (array1[i] == - -std::numeric_limits<_DataType1>::infinity()) - { + -std::numeric_limits<_DataType1>::infinity()) { partial &= (array1[i] == array2[i]); continue; } else if (array2[i] == - std::numeric_limits<_DataType2>::infinity()) - { + std::numeric_limits<_DataType2>::infinity()) { partial &= (array1[i] == array2[i]); continue; } else if (array2[i] == - -std::numeric_limits<_DataType2>::infinity()) - { + -std::numeric_limits<_DataType2>::infinity()) { partial &= (array1[i] == array2[i]); continue; } @@ -614,8 +611,7 @@ DPCTLSyclEventRef (*dpnp_any_ext_c)(DPCTLSyclQueueRef, sg.get_group_id()[0] * max_sg_size); \ \ if (start + static_cast(vec_sz) * max_sg_size < \ - result_size) \ - { \ + result_size) { \ auto input1_multi_ptr = sycl::address_space_cast< \ sycl::access::address_space::global_space, \ sycl::access::decorated::yes>(&input1_data[start]); \ From 30a34340ce1d10e497fcad35bbf69a1bab8d3e4d Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Thu, 5 Oct 2023 09:52:42 -0700 Subject: [PATCH 13/13] fix pre-commit --- dpnp/backend/kernels/dpnp_krnl_mathematical.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp b/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp index 9eef64bd9233..949271e9b5b1 100644 --- a/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp +++ b/dpnp/backend/kernels/dpnp_krnl_mathematical.cpp @@ -181,8 +181,7 @@ DPCTLSyclEventRef } else { for (size_t k = start + sg.get_local_id()[0]; k < size; - k += max_sg_size) - { + k += max_sg_size) { result[k] = std::abs(array1[k]); } }