Skip to content

Commit fee8e79

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

File tree

3 files changed

+166
-1
lines changed

3 files changed

+166
-1
lines changed

doc/reference/constants.rst

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

0 commit comments

Comments
 (0)