37
37
38
38
"""
39
39
# pylint: disable=protected-access
40
+ # pylint: disable=redefined-outer-name
40
41
41
42
import os
42
43
57
58
__all__ = [
58
59
"are_same_logical_tensors" ,
59
60
"asnumpy" ,
60
- "astype" ,
61
61
"as_usm_ndarray" ,
62
62
"check_limitations" ,
63
63
"check_supported_arrays_type" ,
74
74
"synchronize_array_data" ,
75
75
]
76
76
77
- from dpnp import float64
78
77
from dpnp .dpnp_iface_arraycreation import *
79
78
from dpnp .dpnp_iface_arraycreation import __all__ as __all__arraycreation
80
79
from dpnp .dpnp_iface_bitwise import *
@@ -182,11 +181,13 @@ def asnumpy(a, order="C"):
182
181
----------
183
182
a : {array_like}
184
183
Arbitrary object that can be converted to :obj:`numpy.ndarray`.
185
- order : {'C', 'F', 'A', 'K'}
184
+ order : {None, 'C', 'F', 'A', 'K'}, optional
186
185
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'``.
190
191
191
192
Returns
192
193
-------
@@ -208,71 +209,6 @@ def asnumpy(a, order="C"):
208
209
return numpy .asarray (a , order = order )
209
210
210
211
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
-
276
212
def as_usm_ndarray (a , dtype = None , device = None , usm_type = None , sycl_queue = None ):
277
213
"""
278
214
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):
285
221
The desired dtype for the result array if new array is creating. If not
286
222
given, a default dtype will be used that can represent the values (by
287
223
considering Promotion Type Rule and device capabilities when necessary).
224
+
288
225
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
+
297
236
Default: ``None``.
298
237
usm_type : {None, "device", "shared", "host"}, optional
299
238
The type of SYCL USM allocation for the result array if new array
300
239
is created.
240
+
301
241
Default: ``None``.
302
242
sycl_queue : {None, SyclQueue}, optional
303
243
A SYCL queue to use for result array allocation if required.
244
+
304
245
Default: ``None``.
305
246
306
247
Returns
@@ -391,11 +332,15 @@ def check_supported_arrays_type(*arrays, scalar_type=False, all_scalars=False):
391
332
----------
392
333
arrays : {dpnp.ndarray, usm_ndarray}
393
334
Input arrays to check for supported types.
394
- scalar_type : { bool} , optional
335
+ scalar_type : bool, optional
395
336
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
397
340
All the input arrays can be scalar if flag is ``True``.
398
341
342
+ Default: ``False``.
343
+
399
344
Returns
400
345
-------
401
346
out : bool
@@ -437,20 +382,24 @@ def default_float_type(device=None, sycl_queue=None):
437
382
438
383
Parameters
439
384
----------
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`.
447
392
The value ``None`` is interpreted as to use a default device.
393
+
394
+ Default: ``None``.
448
395
sycl_queue : {None, SyclQueue}, optional
449
396
A SYCL queue which might be used to create an array of default floating
450
397
type. The `sycl_queue` can be ``None`` (the default), which is
451
398
interpreted as to get the SYCL queue from `device` keyword if present
452
399
or to use a default queue.
453
400
401
+ Default: ``None``.
402
+
454
403
Returns
455
404
-------
456
405
dt : dtype
@@ -461,7 +410,7 @@ def default_float_type(device=None, sycl_queue=None):
461
410
_sycl_queue = get_normalized_queue_device (
462
411
device = device , sycl_queue = sycl_queue
463
412
)
464
- return map_dtype_to_device (float64 , _sycl_queue .sycl_device )
413
+ return map_dtype_to_device (dpnp . float64 , _sycl_queue .sycl_device )
465
414
466
415
467
416
def get_dpnp_descriptor (
@@ -569,16 +518,24 @@ def get_normalized_queue_device(obj=None, device=None, sycl_queue=None):
569
518
and implementing `__sycl_usm_array_interface__` protocol, an instance
570
519
of `numpy.ndarray`, an object supporting Python buffer protocol,
571
520
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
573
522
A queue which explicitly indicates where USM allocation is done
574
523
and the population code (if any) is executed.
575
524
Value ``None`` is interpreted as to get the SYCL queue from either
576
525
`obj` parameter if not ``None`` or from `device` keyword,
577
526
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``.
582
539
583
540
Returns
584
541
-------
@@ -616,9 +573,13 @@ def get_result_array(a, out=None, casting="safe"):
616
573
If provided, value of `a` array will be copied into it
617
574
according to ``safe`` casting rule.
618
575
It should be of the appropriate shape.
576
+
577
+ Default: ``None``.
619
578
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
620
579
Controls what kind of data casting may occur.
621
580
581
+ Default: ``'safe'``.
582
+
622
583
Returns
623
584
-------
624
585
out : {dpnp_array}
@@ -714,6 +675,7 @@ def is_cuda_backend(obj=None):
714
675
An input object with sycl_device property to check device backend.
715
676
If `obj` is ``None``, device backend will be checked for the default
716
677
queue.
678
+
717
679
Default: ``None``.
718
680
719
681
Returns
0 commit comments