Skip to content

Commit d0d4bf1

Browse files
Closes gh-1115, fixes docstring's Returns sections
1 parent 26b2eaa commit d0d4bf1

File tree

9 files changed

+339
-137
lines changed

9 files changed

+339
-137
lines changed

dpctl/tensor/_copy_utils.py

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,29 @@ def from_numpy(np_ary, device=None, usm_type="device", sycl_queue=None):
125125
from_numpy(arg, device=None, usm_type="device", sycl_queue=None)
126126
127127
Creates :class:`dpctl.tensor.usm_ndarray` from instance of
128-
`numpy.ndarray`.
128+
:class:`numpy.ndarray`.
129129
130130
Args:
131-
arg: An instance of input `numpy.ndarray`
132-
device: array API specification of device where the output array
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
131+
arg (array-like): An instance of input convertible to
132+
:class:`numpy.ndarray`
133+
device (object): array API specification of device where the
134+
output array is created. Device can be specified by a
135+
a filter selector string, an instance of
136+
:class:`dpctl.SyclDevice`, an instance of
137+
:class:`dpctl.SyclQueue`, an instance of
138+
:class:`dpctl.tensor.Device`. If the value is `None`,
139+
returned array is created on the default-selected device.
140+
Default: `None`.
141+
usm_type (str): The requested USM allocation type for the
142+
output array. Recognized values are `"device"`, `"shared"`,
143+
or `"host"`.
144+
sycl_queue (:class:`dpctl.SyclQueue`, optional):
145+
A SYCL queue that determines output array allocation device
146+
as well as execution placement of data movement operations.
147+
The `device` and `sycl_queue` arguments
138148
are equivalent. Only one of them should be specified. If both
139149
are provided, they must be consistent and result in using the
140-
same execution queue.
150+
same execution queue. Default: `None`.
141151
142152
The returned array has the same shape, and the same data type kind.
143153
If the device does not support the data type of input array, a
@@ -154,12 +164,15 @@ def to_numpy(usm_ary):
154164
to_numpy(usm_ary)
155165
156166
Copies content of :class:`dpctl.tensor.usm_ndarray` instance `usm_ary`
157-
into `numpy.ndarray` instance of the same shape and same data type.
167+
into :class:`numpy.ndarray` instance of the same shape and same data type.
158168
159169
Args:
160-
usm_ary: An instance of :class:`dpctl.tensor.usm_ndarray`
170+
usm_ary (usm_ndarray):
171+
Input array
161172
Returns:
162-
An instance of `numpy.ndarray` populated with content of `usm_ary`.
173+
:class:`numpy.ndarray`:
174+
An instance of :class:`numpy.ndarray` populated with content of
175+
`usm_ary`
163176
"""
164177
return _copy_to_numpy(usm_ary)
165178

@@ -169,18 +182,24 @@ def asnumpy(usm_ary):
169182
asnumpy(usm_ary)
170183
171184
Copies content of :class:`dpctl.tensor.usm_ndarray` instance `usm_ary`
172-
into `numpy.ndarray` instance of the same shape and same data type.
185+
into :class:`numpy.ndarray` instance of the same shape and same data
186+
type.
173187
174188
Args:
175-
usm_ary: An instance of :class:`dpctl.tensor.usm_ndarray`
189+
usm_ary (usm_ndarray):
190+
Input array
176191
Returns:
177-
An instance of `numpy.ndarray` populated with content of `usm_ary`.
192+
:class:`numpy.ndarray`:
193+
An instance of :class:`numpy.ndarray` populated with content
194+
of `usm_ary`
178195
"""
179196
return _copy_to_numpy(usm_ary)
180197

181198

182199
class Dummy:
183-
"Helper class with specified __sycl_usm_array_interface__ attribute"
200+
"""
201+
Helper class with specified ``__sycl_usm_array_interface__`` attribute
202+
"""
184203

185204
def __init__(self, iface):
186205
self.__sycl_usm_array_interface__ = iface
@@ -280,10 +299,20 @@ def _copy_from_usm_ndarray_to_usm_ndarray(dst, src):
280299

281300

282301
def copy(usm_ary, order="K"):
283-
"""
284-
Creates a copy of given instance of `usm_ndarray`.
302+
"""copy(ary, order="K")
303+
304+
Creates a copy of given instance of :class:`dpctl.tensor.usm_ndarray`.
305+
306+
Args:
307+
ary (usm_ndarray):
308+
Input array.
309+
order ({"C", "F", "A", "K"}, optional):
310+
Controls the memory layout of the output array.
311+
Returns:
312+
usm_ndarray:
313+
A copy of the input array.
285314
286-
Memory layour of the copy is controlled by `order` keyword,
315+
Memory layout of the copy is controlled by `order` keyword,
287316
following NumPy's conventions. The `order` keywords can be
288317
one of the following:
289318
@@ -342,10 +371,31 @@ def copy(usm_ary, order="K"):
342371

343372

344373
def astype(usm_ary, newdtype, order="K", casting="unsafe", copy=True):
345-
"""
346-
astype(usm_array, new_dtype, order="K", casting="unsafe", copy=True)
374+
""" astype(array, new_dtype, order="K", casting="unsafe", \
375+
copy=True)
376+
377+
Returns a copy of the :class:`dpctl.tensor.usm_ndarray`, cast to a
378+
specified type.
347379
348-
Returns a copy of the array, cast to a specified type.
380+
Args:
381+
array (usm_ndarray):
382+
An input array.
383+
new_dtype (dtype):
384+
The data type of the resulting array.
385+
order ({"C", "F", "A", "K"}, optional):
386+
Controls memory layout of the resulting array if a copy
387+
is returned.
388+
casting ({'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional):
389+
Controls what kind of data casting may occur. Please see
390+
:meth:`numpy.ndarray.astype` for description of casting modes.
391+
copy (bool, optional):
392+
By default, `astype` always returns a newly allocated array.
393+
If this keyword is set to `False`, a view of the input array
394+
may be returned when possible.
395+
396+
Returns:
397+
usm_ndarray:
398+
An array with requested data type.
349399
350400
A view can be returned, if possible, when `copy=False` is used.
351401
"""

0 commit comments

Comments
 (0)