diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 44f67ea77eab..7dad92d81611 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -789,47 +789,51 @@ def astype( Parameters ---------- - x1 : {dpnp.ndarray, usm_ndarray} - Array data type casting. dtype : {None, str, dtype object} Target data type. - order : {"C", "F", "A", "K"}, optional + order : {None, "C", "F", "A", "K"}, optional 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. - casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional - Controls what kind of data casting may occur. - Defaults to ``'unsafe'`` for backwards compatibility. - - - 'no' means the data types should not be cast at all. - - 'equiv' means only byte-order changes are allowed. - - 'safe' means only casts which can preserve values are allowed. - - 'same_kind' means only safe casts or casts within a kind, like - float64 to float32, are allowed. - - 'unsafe' means any data conversions may be done. - - copy : {bool}, optional - By default, ``astype`` always returns a newly allocated array. If - this is set to ``False``, and the `dtype`, `order`, and `subok` - requirements are satisfied, the input array is returned instead of - a copy. - device : {None, string, SyclDevice, SyclQueue}, optional + 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. + + Default: ``"K"``. + casting : {"no", "equiv", "safe", "same_kind", "unsafe"}, optional + Controls what kind of data casting may occur. Defaults to + ``"unsafe"`` for backwards compatibility. + + - "no" means the data types should not be cast at all. + - "equiv" means only byte-order changes are allowed. + - "safe" means only casts which can preserve values are allowed. + - "same_kind" means only safe casts or casts within a kind, + like float64 to float32, are allowed. + - "unsafe" means any data conversions may be done. + + Default: ``"unsafe"``. + copy : bool, optional + Specifies whether to copy an array when the specified dtype matches + the data type of that array. If ``True``, a newly allocated array + must always be returned. If ``False`` and the specified dtype + matches the data type of that array, the self array must be returned; + otherwise, a newly allocated array must be returned. + + Default: ``True``. + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. Default: ``None``. + `device` can be ``None``, a oneAPI filter selector string, + an instance of :class:`dpctl.SyclDevice` corresponding to + a non-partitioned SYCL device, an instance of + :class:`dpctl.SyclQueue`, or a :class:`dpctl.tensor.Device` object + returned by :attr:`dpnp.ndarray.device`. + If the value is ``None``, returned array is created on the same + device as that array. + + Default: ``None``. Returns ------- - arr_t : dpnp.ndarray - Unless `copy` is ``False`` and the other conditions for returning the input array - are satisfied, `arr_t` is a new array of the same shape as the input array, - with dtype, order given by dtype, order. + out : dpnp.ndarray + An array having the specified data type. Limitations ----------- @@ -839,9 +843,9 @@ def astype( Examples -------- >>> import dpnp as np - >>> x = np.array([1, 2, 2.5]) - >>> x + >>> x = np.array([1, 2, 2.5]); x array([1. , 2. , 2.5]) + >>> x.astype(int) array([1, 2, 2]) @@ -925,13 +929,14 @@ def copy(self, order="C", device=None, usm_type=None, sycl_queue=None): order : {"C", "F", "A", "K"}, optional Memory layout of the newly output array. Default: ``"C"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter - selector string, an instance of :class:`dpctl.SyclDevice` - corresponding to a non-partitioned SYCL device, an instance of - :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, + an instance of :class:`dpctl.SyclDevice` corresponding to + a non-partitioned SYCL device, an instance of + :class:`dpctl.SyclQueue`, or a :class:`dpctl.tensor.Device` object + returned by :attr:`dpnp.ndarray.device`. + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1821,12 +1826,13 @@ def to_device(self, device, /, *, stream=None): Parameters ---------- - device : {string, SyclDevice, SyclQueue} - Array API concept of target device. It can be an OneAPI filter - selector string, an instance of :class:`dpctl.SyclDevice` - corresponding to a non-partitioned SYCL device, an instance of + device : {None, string, SyclDevice, SyclQueue, Device}, optional + An array API concept of device where the output array is created. + `device` can be ``None``, a oneAPI filter selector string, + an instance of :class:`dpctl.SyclDevice` corresponding to + a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, or a :class:`dpctl.tensor.Device` object - returned by :obj:`dpnp.dpnp_array.dpnp_array.device` property. + returned by :attr:`dpnp.ndarray.device`. stream : {SyclQueue, None}, optional Execution queue to synchronize with. If ``None``, synchronization is not performed. diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index d483384e0273..c81ba27fde4e 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -37,6 +37,7 @@ """ # pylint: disable=protected-access +# pylint: disable=redefined-outer-name import os @@ -57,7 +58,6 @@ __all__ = [ "are_same_logical_tensors", "asnumpy", - "astype", "as_usm_ndarray", "check_limitations", "check_supported_arrays_type", @@ -74,7 +74,6 @@ "synchronize_array_data", ] -from dpnp import float64 from dpnp.dpnp_iface_arraycreation import * from dpnp.dpnp_iface_arraycreation import __all__ as __all__arraycreation from dpnp.dpnp_iface_bitwise import * @@ -182,11 +181,13 @@ def asnumpy(a, order="C"): ---------- a : {array_like} Arbitrary object that can be converted to :obj:`numpy.ndarray`. - order : {'C', 'F', 'A', 'K'} + order : {None, 'C', 'F', 'A', 'K'}, optional The desired memory layout of the converted array. - 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. + 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. + + Default: ``'C'``. Returns ------- @@ -208,71 +209,6 @@ def asnumpy(a, order="C"): return numpy.asarray(a, order=order) -# pylint: disable=redefined-outer-name -def astype(x1, dtype, order="K", casting="unsafe", copy=True, device=None): - """ - Copy the array with data type casting. - - Parameters - ---------- - x1 : {dpnp.ndarray, usm_ndarray} - Array data type casting. - dtype : {None, str, dtype object} - 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. - casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional - Controls what kind of data casting may occur. Defaults to ``unsafe`` - for backwards compatibility. - - - 'no' means the data types should not be cast at all. - - 'equiv' means only byte-order changes are allowed. - - 'safe' means only casts which can preserve values are allowed. - - 'same_kind' means only safe casts or casts within a kind, like - float64 to float32, are allowed. - - 'unsafe' means any data conversions may be done. - - copy : {bool}, optional - By default, ``astype`` always returns a newly allocated array. If this - is set to ``False``, and the `dtype`, `order`, and `subok` requirements - are satisfied, the input array is returned instead of a copy. - device : {None, string, SyclDevice, SyclQueue}, optional - An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. Default: ``None``. - - Returns - ------- - arr_t : dpnp.ndarray - Unless `copy` is ``False`` and the other conditions for returning - the input array are satisfied, `arr_t` is a new array of the same shape - as the input array, with dtype, order given by dtype, order. - - """ - - if order is None: - order = "K" - - x1_obj = dpnp.get_usm_ndarray(x1) - array_obj = dpt.astype( - x1_obj, dtype, order=order, casting=casting, copy=copy, device=device - ) - - if array_obj is x1_obj and isinstance(x1, dpnp_array): - # return x1 if dpctl returns a zero copy of x1_obj - return x1 - return dpnp_array._create_from_usm_ndarray(array_obj) - - def as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None): """ Return :class:`dpctl.tensor.usm_ndarray` from input object `a`. @@ -285,22 +221,27 @@ def as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None): The desired dtype for the result array if new array is creating. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary). + Default: ``None``. - device : {None, string, SyclDevice, SyclQueue}, optional - An array API concept of device where the result array is created if - required. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + device : {None, string, SyclDevice, SyclQueue, Device}, optional + An array API concept of device where the output array is created. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + If the value is ``None``, returned array is created on the same device + as `a`. + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the result array if new array is created. + Default: ``None``. sycl_queue : {None, SyclQueue}, optional A SYCL queue to use for result array allocation if required. + Default: ``None``. Returns @@ -391,11 +332,15 @@ def check_supported_arrays_type(*arrays, scalar_type=False, all_scalars=False): ---------- arrays : {dpnp.ndarray, usm_ndarray} Input arrays to check for supported types. - scalar_type : {bool}, optional + scalar_type : bool, optional A scalar type is also considered as supported if flag is ``True``. - all_scalars : {bool}, optional + + Default: ``False``. + all_scalars : bool, optional All the input arrays can be scalar if flag is ``True``. + Default: ``False``. + Returns ------- out : bool @@ -437,20 +382,24 @@ def default_float_type(device=None, sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional - An array API concept of device where an array of default floating type - might be created. The `device` can be ``None`` (the default), an OneAPI - filter selector string, an instance of :class:`dpctl.SyclDevice` - corresponding to a non-partitioned SYCL device, an instance of - :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + device : {None, string, SyclDevice, SyclQueue, Device}, optional + An array API concept of device where the output array is created. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. The value ``None`` is interpreted as to use a default device. + + Default: ``None``. sycl_queue : {None, SyclQueue}, optional A SYCL queue which might be used to create an array of default floating type. The `sycl_queue` can be ``None`` (the default), which is interpreted as to get the SYCL queue from `device` keyword if present or to use a default queue. + Default: ``None``. + Returns ------- dt : dtype @@ -461,7 +410,7 @@ def default_float_type(device=None, sycl_queue=None): _sycl_queue = get_normalized_queue_device( device=device, sycl_queue=sycl_queue ) - return map_dtype_to_device(float64, _sycl_queue.sycl_device) + return map_dtype_to_device(dpnp.float64, _sycl_queue.sycl_device) def get_dpnp_descriptor( @@ -569,16 +518,24 @@ def get_normalized_queue_device(obj=None, device=None, sycl_queue=None): and implementing `__sycl_usm_array_interface__` protocol, an instance of `numpy.ndarray`, an object supporting Python buffer protocol, a Python scalar, or a (possibly nested) sequence of Python scalars. - sycl_queue : class:`dpctl.SyclQueue`, optional + sycl_queue : {None, class:`dpctl.SyclQueue`}, optional A queue which explicitly indicates where USM allocation is done and the population code (if any) is executed. Value ``None`` is interpreted as to get the SYCL queue from either `obj` parameter if not ``None`` or from `device` keyword, or to use default queue. - device : {string, :class:`dpctl.SyclDevice`, :class:`dpctl.SyclQueue, - :class:`dpctl.tensor.Device`}, optional - An array-API keyword indicating non-partitioned SYCL device - where array is allocated. + + Default: ``None``. + device : {None, string, SyclDevice, SyclQueue, Device}, optional + An array API concept of device where the output array is created. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + The value ``None`` is interpreted as to use the same device as `obj`. + + Default: ``None``. Returns ------- @@ -616,9 +573,13 @@ def get_result_array(a, out=None, casting="safe"): If provided, value of `a` array will be copied into it according to ``safe`` casting rule. It should be of the appropriate shape. + + Default: ``None``. casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional Controls what kind of data casting may occur. + Default: ``'safe'``. + Returns ------- out : {dpnp_array} @@ -714,6 +675,7 @@ def is_cuda_backend(obj=None): An input object with sycl_device property to check device backend. If `obj` is ``None``, device backend will be checked for the default queue. + Default: ``None``. Returns diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 2b5fa4e5d0c8..6c39dd8a8d45 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -64,6 +64,7 @@ "asarray", "ascontiguousarray", "asfortranarray", + "astype", "copy", "diag", "diagflat", @@ -207,13 +208,15 @@ def arange( The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary). - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -325,13 +328,14 @@ def array( should have. Ones will be prepended to the shape as needed to meet this requirement. Default: ``0``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -469,13 +473,15 @@ def asanyarray( order : {None, "C", "F", "A", "K"}, optional Memory layout of the newly output array. Default: ``"K"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -573,13 +579,14 @@ def asarray( order : {None, "C", "F", "A", "K"}, optional Memory layout of the newly output array. Default: ``"K"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -674,13 +681,15 @@ def ascontiguousarray( The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary). - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -786,13 +795,15 @@ def asfortranarray( The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary). - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -884,6 +895,95 @@ def asfortranarray( ) +def astype(x, dtype, /, *, order="K", casting="unsafe", copy=True, device=None): + """ + Copy the array with data type casting. + + Parameters + ---------- + x : {dpnp.ndarray, usm_ndarray} + Array data type casting. + dtype : {None, str, dtype object} + Target data type. + order : {None, "C", "F", "A", "K"}, optional + 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. + + Default: ``"K"``. + casting : {"no", "equiv", "safe", "same_kind", "unsafe"}, optional + Controls what kind of data casting may occur. Defaults to ``"unsafe"`` + for backwards compatibility. + + - "no" means the data types should not be cast at all. + - "equiv" means only byte-order changes are allowed. + - "safe" means only casts which can preserve values are allowed. + - "same_kind" means only safe casts or casts within a kind, like + float64 to float32, are allowed. + - "unsafe" means any data conversions may be done. + + Default: ``"unsafe"``. + copy : bool, optional + Specifies whether to copy an array when the specified dtype matches the + data type of the input array ``x``. If ``True``, a newly allocated + array must always be returned. If ``False`` and the specified dtype + matches the data type of the input array, the input array must be + returned; otherwise, a newly allocated array must be returned. + + Default: ``True``. + device : {None, string, SyclDevice, SyclQueue, Device}, optional + An array API concept of device where the output array is created. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + If the value is ``None``, returned array is created on the same device + as `x`. + + Default: ``None``. + + Returns + ------- + out : dpnp.ndarray + An array having the specified data type. + + See Also + -------- + :obj:`dpnp.ndarray.astype` : Equivalent method. + + Examples + -------- + >>> import dpnp as np + >>> x = np.array([1, 2, 3]); x + array([1, 2, 3]) + >>> np.astype(x, np.float32) + array([1., 2., 3.], dtype=float32) + + Non-copy case: + + >>> x = np.array([1, 2, 3]) + >>> result = np.astype(x, x.dtype, copy=False) + >>> result is x + True + + """ + + if order is None: + order = "K" + + usm_x = dpnp.get_usm_ndarray(x) + usm_res = dpt.astype( + usm_x, dtype, order=order, casting=casting, copy=copy, device=device + ) + + if usm_res is usm_x and isinstance(x, dpnp_array): + # return x if dpctl returns a zero copy of usm_x + return x + return dpnp_array._create_from_usm_ndarray(usm_res) + + def copy( a, order="K", subok=False, device=None, usm_type=None, sycl_queue=None ): @@ -901,13 +1001,15 @@ def copy( order : {"C", "F", "A", "K"}, optional Memory layout of the newly output array. Default: ``"K"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -1019,13 +1121,15 @@ def diag(v, /, k=0, *, device=None, usm_type=None, sycl_queue=None): Diagonal in question. Use k > 0 for diagonals above the main diagonal, and k < 0 for diagonals below the main diagonal. Default: ``0``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -1122,13 +1226,15 @@ def diagflat(v, /, k=0, *, device=None, usm_type=None, sycl_queue=None): Diagonal to set; 0, the default, corresponds to the "main" diagonal, a positive (negative) k giving the number of the diagonal above (below) the main. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -1226,13 +1332,15 @@ def empty( order : {None, "C", "F"}, optional Memory layout of the newly output array. Default: ``"C"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -1330,13 +1438,15 @@ def empty_like( Default: ``"K"``. shape : {None, int, sequence of ints} Overrides the shape of the result. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -1440,13 +1550,15 @@ def eye( order : {None, "C", "F"}, optional Memory layout of the newly output array. Default: ``"C"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -1550,13 +1662,15 @@ def frombuffer( offset : int, optional Start reading the buffer from this offset (in bytes). Default: ``0``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -1664,13 +1778,15 @@ def fromfile( offset : int, optional The offset (in bytes) from the file's current position. Defaults to 0. Only permitted for binary files. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -1783,13 +1899,15 @@ def fromfunction( Data-type of the coordinate arrays passed to `function`. Default is the default floating point data type for the device where the returned array is allocated. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -1892,13 +2010,15 @@ def fromiter( count : int, optional The number of items to read from *iterable*. The default is -1, which means all data is read. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -1992,13 +2112,15 @@ def fromstring( sep : str, optional The string separating numbers in the data; extra whitespace between elements is also ignored. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -2166,13 +2288,15 @@ def full( order : {None, "C", "F"}, optional Memory layout of the newly output array. Default: ``"C"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -2273,13 +2397,15 @@ def full_like( Default: ``"K"``. shape : {None, int, sequence of ints} Overrides the shape of the result. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -2386,13 +2512,15 @@ def geomspace( The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary). - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -2496,13 +2624,15 @@ def identity( The desired dtype for the array, e.g., dpnp.int32. Default is the default floating point data type for the device where input array is allocated. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -2611,13 +2741,15 @@ def linspace( The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary). - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -2721,13 +2853,15 @@ def loadtxt( Default is the default floating point data type for the device where the returned array is allocated. A structured data-type is not supported. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -2834,13 +2968,15 @@ def logspace( num : int, optional Number of samples to generate. Default: ``50``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -3038,13 +3174,15 @@ class MGridClass: Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -3115,13 +3253,15 @@ class OGridClass: Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -3203,13 +3343,15 @@ def ones( order : {None, "C", "F"}, optional Memory layout of the newly output array. Default: ``"C"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -3313,13 +3455,15 @@ def ones_like( Default: ``"K"``. shape : {None, int, sequence of ints} Overrides the shape of the result. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -3484,13 +3628,15 @@ def tri( The desired dtype for the array, e.g., dpnp.int32. Default is the default floating point data type for the device where input array is allocated. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -3720,13 +3866,15 @@ def vander( increasing : bool, optional Order of the powers of the columns. If ``True,`` the powers increase from left to right, if ``False`` (the default) they are reversed. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -3848,13 +3996,15 @@ def zeros( order : {None, "C", "F"}, optional Memory layout of the newly output array. Default: ``"C"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. @@ -3958,13 +4108,15 @@ def zeros_like( Default: ``"K"``. shape : {None, int, sequence of ints} Overrides the shape of the result. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. diff --git a/dpnp/dpnp_iface_indexing.py b/dpnp/dpnp_iface_indexing.py index 9ace42adea6a..630f2d7a52e5 100644 --- a/dpnp/dpnp_iface_indexing.py +++ b/dpnp/dpnp_iface_indexing.py @@ -467,15 +467,16 @@ def diag_indices(n, ndim=2, device=None, usm_type="device", sycl_queue=None): The number of dimensions. Default: ``2``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. Default: ``None``. + usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1074,15 +1075,16 @@ def indices( representation. Default is ``False``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. Default: ``None``. + usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1338,15 +1340,16 @@ def mask_indices( interpreted as an offset. Default: ``0``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. Default: ``None``. + usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -2348,15 +2351,16 @@ def tril_indices( By default `m` is taken equal to `n`. Default: ``None``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. Default: ``None``. + usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -2557,15 +2561,16 @@ def triu_indices( By default `m` is taken equal to `n`. Default: ``None``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. - Default: ``"device"``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. diff --git a/dpnp/dpnp_iface_logic.py b/dpnp/dpnp_iface_logic.py index cd9de16581b4..001d0f415317 100644 --- a/dpnp/dpnp_iface_logic.py +++ b/dpnp/dpnp_iface_logic.py @@ -844,7 +844,7 @@ def isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False): ) elif dpnp.issubdtype(b, dpnp.integer): dt = dpnp.result_type(b, 1.0, rtol, atol) - b = dpnp.astype(b, dtype=dt) + b = dpnp.astype(b, dt) # Firstly handle finite values: # result = absolute(a - b) <= atol + rtol * absolute(b) diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 5b6c9445ea3a..b5ca0942ac4c 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -743,15 +743,16 @@ def asarray_chkfinite( Memory layout of the newly output array. Default: ``"K"``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. Default: ``None``. + usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -859,12 +860,13 @@ def asfarray(a, dtype=None, *, device=None, usm_type=None, sycl_queue=None): or :obj:`dpnp.float32` type otherwise). Default: ``None``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by :obj:`dpnp.ndarray.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional diff --git a/dpnp/dpnp_iface_statistics.py b/dpnp/dpnp_iface_statistics.py index ac2a80b1d29d..78e4b03fd009 100644 --- a/dpnp/dpnp_iface_statistics.py +++ b/dpnp/dpnp_iface_statistics.py @@ -900,14 +900,14 @@ def cov( if fweights.ndim > 1: raise ValueError("cannot handle multidimensional fweights") - fweights = dpnp.astype(fweights, dtype=def_float) + fweights = dpnp.astype(fweights, def_float) if aweights is not None: dpnp.check_supported_arrays_type(aweights) if aweights.ndim > 1: raise ValueError("cannot handle multidimensional aweights") - aweights = dpnp.astype(aweights, dtype=def_float) + aweights = dpnp.astype(aweights, def_float) return dpnp_cov( m, diff --git a/dpnp/dpnp_iface_trigonometric.py b/dpnp/dpnp_iface_trigonometric.py index 3c9789e0b27e..1aea90ab6a59 100644 --- a/dpnp/dpnp_iface_trigonometric.py +++ b/dpnp/dpnp_iface_trigonometric.py @@ -2448,7 +2448,7 @@ def unwrap(p, discont=None, axis=-1, *, period=2 * dpnp.pi): abs_p_diff = dpnp.abs(p_diff, out=p_diff) ph_correct = dpnp.where(abs_p_diff < discont, 0, ph_correct, out=ph_correct) - up = dpnp.astype(p, dtype=dt, copy=True) + up = dpnp.astype(p, dt, copy=True) up[slice1] = p[slice1] up[slice1] += ph_correct.cumsum(axis=axis) return up diff --git a/dpnp/dpnp_utils/dpnp_utils_reduction.py b/dpnp/dpnp_utils/dpnp_utils_reduction.py index 588d42445db9..6ce2a90c0603 100644 --- a/dpnp/dpnp_utils/dpnp_utils_reduction.py +++ b/dpnp/dpnp_utils/dpnp_utils_reduction.py @@ -40,7 +40,7 @@ def dpnp_wrap_reduction_call(usm_a, out, _reduction_fn, res_dt, **kwargs): # dpctl requires strict data type matching of out array with the result if out.dtype != res_dt: - out = dpnp.astype(out, dtype=res_dt, copy=False) + out = dpnp.astype(out, res_dt, copy=False) usm_out = dpnp.get_usm_ndarray(out) diff --git a/dpnp/fft/dpnp_iface_fft.py b/dpnp/fft/dpnp_iface_fft.py index 7ce75fd6b918..bc9aa3ac9df3 100644 --- a/dpnp/fft/dpnp_iface_fft.py +++ b/dpnp/fft/dpnp_iface_fft.py @@ -279,13 +279,14 @@ def fftfreq(n, d=1.0, device=None, usm_type=None, sycl_queue=None): d : scalar, optional Sample spacing (inverse of the sampling rate). Default: ``1.0``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1542,13 +1543,14 @@ def rfftfreq(n, d=1.0, device=None, usm_type=None, sycl_queue=None): d : scalar, optional Sample spacing (inverse of the sampling rate). Default: ``1.0``. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. diff --git a/dpnp/linalg/dpnp_utils_linalg.py b/dpnp/linalg/dpnp_utils_linalg.py index 1a2ac0c99f57..c5fafa7f342f 100644 --- a/dpnp/linalg/dpnp_utils_linalg.py +++ b/dpnp/linalg/dpnp_utils_linalg.py @@ -1296,9 +1296,15 @@ def _real_type(dtype, device=None): ---------- dtype : dpnp.dtype The dtype for which to find the corresponding real data type. - device : {None, string, SyclDevice, SyclQueue}, optional - An array API concept of device where an array of default floating type - might be created. + device : {None, string, SyclDevice, SyclQueue, Device}, optional + An array API concept of device where an array of default floating data + type is created. `device` can be ``None``, a oneAPI filter selector + string, an instance of :class:`dpctl.SyclDevice` corresponding to + a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, + or a :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. Returns ------- @@ -2359,7 +2365,7 @@ def dpnp_norm(x, ord=None, axis=None, keepdims=False): """Compute matrix or vector norm.""" if not dpnp.issubdtype(x.dtype, dpnp.inexact): - x = dpnp.astype(x, dtype=dpnp.default_float_type(x.device)) + x = dpnp.astype(x, dpnp.default_float_type(x.device)) ndim = x.ndim # Immediately handle some default, simple, fast, and common cases. diff --git a/dpnp/random/dpnp_iface_random.py b/dpnp/random/dpnp_iface_random.py index d20b4f64c2a6..f21e1733cd95 100644 --- a/dpnp/random/dpnp_iface_random.py +++ b/dpnp/random/dpnp_iface_random.py @@ -875,12 +875,15 @@ def normal( Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1133,13 +1136,14 @@ def rand(*args, device=None, usm_type="device", sycl_queue=None): *args : sequence of ints, optional The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1193,12 +1197,15 @@ def randint( Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1251,12 +1258,15 @@ def randn(d0, *dn, device=None, usm_type="device", sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1303,12 +1313,15 @@ def random(size=None, device=None, usm_type="device", sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1351,12 +1364,15 @@ def random_integers( Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1416,12 +1432,15 @@ def random_sample(size=None, device=None, usm_type="device", sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1463,12 +1482,15 @@ def ranf(size=None, device=None, usm_type="device", sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1551,12 +1573,15 @@ def sample(size=None, device=None, usm_type="device", sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1627,13 +1652,15 @@ def seed(seed=None, device=None, sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional - An array API concept of device where an array with generated numbers - will be created. The `device` can be ``None`` (the default), an OneAPI - filter selector string, an instance of :class:`dpctl.SyclDevice` - corresponding to a non-partitioned SYCL device, an instance of - :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + device : {None, string, SyclDevice, SyclQueue, Device}, optional + An array API concept of device where the output array is created. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. sycl_queue : {None, SyclQueue}, optional A SYCL queue to use for an array with generated numbers. @@ -1786,12 +1813,15 @@ def standard_normal(size=None, device=None, usm_type="device", sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional @@ -1928,12 +1958,15 @@ def uniform( Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector string, - an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device, - an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. sycl_queue : {None, SyclQueue}, optional diff --git a/dpnp/random/dpnp_random_state.py b/dpnp/random/dpnp_random_state.py index 774095d518ed..84f27f3ca396 100644 --- a/dpnp/random/dpnp_random_state.py +++ b/dpnp/random/dpnp_random_state.py @@ -61,13 +61,15 @@ class RandomState: A random seed to initialize the pseudo-random number generator. The `seed` can be ``None`` (the default), an integer scalar, or an array of at most three integer scalars. - device : {None, string, SyclDevice, SyclQueue}, optional + device : {None, string, SyclDevice, SyclQueue, Device}, optional An array API concept of device where the output array is created. - The `device` can be ``None`` (the default), an OneAPI filter selector - string, an instance of :class:`dpctl.SyclDevice` corresponding to - a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`, - or a `Device` object returned by - :obj:`dpnp.dpnp_array.dpnp_array.device` property. + `device` can be ``None``, a oneAPI filter selector string, an instance + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL + device, an instance of :class:`dpctl.SyclQueue`, or a + :class:`dpctl.tensor.Device` object returned by + :attr:`dpnp.ndarray.device`. + + Default: ``None``. sycl_queue : {None, SyclQueue}, optional A SYCL queue to use for output array allocation and copying. The `sycl_queue` can be passed as ``None`` (the default), which means diff --git a/dpnp/tests/test_arraycreation.py b/dpnp/tests/test_arraycreation.py index bf6d31b120e5..f82bd606adb0 100644 --- a/dpnp/tests/test_arraycreation.py +++ b/dpnp/tests/test_arraycreation.py @@ -10,6 +10,7 @@ assert_array_equal, assert_equal, assert_raises, + assert_raises_regex, ) import dpnp @@ -57,6 +58,28 @@ def test_error(self): assert_raises(TypeError, dpnp.array, x, ndmin=3.0) +class TestAsType: + @testing.with_requires("numpy>=2.0") + @pytest.mark.parametrize("xp", [dpnp, numpy]) + def test_validate_positional_args(self, xp): + x = xp.ones(4) + assert_raises_regex( + TypeError, + "got some positional-only arguments passed as keyword arguments", + xp.astype, + x, + dtype="f4", + ) + assert_raises_regex( + TypeError, + "takes 2 positional arguments but 3 were given", + xp.astype, + x, + "f4", + None, + ) + + class TestTrace: @pytest.mark.parametrize("a_sh", [(3, 4), (2, 2, 2)]) @pytest.mark.parametrize( diff --git a/dpnp/tests/test_ndarray.py b/dpnp/tests/test_ndarray.py index e834f56749f9..1ae605ef5b7d 100644 --- a/dpnp/tests/test_ndarray.py +++ b/dpnp/tests/test_ndarray.py @@ -20,26 +20,27 @@ from .third_party.cupy import testing -@pytest.mark.usefixtures("suppress_complex_warning") -@pytest.mark.parametrize("res_dtype", get_all_dtypes()) -@pytest.mark.parametrize("arr_dtype", get_all_dtypes()) -@pytest.mark.parametrize( - "arr", - [[-2, -1, 0, 1, 2], [[-2, -1], [1, 2]], []], - ids=["[-2, -1, 0, 1, 2]", "[[-2, -1], [1, 2]]", "[]"], -) -def test_astype(arr, arr_dtype, res_dtype): - numpy_array = get_abs_array(arr, arr_dtype) - dpnp_array = dpnp.array(numpy_array) - expected = numpy_array.astype(res_dtype) - result = dpnp_array.astype(res_dtype) - assert_allclose(expected, result) +class TestAsType: + @pytest.mark.usefixtures("suppress_complex_warning") + @pytest.mark.parametrize("res_dtype", get_all_dtypes()) + @pytest.mark.parametrize("arr_dtype", get_all_dtypes()) + @pytest.mark.parametrize( + "arr", + [[-2, -1, 0, 1, 2], [[-2, -1], [1, 2]], []], + ids=["1d", "2d", "empty"], + ) + def test_basic(self, arr, arr_dtype, res_dtype): + a = get_abs_array(arr, arr_dtype) + ia = dpnp.array(a) + expected = a.astype(res_dtype) + result = ia.astype(res_dtype) + assert_allclose(expected, result) -def test_astype_subok_error(): - x = dpnp.ones((4)) - with pytest.raises(NotImplementedError): - x.astype("i4", subok=False) + def test_subok_error(self): + x = dpnp.ones(4) + with pytest.raises(NotImplementedError): + x.astype("i4", subok=False) class TestAttributes: diff --git a/dpnp/tests/test_sycl_queue.py b/dpnp/tests/test_sycl_queue.py index acbb61bbd522..c2eb62a52ff7 100644 --- a/dpnp/tests/test_sycl_queue.py +++ b/dpnp/tests/test_sycl_queue.py @@ -2015,11 +2015,11 @@ def test_histogram_bin_edges(wgt, device): ) def test_astype(device_x, device_y): x = dpnp.array([1, 2, 3], dtype="i4", device=device_x) - y = dpnp.astype(x, dtype="f4") + y = dpnp.astype(x, "f4") assert_sycl_queue_equal(y.sycl_queue, x.sycl_queue) sycl_queue = dpctl.SyclQueue(device_y) - y = dpnp.astype(x, dtype="f4", device=sycl_queue) + y = dpnp.astype(x, "f4", device=sycl_queue) assert_sycl_queue_equal(y.sycl_queue, sycl_queue)