3737
3838"""
3939# pylint: disable=protected-access
40+ # pylint: disable=redefined-outer-name
4041
4142import os
4243
5758__all__ = [
5859 "are_same_logical_tensors" ,
5960 "asnumpy" ,
60- "astype" ,
6161 "as_usm_ndarray" ,
6262 "check_limitations" ,
6363 "check_supported_arrays_type" ,
7474 "synchronize_array_data" ,
7575]
7676
77- from dpnp import float64
7877from dpnp .dpnp_iface_arraycreation import *
7978from dpnp .dpnp_iface_arraycreation import __all__ as __all__arraycreation
8079from dpnp .dpnp_iface_bitwise import *
@@ -182,11 +181,13 @@ def asnumpy(a, order="C"):
182181 ----------
183182 a : {array_like}
184183 Arbitrary object that can be converted to :obj:`numpy.ndarray`.
185- order : {'C', 'F', 'A', 'K'}
184+ order : {None, 'C', 'F', 'A', 'K'}, optional
186185 The desired memory layout of the converted array.
187- When `order` is ``A``, it uses ``F`` if `a` is column-major and uses
188- ``C`` otherwise. And when `order` is ``K``, it keeps strides as closely
189- as possible.
186+ When `order` is ``'A'``, it uses ``'F'`` if `a` is column-major and
187+ uses ``'C'`` otherwise. And when `order` is ``'K'``, it keeps strides
188+ as closely as possible.
189+
190+ Default: ``'C'``.
190191
191192 Returns
192193 -------
@@ -208,71 +209,6 @@ def asnumpy(a, order="C"):
208209 return numpy .asarray (a , order = order )
209210
210211
211- # pylint: disable=redefined-outer-name
212- def astype (x1 , dtype , order = "K" , casting = "unsafe" , copy = True , device = None ):
213- """
214- Copy the array with data type casting.
215-
216- Parameters
217- ----------
218- x1 : {dpnp.ndarray, usm_ndarray}
219- Array data type casting.
220- dtype : {None, str, dtype object}
221- Target data type.
222- order : {'C', 'F', 'A', 'K'}
223- Row-major (C-style) or column-major (Fortran-style) order.
224- When `order` is ``A``, it uses ``F`` if `a` is column-major and uses
225- ``C`` otherwise. And when `order` is ``K``, it keeps strides as closely
226- as possible.
227- copy : bool
228- If it is ``False`` and no cast happens, then this method returns
229- the array itself. Otherwise, a copy is returned.
230- casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
231- Controls what kind of data casting may occur. Defaults to ``unsafe``
232- for backwards compatibility.
233-
234- - 'no' means the data types should not be cast at all.
235- - 'equiv' means only byte-order changes are allowed.
236- - 'safe' means only casts which can preserve values are allowed.
237- - 'same_kind' means only safe casts or casts within a kind, like
238- float64 to float32, are allowed.
239- - 'unsafe' means any data conversions may be done.
240-
241- copy : {bool}, optional
242- By default, ``astype`` always returns a newly allocated array. If this
243- is set to ``False``, and the `dtype`, `order`, and `subok` requirements
244- are satisfied, the input array is returned instead of a copy.
245- device : {None, string, SyclDevice, SyclQueue}, optional
246- An array API concept of device where the output array is created.
247- The `device` can be ``None`` (the default), an OneAPI filter selector
248- string, an instance of :class:`dpctl.SyclDevice` corresponding to
249- a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
250- or a `Device` object returned by
251- :obj:`dpnp.dpnp_array.dpnp_array.device` property. Default: ``None``.
252-
253- Returns
254- -------
255- arr_t : dpnp.ndarray
256- Unless `copy` is ``False`` and the other conditions for returning
257- the input array are satisfied, `arr_t` is a new array of the same shape
258- as the input array, with dtype, order given by dtype, order.
259-
260- """
261-
262- if order is None :
263- order = "K"
264-
265- x1_obj = dpnp .get_usm_ndarray (x1 )
266- array_obj = dpt .astype (
267- x1_obj , dtype , order = order , casting = casting , copy = copy , device = device
268- )
269-
270- if array_obj is x1_obj and isinstance (x1 , dpnp_array ):
271- # return x1 if dpctl returns a zero copy of x1_obj
272- return x1
273- return dpnp_array ._create_from_usm_ndarray (array_obj )
274-
275-
276212def as_usm_ndarray (a , dtype = None , device = None , usm_type = None , sycl_queue = None ):
277213 """
278214 Return :class:`dpctl.tensor.usm_ndarray` from input object `a`.
@@ -285,22 +221,27 @@ def as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None):
285221 The desired dtype for the result array if new array is creating. If not
286222 given, a default dtype will be used that can represent the values (by
287223 considering Promotion Type Rule and device capabilities when necessary).
224+
288225 Default: ``None``.
289- device : {None, string, SyclDevice, SyclQueue}, optional
290- An array API concept of device where the result array is created if
291- required.
292- The `device` can be ``None`` (the default), an OneAPI filter selector
293- string, an instance of :class:`dpctl.SyclDevice` corresponding to
294- a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
295- or a `Device` object returned by
296- :obj:`dpnp.dpnp_array.dpnp_array.device` property.
226+ device : {None, string, SyclDevice, SyclQueue, Device}, optional
227+ An array API concept of device where the output array is created.
228+ `device` can be ``None``, a oneAPI filter selector string, an instance
229+ of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL
230+ device, an instance of :class:`dpctl.SyclQueue`, or a
231+ :class:`dpctl.tensor.Device` object returned by
232+ :attr:`dpnp.ndarray.device`.
233+ If the value is ``None``, returned array is created on the same device
234+ as `a`.
235+
297236 Default: ``None``.
298237 usm_type : {None, "device", "shared", "host"}, optional
299238 The type of SYCL USM allocation for the result array if new array
300239 is created.
240+
301241 Default: ``None``.
302242 sycl_queue : {None, SyclQueue}, optional
303243 A SYCL queue to use for result array allocation if required.
244+
304245 Default: ``None``.
305246
306247 Returns
@@ -391,11 +332,15 @@ def check_supported_arrays_type(*arrays, scalar_type=False, all_scalars=False):
391332 ----------
392333 arrays : {dpnp.ndarray, usm_ndarray}
393334 Input arrays to check for supported types.
394- scalar_type : { bool} , optional
335+ scalar_type : bool, optional
395336 A scalar type is also considered as supported if flag is ``True``.
396- all_scalars : {bool}, optional
337+
338+ Default: ``False``.
339+ all_scalars : bool, optional
397340 All the input arrays can be scalar if flag is ``True``.
398341
342+ Default: ``False``.
343+
399344 Returns
400345 -------
401346 out : bool
@@ -437,20 +382,24 @@ def default_float_type(device=None, sycl_queue=None):
437382
438383 Parameters
439384 ----------
440- device : {None, string, SyclDevice, SyclQueue}, optional
441- An array API concept of device where an array of default floating type
442- might be created. The `device` can be ``None`` (the default) , an OneAPI
443- filter selector string, an instance of :class:`dpctl.SyclDevice`
444- corresponding to a non-partitioned SYCL device, an instance of
445- :class:`dpctl.SyclQueue`, or a ` Device` object returned by
446- :obj :`dpnp.dpnp_array.dpnp_array. device` property .
385+ device : {None, string, SyclDevice, SyclQueue, Device }, optional
386+ An array API concept of device where the output array is created.
387+ `device` can be ``None``, a oneAPI filter selector string , an instance
388+ of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL
389+ device, an instance of :class:`dpctl.SyclQueue`, or a
390+ :class:`dpctl.tensor. Device` object returned by
391+ :attr :`dpnp.ndarray. device`.
447392 The value ``None`` is interpreted as to use a default device.
393+
394+ Default: ``None``.
448395 sycl_queue : {None, SyclQueue}, optional
449396 A SYCL queue which might be used to create an array of default floating
450397 type. The `sycl_queue` can be ``None`` (the default), which is
451398 interpreted as to get the SYCL queue from `device` keyword if present
452399 or to use a default queue.
453400
401+ Default: ``None``.
402+
454403 Returns
455404 -------
456405 dt : dtype
@@ -461,7 +410,7 @@ def default_float_type(device=None, sycl_queue=None):
461410 _sycl_queue = get_normalized_queue_device (
462411 device = device , sycl_queue = sycl_queue
463412 )
464- return map_dtype_to_device (float64 , _sycl_queue .sycl_device )
413+ return map_dtype_to_device (dpnp . float64 , _sycl_queue .sycl_device )
465414
466415
467416def get_dpnp_descriptor (
@@ -569,16 +518,24 @@ def get_normalized_queue_device(obj=None, device=None, sycl_queue=None):
569518 and implementing `__sycl_usm_array_interface__` protocol, an instance
570519 of `numpy.ndarray`, an object supporting Python buffer protocol,
571520 a Python scalar, or a (possibly nested) sequence of Python scalars.
572- sycl_queue : class:`dpctl.SyclQueue`, optional
521+ sycl_queue : {None, class:`dpctl.SyclQueue`} , optional
573522 A queue which explicitly indicates where USM allocation is done
574523 and the population code (if any) is executed.
575524 Value ``None`` is interpreted as to get the SYCL queue from either
576525 `obj` parameter if not ``None`` or from `device` keyword,
577526 or to use default queue.
578- device : {string, :class:`dpctl.SyclDevice`, :class:`dpctl.SyclQueue,
579- :class:`dpctl.tensor.Device`}, optional
580- An array-API keyword indicating non-partitioned SYCL device
581- where array is allocated.
527+
528+ Default: ``None``.
529+ device : {None, string, SyclDevice, SyclQueue, Device}, optional
530+ An array API concept of device where the output array is created.
531+ `device` can be ``None``, a oneAPI filter selector string, an instance
532+ of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL
533+ device, an instance of :class:`dpctl.SyclQueue`, or a
534+ :class:`dpctl.tensor.Device` object returned by
535+ :attr:`dpnp.ndarray.device`.
536+ The value ``None`` is interpreted as to use the same device as `obj`.
537+
538+ Default: ``None``.
582539
583540 Returns
584541 -------
@@ -616,9 +573,13 @@ def get_result_array(a, out=None, casting="safe"):
616573 If provided, value of `a` array will be copied into it
617574 according to ``safe`` casting rule.
618575 It should be of the appropriate shape.
576+
577+ Default: ``None``.
619578 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
620579 Controls what kind of data casting may occur.
621580
581+ Default: ``'safe'``.
582+
622583 Returns
623584 -------
624585 out : {dpnp_array}
@@ -714,6 +675,7 @@ def is_cuda_backend(obj=None):
714675 An input object with sycl_device property to check device backend.
715676 If `obj` is ``None``, device backend will be checked for the default
716677 queue.
678+
717679 Default: ``None``.
718680
719681 Returns
0 commit comments