Skip to content

Commit f93db81

Browse files
authored
Update dpnp.ndarray docstrings (#2422)
This PR improves documentations of `dpnp.ndarray` class, including: - adding missing docstrings to the methods and attributes - extending `ndarray.rst` page to have all methods and attributes rendered - aligning signatures of the methods with numpy.ndarray class - adding a page with dpnp constants - updating a link with `dpnp.DLDeviceType` enum Also `dpnp_array.py` was added to pylint scope.
1 parent 9fc84dc commit f93db81

File tree

9 files changed

+677
-306
lines changed

9 files changed

+677
-306
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ repos:
119119
"--disable=redefined-builtin",
120120
"--disable=unused-wildcard-import"
121121
]
122-
files: '^dpnp/(dpnp_iface.*|fft|linalg)'
122+
files: '^dpnp/(dpnp_iface.*|fft|linalg|dpnp_array)'
123123
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
124124
rev: v2.14.0
125125
hooks:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
* Removed the use of class template argument deduction for alias template to conform to the C++17 standard [#2517](https://github.com/IntelPython/dpnp/pull/2517)
3030
* Changed th order of individual FFTs over `axes` for `dpnp.fft.irfftn` to be in forward order [#2524](https://github.com/IntelPython/dpnp/pull/2524)
3131
* Replaced the use of `numpy.testing.suppress_warnings` with appropriate calls from the warnings module [#2529](https://github.com/IntelPython/dpnp/pull/2529)
32+
* Improved documentations of `dpnp.ndarray` class and added a page with description of supported constants [#2422](https://github.com/IntelPython/dpnp/pull/2422)
3233

3334
### Deprecated
3435

doc/reference/constants.rst

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
Constants
2+
=========
3+
4+
DPNP includes several constants:
5+
6+
.. currentmodule:: dpnp
7+
8+
.. autodata:: DLDeviceType
9+
10+
.. data:: e
11+
12+
Euler's constant, base of natural logarithms, Napier's constant.
13+
14+
``e = 2.71828182845904523536028747135266249775724709369995...``
15+
16+
.. rubric:: See Also
17+
18+
:func:`exp` : Exponential function
19+
20+
:func:`log` : Natural logarithm
21+
22+
.. rubric:: References
23+
24+
https://en.wikipedia.org/wiki/E_%28mathematical_constant%29
25+
26+
27+
.. data:: euler_gamma
28+
29+
``γ = 0.5772156649015328606065120900824024310421...``
30+
31+
.. rubric:: References
32+
33+
https://en.wikipedia.org/wiki/Euler%27s_constant
34+
35+
36+
.. data:: inf
37+
38+
IEEE 754 floating point representation of (positive) infinity.
39+
40+
.. rubric:: Returns
41+
42+
y : float
43+
A floating point representation of positive infinity.
44+
45+
.. rubric:: See Also
46+
47+
:func:`isinf` : Shows which elements are positive or negative infinity
48+
49+
:func:`isposinf` : Shows which elements are positive infinity
50+
51+
:func:`isneginf` : Shows which elements are negative infinity
52+
53+
:func:`isnan` : Shows which elements are Not a Number
54+
55+
:func:`isfinite` : Shows which elements are finite (not one of Not a Number,
56+
positive infinity and negative infinity)
57+
58+
.. rubric:: Notes
59+
60+
DPNP uses the IEEE Standard for Binary Floating-Point for Arithmetic
61+
(IEEE 754). This means that Not a Number is not equivalent to infinity.
62+
Also that positive infinity is not equivalent to negative infinity. But
63+
infinity is equivalent to positive infinity.
64+
65+
.. rubric:: Examples
66+
67+
.. code-block:: python
68+
69+
>>> import dpnp as np
70+
>>> np.inf
71+
inf
72+
>>> np.array([1]) / 0.0
73+
array([inf])
74+
75+
76+
.. data:: nan
77+
78+
IEEE 754 floating point representation of Not a Number (NaN).
79+
80+
.. rubric:: Returns
81+
82+
y : A floating point representation of Not a Number.
83+
84+
.. rubric:: See Also
85+
86+
:func:`isnan` : Shows which elements are Not a Number
87+
88+
:func:`isfinite` : Shows which elements are finite (not one of Not a Number,
89+
positive infinity and negative infinity)
90+
91+
.. rubric:: Notes
92+
93+
DPNP uses the IEEE Standard for Binary Floating-Point for Arithmetic
94+
(IEEE 754). This means that Not a Number is not equivalent to infinity.
95+
96+
.. rubric:: Examples
97+
98+
.. code-block:: python
99+
100+
>>> import dpnp as np
101+
>>> np.nan
102+
nan
103+
>>> np.log(np.array(-1))
104+
array(nan)
105+
>>> np.log(np.array([-1, 1, 2]))
106+
array([ nan, 0. , 0.69314718])
107+
108+
109+
.. data:: newaxis
110+
111+
A convenient alias for *None*, useful for indexing arrays.
112+
113+
.. rubric:: Examples
114+
115+
.. code-block:: python
116+
117+
>>> import dpnp as np
118+
>>> np.newaxis is None
119+
True
120+
>>> x = np.arange(3)
121+
>>> x
122+
array([0, 1, 2])
123+
>>> x[:, np.newaxis]
124+
array([[0],
125+
[1],
126+
[2]])
127+
>>> x[:, np.newaxis, np.newaxis]
128+
array([[[0]],
129+
[[1]],
130+
[[2]]])
131+
>>> x[:, np.newaxis] * x
132+
array([[0, 0, 0],
133+
[0, 1, 2],
134+
[0, 2, 4]])
135+
136+
Outer product, same as ``outer(x, y)``:
137+
138+
>>> y = np.arange(3, 6)
139+
>>> x[:, np.newaxis] * y
140+
array([[ 0, 0, 0],
141+
[ 3, 4, 5],
142+
[ 6, 8, 10]])
143+
144+
``x[np.newaxis, :]`` is equivalent to ``x[np.newaxis]`` and ``x[None]``:
145+
146+
>>> x[np.newaxis, :].shape
147+
(1, 3)
148+
>>> x[np.newaxis].shape
149+
(1, 3)
150+
>>> x[None].shape
151+
(1, 3)
152+
>>> x[:, np.newaxis].shape
153+
(3, 1)
154+
155+
156+
.. data:: pi
157+
158+
``pi = 3.1415926535897932384626433...``
159+
160+
.. rubric:: References
161+
162+
https://en.wikipedia.org/wiki/Pi

doc/reference/ndarray.rst

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ of the array:
6666
dpnp.ndarray.size
6767
dpnp.ndarray.itemsize
6868
dpnp.ndarray.nbytes
69-
dpnp.ndarray.base
69+
dpnp.ndarray.device
70+
dpnp.ndarray.sycl_context
71+
dpnp.ndarray.sycl_device
72+
dpnp.ndarray.sycl_queue
73+
dpnp.ndarray.usm_type
7074

7175

7276
Data type
@@ -98,6 +102,17 @@ Other attributes
98102
dpnp.ndarray.flat
99103

100104

105+
Special attributes
106+
------------------
107+
108+
.. autosummary::
109+
:toctree: generated/
110+
:nosignatures:
111+
112+
dpnp.ndarray.__sycl_usm_array_interface__
113+
dpnp.ndarray.__usm_ndarray__
114+
115+
101116
Array methods
102117
-------------
103118

@@ -145,6 +160,7 @@ Array conversion
145160
dpnp.ndarray.getfield
146161
dpnp.ndarray.setflags
147162
dpnp.ndarray.fill
163+
dpnp.ndarray.get_array
148164

149165

150166
Shape manipulation
@@ -195,6 +211,26 @@ the operation should proceed.
195211
Calculation
196212
-----------
197213

214+
Many of these methods take an argument named *axis*. In such cases,
215+
216+
- If *axis* is *None* (the default), the array is treated as a 1-D array and
217+
the operation is performed over the entire array. This behavior is also the
218+
default if *self* is a 0-dimensional array.
219+
220+
- If *axis* is an integer, then the operation is done over the given axis (for
221+
each 1-D subarray that can be created along the given axis).
222+
223+
The parameter *dtype* specifies the data type over which a reduction operation
224+
(like summing) should take place. The default reduce data type is the same as
225+
the data type of *self*. To avoid overflow, it can be useful to perform the
226+
reduction using a larger data type.
227+
228+
For several methods, an optional *out* argument can also be provided and the
229+
result will be placed into the output array given. The *out* argument must be
230+
an :class:`dpnp.ndarray` and have the same number of elements as the result
231+
array. It can have a different data type in which case casting will be
232+
performed.
233+
198234
.. autosummary::
199235
:toctree: generated/
200236
:nosignatures:
@@ -226,12 +262,11 @@ Arithmetic and comparison operations on :class:`dpnp.ndarrays <dpnp.ndarray>`
226262
are defined as element-wise operations, and generally yield
227263
:class:`dpnp.ndarray` objects as results.
228264

229-
Each of the arithmetic operations (``+``, ``-``, ``*``, ``/``, ``//``,
230-
``%``, ``divmod()``, ``**`` or ``pow()``, ``<<``, ``>>``, ``&``,
231-
``^``, ``|``, ``~``) and the comparisons (``==``, ``<``, ``>``,
232-
``<=``, ``>=``, ``!=``) is equivalent to the corresponding
233-
universal function (or :term:`ufunc` for short) in DPNP. For
234-
more information, see the section on :ref:`Universal Functions
265+
Each of the arithmetic operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,
266+
``divmod()``, ``**`` or ``pow()``, ``<<``, ``>>``, ``&``, ``^``, ``|``, ``~``)
267+
and the comparisons (``==``, ``<``, ``>``, ``<=``, ``>=``, ``!=``) is
268+
equivalent to the corresponding universal function (or :term:`ufunc` for short)
269+
in DPNP. For more information, see the section on :ref:`Universal Functions
235270
<ufuncs>`.
236271

237272

@@ -252,6 +287,7 @@ Truth value of an array (:class:`bool() <bool>`):
252287

253288
.. autosummary::
254289
:toctree: generated/
290+
:nosignatures:
255291

256292
dpnp.ndarray.__bool__
257293

@@ -343,6 +379,7 @@ Matrix Multiplication:
343379

344380
.. autosummary::
345381
:toctree: generated/
382+
:nosignatures:
346383

347384
dpnp.ndarray.__matmul__
348385
dpnp.ndarray.__rmatmul__
@@ -371,7 +408,10 @@ Basic customization:
371408

372409
dpnp.ndarray.__new__
373410
dpnp.ndarray.__array__
411+
dpnp.ndarray.__array_namespace__
374412
dpnp.ndarray.__array_wrap__
413+
dpnp.ndarray.__dlpack__
414+
dpnp.ndarray.__dlpack_device__
375415

376416
Container customization: (see :ref:`Indexing <routines.indexing>`)
377417

@@ -380,19 +420,21 @@ Container customization: (see :ref:`Indexing <routines.indexing>`)
380420
:nosignatures:
381421

382422
dpnp.ndarray.__len__
423+
dpnp.ndarray.__iter__
383424
dpnp.ndarray.__getitem__
384425
dpnp.ndarray.__setitem__
385426
dpnp.ndarray.__contains__
386427

387-
Conversion; the operations :class:`int() <int>`,
388-
:class:`float() <float>` and :class:`complex() <complex>`.
428+
Conversion; the operations :class:`int() <int>`, :class:`float() <float>`,
429+
:class:`complex() <complex>` and :func:`operator.index() <operator.index>`.
389430
They work only on arrays that have one element in them
390431
and return the appropriate scalar.
391432

392433
.. autosummary::
393434
:toctree: generated/
394435
:nosignatures:
395436

437+
dpnp.ndarray.__index__
396438
dpnp.ndarray.__int__
397439
dpnp.ndarray.__float__
398440
dpnp.ndarray.__complex__

doc/reference/routines.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ These functions cover a subset of
1111
.. toctree::
1212
:maxdepth: 2
1313

14+
constants
1415
array-creation
1516
array-manipulation
1617
bitwise

0 commit comments

Comments
 (0)