Skip to content

Commit 2b560f8

Browse files
committed
Add a page with constants documented and set a proper reference on dpnp.DLDeviceType
1 parent 199c4f9 commit 2b560f8

File tree

4 files changed

+177
-10
lines changed

4 files changed

+177
-10
lines changed

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/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

dpnp/dpnp_array.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ def __dlpack__(
233233
dl_device : {tuple, None}, optional:
234234
The device the returned DLPack capsule will be placed on. The
235235
device must be a 2-tuple matching the format of
236-
``__dlpack_device__`` method, an integer enumerator representing
237-
the device type followed by an integer representing the index of
238-
the device.
236+
:meth:`dpnp.ndarray.__dlpack_device__`, an integer enumerator
237+
representing the device type followed by an integer representing
238+
the index of the device.
239239
240240
Default: ``None``.
241241
copy : {bool, None}, optional:
@@ -278,9 +278,12 @@ def __dlpack_device__(self, /):
278278
allocated, or the non-partitioned parent device of the allocation
279279
device.
280280
281+
See :class:`dpnp.DLDeviceType` for a list of devices supported by the
282+
DLPack protocol.
283+
281284
Raises
282285
------
283-
DLPackCreationError:
286+
DLPackCreationError
284287
when the ``device_id`` could not be determined.
285288
286289
"""

dpnp/dpnp_iface_arraycreation.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,8 +2180,9 @@ def from_dlpack(x, /, *, device=None, copy=None):
21802180
Parameters
21812181
----------
21822182
x : object
2183-
A Python object representing an array that implements the ``__dlpack__``
2184-
and ``__dlpack_device__`` methods.
2183+
A Python object representing an array that implements the
2184+
:meth:`dpnp.ndarray.__dlpack__` and
2185+
:meth:`dpnp.ndarray.__dlpack_device__`.
21852186
device : {None, string, tuple, device}, optional
21862187
Device where the output array is to be placed. `device` keyword values
21872188
can be:
@@ -2197,10 +2198,10 @@ def from_dlpack(x, /, *, device=None, copy=None):
21972198
``device.sycl_queue``. The `device` object is obtained via
21982199
:attr:`dpctl.tensor.usm_ndarray.device`.
21992200
* ``(device_type, device_id)`` : 2-tuple matching the format of the
2200-
output of the ``__dlpack_device__`` method: an integer enumerator
2201-
representing the device type followed by an integer representing
2202-
the index of the device. The only supported :class:`dpnp.DLDeviceType`
2203-
device types are ``"kDLCPU"`` and ``"kDLOneAPI"``.
2201+
output of the :meth:`dpnp.ndarray.__dlpack_device__`: an integer
2202+
enumerator representing the device type followed by an integer
2203+
representing the index of the device. The only supported
2204+
:class:`dpnp.DLDeviceType` are ``"kDLCPU"`` and ``"kDLOneAPI"``.
22042205
22052206
Default: ``None``.
22062207
copy : {bool, None}, optional

0 commit comments

Comments
 (0)