From 3d9db1cf46ed950e32e8b97de859ac782770c6ef Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 12:12:44 +0100 Subject: [PATCH 01/14] Make keyword-only parameters and align names --- dpnp/dpnp_iface.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index d483384e0273..ad09b8485b3d 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -209,13 +209,13 @@ def asnumpy(a, order="C"): # pylint: disable=redefined-outer-name -def astype(x1, dtype, order="K", casting="unsafe", copy=True, device=None): +def astype(x, dtype, /, *, order="K", casting="unsafe", copy=True, device=None): """ Copy the array with data type casting. Parameters ---------- - x1 : {dpnp.ndarray, usm_ndarray} + x : {dpnp.ndarray, usm_ndarray} Array data type casting. dtype : {None, str, dtype object} Target data type. @@ -262,15 +262,15 @@ def astype(x1, dtype, order="K", casting="unsafe", copy=True, device=None): 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 + usm_x = dpnp.get_usm_ndarray(x) + usm_res = dpt.astype( + usm_x, 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) + 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 as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None): From 91b60966579e7dfb61cfd5f0997d3c3bd85ac566 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 12:25:59 +0100 Subject: [PATCH 02/14] Update docstrings --- dpnp/dpnp_iface.py | 66 ++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index ad09b8485b3d..232dd5e5f9d2 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -219,16 +219,15 @@ def astype(x, dtype, /, *, order="K", casting="unsafe", copy=True, device=None): Array data type casting. dtype : {None, str, dtype object} Target data type. - order : {'C', 'F', 'A', 'K'} + 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. + 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`` + 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. @@ -238,24 +237,47 @@ def astype(x, dtype, /, *, order="K", casting="unsafe", copy=True, device=None): 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. + 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}, 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``. + An array API specification of device where the output array is created. + Device can be specified by a filter selector string, an instance of + :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or + an instance of :class:`dpctl.tensor.Device`. If the value is ``None``, + returned array is created on the same device as `x`. + + 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. + + 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 """ From ed38d67a5e447c038ca46764169fb5a14c688cf8 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 12:28:26 +0100 Subject: [PATCH 03/14] Remove excess import --- dpnp/dpnp_iface.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index 232dd5e5f9d2..8cb1e51f5a36 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -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 * @@ -483,7 +482,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( From 44db6af5a97a436369029777c34b733112b3a51f Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 12:36:50 +0100 Subject: [PATCH 04/14] Update docstrings of other interface functions --- dpnp/dpnp_iface.py | 71 ++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index 8cb1e51f5a36..d48f647099c1 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -181,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 ------- @@ -306,22 +308,24 @@ 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. + An array API specification of device where the output array is created. + Device can be specified by a filter selector string, an instance of + :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or + an instance of :class:`dpctl.tensor.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 @@ -412,11 +416,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 @@ -459,19 +467,21 @@ 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. - The value ``None`` is interpreted as to use a default device. + An array API specification of device where the output array is created. + Device can be specified by a filter selector string, an instance of + :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or + an instance of :class:`dpctl.tensor.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 @@ -590,16 +600,22 @@ 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}, optional + An array API specification of device where the output array is created. + Device can be specified by a filter selector string, an instance of + :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or + an instance of :class:`dpctl.tensor.Device`. The value ``None`` is + interpreted as to use the same device as `obj`. + + Default: ``None``. Returns ------- @@ -637,9 +653,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} @@ -735,6 +755,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 From 757ed5933cd5988997ba9d19fb4ae4011bdf730c Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 13:03:10 +0100 Subject: [PATCH 05/14] Align docstring of device keyword accross all the functions --- dpnp/dpnp_array.py | 40 +-- dpnp/dpnp_iface.py | 58 ++-- dpnp/dpnp_iface_arraycreation.py | 448 ++++++++++++++++++------------- dpnp/dpnp_iface_indexing.py | 70 ++--- dpnp/dpnp_iface_manipulation.py | 25 +- dpnp/fft/dpnp_iface_fft.py | 28 +- dpnp/linalg/dpnp_utils_linalg.py | 14 +- dpnp/random/dpnp_iface_random.py | 160 ++++++----- dpnp/random/dpnp_random_state.py | 14 +- 9 files changed, 498 insertions(+), 359 deletions(-) diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 44f67ea77eab..c804e265cba6 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -816,13 +816,17 @@ def astype( 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 + 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 ------- @@ -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 d48f647099c1..04563f3a1fc0 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -247,12 +247,15 @@ def astype(x, dtype, /, *, order="K", casting="unsafe", copy=True, device=None): returned; otherwise, a newly allocated array must be returned. Default: ``True``. - device : {None, string, SyclDevice, SyclQueue}, optional - An array API specification of device where the output array is created. - Device can be specified by a filter selector string, an instance of - :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or - an instance of :class:`dpctl.tensor.Device`. If the value is ``None``, - returned array is created on the same device as `x`. + 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``. @@ -310,12 +313,15 @@ def as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None): considering Promotion Type Rule and device capabilities when necessary). Default: ``None``. - device : {None, string, SyclDevice, SyclQueue}, optional - An array API specification of device where the output array is created. - Device can be specified by a filter selector string, an instance of - :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or - an instance of :class:`dpctl.tensor.Device`. If the value is ``None``, - returned array is created on the same device as `a`. + 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 @@ -466,12 +472,14 @@ def default_float_type(device=None, sycl_queue=None): Parameters ---------- - device : {None, string, SyclDevice, SyclQueue}, optional - An array API specification of device where the output array is created. - Device can be specified by a filter selector string, an instance of - :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or - an instance of :class:`dpctl.tensor.Device`. The value ``None`` is - interpreted as to use a default device. + 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 @@ -608,12 +616,14 @@ def get_normalized_queue_device(obj=None, device=None, sycl_queue=None): or to use default queue. Default: ``None``. - device : {None, string, SyclDevice, SyclQueue}, optional - An array API specification of device where the output array is created. - Device can be specified by a filter selector string, an instance of - :class:`dpctl.SyclDevice`, an instance of :class:`dpctl.SyclQueue`, or - an instance of :class:`dpctl.tensor.Device`. The value ``None`` is - interpreted as to use the same device as `obj`. + 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``. diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 2b5fa4e5d0c8..1fd8c135aeda 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -207,13 +207,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 +327,15 @@ 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``. 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,15 @@ 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``. Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -674,13 +682,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 +796,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``. @@ -901,13 +913,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 +1033,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 +1138,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 +1244,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 +1350,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 +1462,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 +1574,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 +1690,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 +1811,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 +1922,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 +2024,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 +2200,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 +2309,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 +2424,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 +2536,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 +2653,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 +2765,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 +2880,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 +3086,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 +3165,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 +3255,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 +3367,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 +3540,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 +3778,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 +3908,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 +4020,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..4e91f7f8290d 100644 --- a/dpnp/dpnp_iface_indexing.py +++ b/dpnp/dpnp_iface_indexing.py @@ -467,13 +467,15 @@ 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``. Default: ``None``. usm_type : {"device", "shared", "host"}, optional @@ -1074,13 +1076,15 @@ 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``. Default: ``None``. usm_type : {"device", "shared", "host"}, optional @@ -1338,13 +1342,15 @@ 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``. Default: ``None``. usm_type : {"device", "shared", "host"}, optional @@ -2348,13 +2354,15 @@ 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``. Default: ``None``. usm_type : {"device", "shared", "host"}, optional @@ -2557,13 +2565,15 @@ 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 diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index 8234bb7916ab..35bc1d8263de 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -721,13 +721,15 @@ 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``. Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional @@ -837,12 +839,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/fft/dpnp_iface_fft.py b/dpnp/fft/dpnp_iface_fft.py index 7ce75fd6b918..ce3f743ba23d 100644 --- a/dpnp/fft/dpnp_iface_fft.py +++ b/dpnp/fft/dpnp_iface_fft.py @@ -279,13 +279,15 @@ 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``. Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1542,13 +1544,15 @@ 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``. 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 f105cff5a6c2..a43aed376abb 100644 --- a/dpnp/linalg/dpnp_utils_linalg.py +++ b/dpnp/linalg/dpnp_utils_linalg.py @@ -1294,9 +1294,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 ------- @@ -2357,7 +2363,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..38ffaf1d919a 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,15 @@ 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``. Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1193,12 +1198,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 +1259,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 +1314,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 +1365,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 +1433,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 +1483,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 +1574,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 +1653,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 +1814,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 +1959,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 From 63089a4cbdf43f271ee0181dce97f4da5da11829 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 13:06:45 +0100 Subject: [PATCH 06/14] dtype keyword is positional one in astype --- dpnp/dpnp_iface_logic.py | 2 +- dpnp/dpnp_iface_statistics.py | 4 ++-- dpnp/dpnp_iface_trigonometric.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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_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 From 7fff293a972eac8377deecba440a2a8feb4e97f6 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 13:18:01 +0100 Subject: [PATCH 07/14] Aligh docstring of astype method and function --- dpnp/dpnp_array.py | 60 +++++++++++++++++++++++----------------------- dpnp/dpnp_iface.py | 24 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index c804e265cba6..7dad92d81611 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -789,33 +789,35 @@ 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. + 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. `device` can be ``None``, a oneAPI filter selector string, @@ -830,10 +832,8 @@ def astype( 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 ----------- @@ -843,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]) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index 04563f3a1fc0..75ef07680545 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -220,25 +220,25 @@ def astype(x, dtype, /, *, order="K", casting="unsafe", copy=True, device=None): Array data type casting. dtype : {None, str, dtype object} Target data type. - order : {None, '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 + 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'`` + 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 + - "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. + - "unsafe" means any data conversions may be done. - Default: ``'unsafe'``. + 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 From 9921320eaedda1ac06d203b0e3661461852f5594 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 13:27:13 +0100 Subject: [PATCH 08/14] Update tests for aastype method --- dpnp/tests/test_ndarray.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/dpnp/tests/test_ndarray.py b/dpnp/tests/test_ndarray.py index e834f56749f9..4d110d3d6a45 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: From 89668ff4b12da11c06bb021282baa63f40c74f86 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 13:29:09 +0100 Subject: [PATCH 09/14] Move astype function to arraycreation namespace --- dpnp/dpnp_iface.py | 92 +------------------------------- dpnp/dpnp_iface_arraycreation.py | 90 +++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 91 deletions(-) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index 75ef07680545..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", @@ -209,96 +209,6 @@ def asnumpy(a, order="C"): return numpy.asarray(a, order=order) -# pylint: disable=redefined-outer-name -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 as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None): """ Return :class:`dpctl.tensor.usm_ndarray` from input object `a`. diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 1fd8c135aeda..d17b69da7463 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -64,6 +64,7 @@ "asarray", "ascontiguousarray", "asfortranarray", + "astype", "copy", "diag", "diagflat", @@ -896,6 +897,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 ): From 1ee8e197e0cb4e37929cba84a0c07779c1388785 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 13:39:45 +0100 Subject: [PATCH 10/14] Add tests for positional-only keywords in astype --- dpnp/tests/test_arraycreation.py | 23 +++++++++++++++++++++++ dpnp/tests/test_ndarray.py | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) 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 4d110d3d6a45..1ae605ef5b7d 100644 --- a/dpnp/tests/test_ndarray.py +++ b/dpnp/tests/test_ndarray.py @@ -38,7 +38,7 @@ def test_basic(self, arr, arr_dtype, res_dtype): assert_allclose(expected, result) def test_subok_error(self): - x = dpnp.ones((4)) + x = dpnp.ones(4) with pytest.raises(NotImplementedError): x.astype("i4", subok=False) From 365abdded3f992c1bc338518b487cad54bd25a5c Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 14:33:27 +0100 Subject: [PATCH 11/14] Update reduction functions to pass dtype as positional argument to astype --- dpnp/dpnp_utils/dpnp_utils_reduction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From da42f24e8eb48e5b427302ccd201ee359e6d03f9 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Mon, 17 Feb 2025 15:11:44 +0100 Subject: [PATCH 12/14] Update dpnp/tests/test_sycl_queue.py::test_astype --- dpnp/tests/test_sycl_queue.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From ae0ed1bc62471b3aa500079502698e556cde5b60 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 19 Feb 2025 13:44:35 +0100 Subject: [PATCH 13/14] Remove duplicate Defaults in docstrings --- dpnp/dpnp_iface_arraycreation.py | 2 -- dpnp/fft/dpnp_iface_fft.py | 2 -- dpnp/random/dpnp_iface_random.py | 1 - 3 files changed, 5 deletions(-) diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index d17b69da7463..6c39dd8a8d45 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -337,7 +337,6 @@ def array( :attr:`dpnp.ndarray.device`. Default: ``None``. - Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -589,7 +588,6 @@ def asarray( :attr:`dpnp.ndarray.device`. Default: ``None``. - 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/fft/dpnp_iface_fft.py b/dpnp/fft/dpnp_iface_fft.py index ce3f743ba23d..bc9aa3ac9df3 100644 --- a/dpnp/fft/dpnp_iface_fft.py +++ b/dpnp/fft/dpnp_iface_fft.py @@ -288,7 +288,6 @@ def fftfreq(n, d=1.0, device=None, usm_type=None, sycl_queue=None): :attr:`dpnp.ndarray.device`. Default: ``None``. - Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``None``. @@ -1553,7 +1552,6 @@ def rfftfreq(n, d=1.0, device=None, usm_type=None, sycl_queue=None): :attr:`dpnp.ndarray.device`. Default: ``None``. - 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/random/dpnp_iface_random.py b/dpnp/random/dpnp_iface_random.py index 38ffaf1d919a..f21e1733cd95 100644 --- a/dpnp/random/dpnp_iface_random.py +++ b/dpnp/random/dpnp_iface_random.py @@ -1145,7 +1145,6 @@ def rand(*args, device=None, usm_type="device", sycl_queue=None): :attr:`dpnp.ndarray.device`. Default: ``None``. - Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. Default: ``"device"``. From b7e2fe1bc50dd6f8475b6e6cb315f6d717b5d520 Mon Sep 17 00:00:00 2001 From: Anton <100830759+antonwolfy@users.noreply.github.com> Date: Wed, 19 Feb 2025 17:53:44 +0100 Subject: [PATCH 14/14] Apply suggestions from code review Co-authored-by: Vahid Tavanashad <120411540+vtavana@users.noreply.github.com> --- dpnp/dpnp_iface_indexing.py | 5 ----- dpnp/dpnp_iface_manipulation.py | 1 - 2 files changed, 6 deletions(-) diff --git a/dpnp/dpnp_iface_indexing.py b/dpnp/dpnp_iface_indexing.py index 4e91f7f8290d..630f2d7a52e5 100644 --- a/dpnp/dpnp_iface_indexing.py +++ b/dpnp/dpnp_iface_indexing.py @@ -477,7 +477,6 @@ def diag_indices(n, ndim=2, device=None, usm_type="device", sycl_queue=None): Default: ``None``. - Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1086,7 +1085,6 @@ def indices( Default: ``None``. - Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -1352,7 +1350,6 @@ def mask_indices( Default: ``None``. - Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -2364,7 +2361,6 @@ def tril_indices( Default: ``None``. - Default: ``None``. usm_type : {"device", "shared", "host"}, optional The type of SYCL USM allocation for the output array. @@ -2575,7 +2571,6 @@ def triu_indices( 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_manipulation.py b/dpnp/dpnp_iface_manipulation.py index f91b15a842a2..b5ca0942ac4c 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -753,7 +753,6 @@ def asarray_chkfinite( Default: ``None``. - Default: ``None``. usm_type : {None, "device", "shared", "host"}, optional The type of SYCL USM allocation for the output array.