Skip to content

Commit a4e9c04

Browse files
committed
Added missing docstrings to ndarray methods
1 parent cf3159e commit a4e9c04

File tree

4 files changed

+82
-26
lines changed

4 files changed

+82
-26
lines changed

doc/reference/ndarray.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ Each of the arithmetic operations (``+``, ``-``, ``*``, ``/``, ``//``,
231231
``%``, ``divmod()``, ``**`` or ``pow()``, ``<<``, ``>>``, ``&``,
232232
``^``, ``|``, ``~``) and the comparisons (``==``, ``<``, ``>``,
233233
``<=``, ``>=``, ``!=``) is equivalent to the corresponding
234-
universal function (or **ufunc** for short) in DPNP. For
234+
:term:`universal function` (or :term:`ufunc` for short) in DPNP. For
235235
more information, see the section on :ref:`Universal Functions
236-
<ufunc>`.
236+
<ufuncs>`.
237237

238238

239239
Comparison operators:
@@ -249,6 +249,23 @@ Comparison operators:
249249
dpnp.ndarray.__eq__
250250
dpnp.ndarray.__ne__
251251

252+
Truth value of an array (:func:`bool()`):
253+
254+
.. autosummary::
255+
:toctree: generated/
256+
257+
ndarray.__bool__
258+
259+
.. note::
260+
261+
Truth-value testing of an array invokes
262+
:meth:`ndarray.__bool__`, which raises an error if the number of
263+
elements in the array is larger than 1, because the truth value
264+
of such arrays is ambiguous. Use :meth:`.any() <ndarray.any>` and
265+
:meth:`.all() <ndarray.all>` instead to be clear about what is meant
266+
in such cases. (If the number of elements is 0, the array evaluates
267+
to ``False``.)
268+
252269

253270
Unary operations:
254271

@@ -303,6 +320,14 @@ Arithmetic, in-place:
303320
dpnp.ndarray.__ixor__
304321

305322

323+
Matrix Multiplication:
324+
325+
.. autosummary::
326+
:toctree: generated/
327+
328+
ndarray.__matmul__
329+
330+
306331
Special methods
307332
---------------
308333

dpnp/dpnp_array.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __and__(self, other):
159159
# '__array_wrap__',
160160

161161
def __bool__(self):
162+
"""``True`` if self else ``False``."""
162163
return self._array_obj.__bool__()
163164

164165
# '__class__',
@@ -185,12 +186,47 @@ def __copy__(self):
185186
# '__doc__',
186187

187188
def __dlpack__(self, stream=None):
189+
"""
190+
Produces DLPack capsule.
191+
192+
Parameters
193+
----------
194+
stream : {:class:`dpctl.SyclQueue`, None}, optional
195+
Execution queue to synchronize with. If ``None``,
196+
synchronization is not performed.
197+
198+
Raises
199+
------
200+
MemoryError
201+
when host memory can not be allocated.
202+
DLPackCreationError
203+
when array is allocated on a partitioned
204+
SYCL device, or with a non-default context.
205+
206+
"""
207+
188208
return self._array_obj.__dlpack__(stream=stream)
189209

190210
def __dlpack_device__(self):
211+
"""
212+
Gives a tuple (``device_type``, ``device_id``) corresponding to
213+
``DLDevice`` entry in ``DLTensor`` in DLPack protocol.
214+
215+
The tuple describes the non-partitioned device where the array has been
216+
allocated, or the non-partitioned parent device of the allocation
217+
device.
218+
219+
Raises
220+
------
221+
DLPackCreationError:
222+
when the ``device_id`` could not be determined.
223+
224+
"""
225+
191226
return self._array_obj.__dlpack_device__()
192227

193228
def __eq__(self, other):
229+
"""Return ``self==value``."""
194230
return dpnp.equal(self, other)
195231

196232
def __float__(self):
@@ -203,6 +239,7 @@ def __floordiv__(self, other):
203239
# '__format__',
204240

205241
def __ge__(self, other):
242+
"""Return ``self>=value``."""
206243
return dpnp.greater_equal(self, other)
207244

208245
# '__getattribute__',
@@ -224,6 +261,7 @@ def __getitem__(self, key):
224261
return res
225262

226263
def __gt__(self, other):
264+
"""Return ``self>value``."""
227265
return dpnp.greater(self, other)
228266

229267
# '__hash__',
@@ -306,21 +344,23 @@ def __ixor__(self, other):
306344
return self
307345

308346
def __le__(self, other):
347+
"""Return ``self<=value``."""
309348
return dpnp.less_equal(self, other)
310349

311350
def __len__(self):
312351
"""Return ``len(self)``."""
313-
314352
return self._array_obj.__len__()
315353

316354
def __lshift__(self, other):
317355
"""Return ``self<<value``."""
318356
return dpnp.left_shift(self, other)
319357

320358
def __lt__(self, other):
359+
"""Return ``self<value``."""
321360
return dpnp.less(self, other)
322361

323362
def __matmul__(self, other):
363+
"""Return ``self@value``."""
324364
return dpnp.matmul(self, other)
325365

326366
def __mod__(self, other):
@@ -332,6 +372,7 @@ def __mul__(self, other):
332372
return dpnp.multiply(self, other)
333373

334374
def __ne__(self, other):
375+
"""Return ``self!=value``."""
335376
return dpnp.not_equal(self, other)
336377

337378
def __neg__(self):
@@ -363,6 +404,7 @@ def __rand__(self, other):
363404
# '__reduce_ex__',
364405

365406
def __repr__(self):
407+
"""Return ``repr(self)``."""
366408
return dpt.usm_ndarray_repr(self._array_obj, prefix="array")
367409

368410
def __rfloordiv__(self, other):
@@ -417,18 +459,7 @@ def __setitem__(self, key, val):
417459
# '__sizeof__',
418460

419461
def __str__(self):
420-
"""
421-
Output values from the array to standard output.
422-
423-
Examples
424-
--------
425-
>>> print(a)
426-
[[ 136. 136. 136.]
427-
[ 272. 272. 272.]
428-
[ 408. 408. 408.]]
429-
430-
"""
431-
462+
"""Return ``str(self)``."""
432463
return self._array_obj.__str__()
433464

434465
def __sub__(self, other):
@@ -1060,12 +1091,12 @@ def real(self):
10601091
array([1. , 0.70710677])
10611092
10621093
"""
1094+
10631095
if dpnp.issubsctype(self.dtype, dpnp.complexfloating):
10641096
return dpnp_array._create_from_usm_ndarray(
10651097
dpnp.get_usm_ndarray(self).real
10661098
)
1067-
else:
1068-
return self
1099+
return self
10691100

10701101
@real.setter
10711102
def real(self, value):
@@ -1083,6 +1114,7 @@ def real(self, value):
10831114
array([9.+2.j, 9.+4.j, 9.+6.j])
10841115
10851116
"""
1117+
10861118
dpnp.copyto(self._array_obj.real, value)
10871119

10881120
def repeat(self, repeats, axis=None):
@@ -1152,7 +1184,8 @@ def searchsorted(self, v, side="left", sorter=None):
11521184

11531185
@property
11541186
def shape(self):
1155-
"""Lengths of axes. A tuple of numbers represents size of each dimension.
1187+
"""
1188+
Lengths of axes. A tuple of numbers represents size of each dimension.
11561189
11571190
Setter of this property involves reshaping without copy. If the array
11581191
cannot be reshaped without copy, it raises an exception.
@@ -1181,7 +1214,6 @@ def shape(self, newshape):
11811214
@property
11821215
def size(self):
11831216
"""Number of elements in the array."""
1184-
11851217
return self._array_obj.size
11861218

11871219
def sort(self, axis=-1, kind=None, order=None):
@@ -1250,14 +1282,12 @@ def std(
12501282
@property
12511283
def strides(self):
12521284
"""
1253-
Get strides of an array.
1254-
12551285
Returns memory displacement in array elements, upon unit
12561286
change of respective index.
12571287
1258-
E.g. for strides (s1, s2, s3) and multi-index (i1, i2, i3)
1259-
1260-
a[i1, i2, i3] == (&a[0,0,0])[ s1*s1 + s2*i2 + s3*i3]
1288+
For example, for strides ``(s1, s2, s3)`` and multi-index
1289+
``(i1, i2, i3)`` position of the respective element relative
1290+
to zero multi-index element is ``s1*s1 + s2*i2 + s3*i3``.
12611291
12621292
"""
12631293

@@ -1403,6 +1433,7 @@ def var(
14031433
Refer to :obj:`dpnp.var` for full documentation.
14041434
14051435
"""
1436+
14061437
return dpnp.var(self, axis, dtype, out, ddof, keepdims, where=where)
14071438

14081439

dpnp/dpnp_iface_arraycreation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ def logspace(
25612561
tuples of lists, and ndarrays. `base` ** `stop` is the final value of
25622562
the sequence, unless `endpoint` is ``False``. In that case, ``num + 1``
25632563
values are spaced over the interval in log-space, of which all but
2564-
the last (a sequence of length num) are returned.
2564+
the last (a sequence of length `num`) are returned.
25652565
num : int, optional
25662566
Number of samples to generate. Default is 50.
25672567
device : {None, string, SyclDevice, SyclQueue}, optional

dpnp/dpnp_iface_manipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ def shape(a):
15561556
15571557
Returns
15581558
-------
1559-
shape : tuple of ints
1559+
shape : tuple of integers
15601560
The elements of the shape tuple give the lengths of the
15611561
corresponding array dimensions.
15621562

0 commit comments

Comments
 (0)