Skip to content

Commit 742b603

Browse files
author
Diptorup Deb
authored
Merge pull request #1123 from IntelPython/tensor-docs-cleanup
Closes gh-1114 and gh-1116
2 parents 8f828f2 + 49c3a9c commit 742b603

File tree

10 files changed

+575
-260
lines changed

10 files changed

+575
-260
lines changed

dpctl/tensor/_copy_utils.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,22 @@ def from_numpy(np_ary, device=None, usm_type="device", sycl_queue=None):
128128
`numpy.ndarray`.
129129
130130
Args:
131-
arg: An instance of `numpy.ndarray`
131+
arg: An instance of input `numpy.ndarray`
132132
device: array API specification of device where the output array
133-
is created.
134-
sycl_queue: a :class:`dpctl.SyclQueue` used to create the output
135-
array is created
133+
is created
134+
usm_type: The requested USM allocation type for the output array
135+
sycl_queue: a :class:`dpctl.SyclQueue` instance that determines
136+
output array allocation device as well as placement of data
137+
movement operation. The `device` and `sycl_queue` arguments
138+
are equivalent. Only one of them should be specified. If both
139+
are provided, they must be consistent and result in using the
140+
same execution queue.
141+
142+
The returned array has the same shape, and the same data type kind.
143+
If the device does not support the data type of input array, a
144+
closest support data type of the same kind may be returned, e.g.
145+
input array of type `float16` may be upcast to `float32` if the
146+
target device does not support 16-bit floating point type.
136147
"""
137148
q = normalize_queue_device(sycl_queue=sycl_queue, device=device)
138149
return _copy_from_numpy(np_ary, usm_type=usm_type, sycl_queue=q)

dpctl/tensor/_ctors.py

Lines changed: 238 additions & 169 deletions
Large diffs are not rendered by default.

dpctl/tensor/_device.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ def __new__(cls, *args, **kwargs):
3939
raise TypeError("No public constructor")
4040

4141
@classmethod
42-
def create_device(cls, dev):
43-
"""
42+
def create_device(cls, dev=None):
43+
"""Device.create_device(dev=None)
44+
4445
Creates instance of Device from argument.
4546
4647
Args:
47-
dev: None, :class:`.Device`, :class:`dpctl.SyclQueue`, or
48-
a :class:`dpctl.SyclDevice` corresponding to a root SYCL
49-
device.
48+
dev:
49+
Device specification, i.e. `None`, :class:`.Device`,
50+
:class:`dpctl.SyclQueue`, or a :class:`dpctl.SyclDevice`
51+
corresponding to a root SYCL device.
5052
Raises:
5153
ValueError: if an instance of :class:`dpctl.SycDevice` corresponding
5254
to a sub-device was specified as the argument
@@ -135,14 +137,13 @@ def __hash__(self):
135137

136138

137139
def normalize_queue_device(sycl_queue=None, device=None):
138-
"""
139-
normalize_queue_device(sycl_queue=None, device=None)
140+
"""normalize_queue_device(sycl_queue=None, device=None)
140141
141142
Utility to process exclusive keyword arguments 'device'
142143
and 'sycl_queue' in functions of `dpctl.tensor`.
143144
144145
Args:
145-
sycl_queue(:class:`dpctl.SyclQueue`, optional):
146+
sycl_queue (:class:`dpctl.SyclQueue`, optional):
146147
explicitly indicates where USM allocation is done
147148
and the population code (if any) is executed.
148149
Value `None` is interpreted as get the SYCL queue

dpctl/tensor/_dlpack.pyx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,25 @@ cpdef usm_ndarray from_dlpack_capsule(object py_caps) except +:
469469

470470

471471
cpdef from_dlpack(array):
472-
"""
473-
dpctl.tensor.from_dlpack(obj) -> dpctl.tensor.usm_ndarray
472+
""" from_dlpack(obj)
474473
475474
Constructs :class:`dpctl.tensor.usm_ndarray` instance from a Python
476475
object `obj` that implements `__dlpack__` protocol. The output
477476
array is always a zero-copy view of the input.
478477
478+
Args:
479+
obj: A Python object representing an array that supports `__dlpack__`
480+
protocol.
481+
482+
Returns:
483+
out (usm_ndarray):
484+
An array with a view into the tensor underlying the input `obj`.
485+
486+
Raises:
487+
TypeError: if `obj` does not implement `__dlpack__` method.
488+
ValueError: if zero copy view can not be constructed because
489+
the input array resides on an unsupported device.
490+
479491
See https://dmlc.github.io/dlpack/latest/ for more details.
480492
481493
:Example:
@@ -498,13 +510,6 @@ cpdef from_dlpack(array):
498510
C = Container(dpt.linspace(0, 100, num=20, dtype="int16"))
499511
X = dpt.from_dlpack(C)
500512
501-
Args:
502-
obj: A Python object representing an array that supports `__dlpack__`
503-
protocol.
504-
Raises:
505-
TypeError: if `obj` does not implement `__dlpack__` method.
506-
ValueError: if zero copy view can not be constructed because
507-
the input array resides on an unsupported device.
508513
"""
509514
if not hasattr(array, "__dlpack__"):
510515
raise TypeError(

dpctl/tensor/_indexing_functions.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@ def take(x, indices, /, *, axis=None, mode="clip"):
3232
Takes elements from array along a given axis.
3333
3434
Args:
35-
x: usm_ndarray
35+
x (usm_ndarray):
3636
The array that elements will be taken from.
37-
indices: usm_ndarray
37+
indices (usm_ndarray):
3838
One-dimensional array of indices.
3939
axis:
4040
The axis over which the values will be selected.
4141
If x is one-dimensional, this argument is optional.
42+
Default: `None`.
4243
mode:
4344
How out-of-bounds indices will be handled.
44-
"Clip" - clamps indices to (-n <= i < n), then wraps
45+
"clip" - clamps indices to (-n <= i < n), then wraps
4546
negative indices.
46-
"Wrap" - wraps both negative and positive indices.
47+
"wrap" - wraps both negative and positive indices.
48+
Default: `"clip"`.
4749
4850
Returns:
4951
out: usm_ndarray
@@ -119,21 +121,23 @@ def put(x, indices, vals, /, *, axis=None, mode="clip"):
119121
along a given axis.
120122
121123
Args:
122-
x: usm_ndarray
124+
x (usm_ndarray):
123125
The array the values will be put into.
124-
indices: usm_ndarray
126+
indices (usm_ndarray)
125127
One-dimensional array of indices.
126128
vals:
127129
Array of values to be put into `x`.
128130
Must be broadcastable to the shape of `indices`.
129131
axis:
130132
The axis over which the values will be placed.
131133
If x is one-dimensional, this argument is optional.
134+
Default: `None`.
132135
mode:
133136
How out-of-bounds indices will be handled.
134-
"Clip" - clamps indices to (-axis_size <= i < axis_size),
137+
"clip" - clamps indices to (-axis_size <= i < axis_size),
135138
then wraps negative indices.
136-
"Wrap" - wraps both negative and positive indices.
139+
"wrap" - wraps both negative and positive indices.
140+
Default: `"clip"`.
137141
"""
138142
if not isinstance(x, dpt.usm_ndarray):
139143
raise TypeError(
@@ -219,14 +223,14 @@ def extract(condition, arr):
219223
``dpctl.tensor.extract``.
220224
221225
Args:
222-
conditions: usm_ndarray
226+
conditions (usm_ndarray):
223227
An array whose non-zero or True entries indicate the element
224228
of `arr` to extract.
225-
arr: usm_ndarray
229+
arr (usm_ndarray):
226230
Input array of the same size as `condition`.
227231
228232
Returns:
229-
usm_ndarray
233+
out (usm_ndarray):
230234
Rank 1 array of values from `arr` where `condition` is True.
231235
"""
232236
if not isinstance(condition, dpt.usm_ndarray):
@@ -259,11 +263,11 @@ def place(arr, mask, vals):
259263
equivalent to ``arr[condition] = vals``.
260264
261265
Args:
262-
arr: usm_ndarray
266+
arr (usm_ndarray):
263267
Array to put data into.
264-
mask: usm_ndarray
268+
mask (usm_ndarray):
265269
Boolean mask array. Must have the same size as `arr`.
266-
vals: usm_ndarray
270+
vals (usm_ndarray, sequence):
267271
Values to put into `arr`. Only the first N elements are
268272
used, where N is the number of True values in `mask`. If
269273
`vals` is smaller than N, it will be repeated, and if
@@ -325,10 +329,10 @@ def nonzero(arr):
325329
row-major, C-style order.
326330
327331
Args:
328-
arr: usm_ndarray
332+
arr (usm_ndarray):
329333
Input array, which has non-zero array rank.
330334
Returns:
331-
Tuple[usm_ndarray]
335+
out: Tuple[usm_ndarray, ...]
332336
Indices of non-zero array elements.
333337
"""
334338
if not isinstance(arr, dpt.usm_ndarray):

0 commit comments

Comments
 (0)