Skip to content

Commit 2bab446

Browse files
Update doc of elementwise functions (#2188)
* Update bitwise docs adding broadcast info * Update logic func docs adding broadcast info * Update mathematical func docs adding broadcast info * Update trigonometric func docs adding broadcast info
1 parent 367e74e commit 2bab446

File tree

4 files changed

+94
-9
lines changed

4 files changed

+94
-9
lines changed

dpnp/dpnp_iface_bitwise.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def binary_repr(num, width=None):
140140
x2 : {dpnp.ndarray, usm_ndarray, scalar}
141141
Second input array, also expected to have integer or boolean data
142142
type. Both inputs `x1` and `x2` can not be scalars at the same time.
143+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
144+
(which becomes the shape of the output).
143145
out : {None, dpnp.ndarray, usm_ndarray}, optional
144146
Output array to populate.
145147
Array must have the correct shape and the expected data type.
@@ -224,6 +226,8 @@ def binary_repr(num, width=None):
224226
x2 : {dpnp.ndarray, usm_ndarray, scalar}
225227
Second input array, also expected to have integer or boolean data
226228
type. Both inputs `x1` and `x2` can not be scalars at the same time.
229+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
230+
(which becomes the shape of the output).
227231
out : {None, dpnp.ndarray, usm_ndarray}, optional
228232
Output array to populate.
229233
Array must have the correct shape and the expected data type.
@@ -299,6 +303,8 @@ def binary_repr(num, width=None):
299303
x2 : {dpnp.ndarray, usm_ndarray, scalar}
300304
Second input array, also expected to have integer or boolean data
301305
type. Both inputs `x1` and `x2` can not be scalars at the same time.
306+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
307+
(which becomes the shape of the output).
302308
out : {None, dpnp.ndarray, usm_ndarray}, optional
303309
Output array to populate.
304310
Array must have the correct shape and the expected data type.
@@ -458,6 +464,8 @@ def binary_repr(num, width=None):
458464
Second input array, also expected to have integer data type.
459465
Each element must be greater than or equal to ``0``.
460466
Both inputs `x1` and `x2` can not be scalars at the same time.
467+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
468+
(which becomes the shape of the output).
461469
out : {None, dpnp.ndarray, usm_ndarray}, optional
462470
Output array to populate.
463471
Array must have the correct shape and the expected data type.
@@ -532,6 +540,8 @@ def binary_repr(num, width=None):
532540
Second input array, also expected to have integer data type.
533541
Each element must be greater than or equal to ``0``.
534542
Both inputs `x1` and `x2` can not be scalars at the same time.
543+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
544+
(which becomes the shape of the output).
535545
out : {None, dpnp.ndarray, usm_ndarray}, optional
536546
Output array to populate.
537547
Array must have the correct shape and the expected data type.

dpnp/dpnp_iface_logic.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ def allclose(a, b, rtol=1.0e-5, atol=1.0e-8, equal_nan=False):
199199
Second input array, also expected to have numeric data type.
200200
Both inputs `a` and `b` can not be scalars at the same time.
201201
rtol : {dpnp.ndarray, usm_ndarray, scalar}, optional
202-
The relative tolerance parameter. Default: ``1e-05``.
202+
The relative tolerance parameter.
203+
Default: ``1e-05``.
203204
atol : {dpnp.ndarray, usm_ndarray, scalar}, optional
204-
The absolute tolerance parameter. Default: ``1e-08``.
205+
The absolute tolerance parameter.
206+
Default: ``1e-08``.
205207
equal_nan : bool
206208
Whether to compare ``NaNs`` as equal. If ``True``, ``NaNs`` in `a` will
207209
be considered equal to ``NaNs`` in `b` in the output array.
@@ -213,14 +215,20 @@ def allclose(a, b, rtol=1.0e-5, atol=1.0e-8, equal_nan=False):
213215
A 0-dim array with ``True`` value if the two arrays are equal within
214216
the given tolerance; with ``False`` otherwise.
215217
216-
217218
See Also
218219
--------
219220
:obj:`dpnp.isclose` : Test whether two arrays are element-wise equal.
220221
:obj:`dpnp.all` : Test whether all elements evaluate to True.
221222
:obj:`dpnp.any` : Test whether any element evaluates to True.
222223
:obj:`dpnp.equal` : Return (x1 == x2) element-wise.
223224
225+
Notes
226+
-----
227+
The comparison of `a` and `b` uses standard broadcasting, which
228+
means that `a` and `b` need not have the same shape in order for
229+
``dpnp.allclose(a, b)`` to evaluate to ``True``.
230+
The same is true for :obj:`dpnp.equal` but not :obj:`dpnp.array_equal`.
231+
224232
Examples
225233
--------
226234
>>> import dpnp as np
@@ -538,6 +546,8 @@ def array_equiv(a1, a2):
538546
x2 : {dpnp.ndarray, usm_ndarray, scalar}
539547
Second input array, also expected to have numeric data type.
540548
Both inputs `x1` and `x2` can not be scalars at the same time.
549+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
550+
(which becomes the shape of the output).
541551
out : {None, dpnp.ndarray, usm_ndarray}, optional
542552
Output array to populate.
543553
Array have the correct shape and the expected data type.
@@ -609,6 +619,8 @@ def array_equiv(a1, a2):
609619
x2 : {dpnp.ndarray, usm_ndarray, scalar}
610620
Second input array, also expected to have numeric data type.
611621
Both inputs `x1` and `x2` can not be scalars at the same time.
622+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
623+
(which becomes the shape of the output).
612624
out : {None, dpnp.ndarray, usm_ndarray}, optional
613625
Output array to populate.
614626
Array must have the correct shape and the expected data type.
@@ -675,6 +687,8 @@ def array_equiv(a1, a2):
675687
x2 : {dpnp.ndarray, usm_ndarray, scalar}
676688
Second input array, also expected to have numeric data type.
677689
Both inputs `x1` and `x2` can not be scalars at the same time.
690+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
691+
(which becomes the shape of the output).
678692
out : {None, dpnp.ndarray, usm_ndarray}, optional
679693
Output array to populate.
680694
Array must have the correct shape and the expected data type.
@@ -753,9 +767,11 @@ def isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False):
753767
Second input array, also expected to have numeric data type.
754768
Both inputs `a` and `b` can not be scalars at the same time.
755769
rtol : {dpnp.ndarray, usm_ndarray, scalar}, optional
756-
The relative tolerance parameter. Default: ``1e-05``.
770+
The relative tolerance parameter.
771+
Default: ``1e-05``.
757772
atol : {dpnp.ndarray, usm_ndarray, scalar}, optional
758-
The absolute tolerance parameter. Default: ``1e-08``.
773+
The absolute tolerance parameter.
774+
Default: ``1e-08``.
759775
equal_nan : bool
760776
Whether to compare ``NaNs`` as equal. If ``True``, ``NaNs`` in `a` will
761777
be considered equal to ``NaNs`` in `b` in the output array.
@@ -1446,6 +1462,8 @@ def isscalar(element):
14461462
x2 : {dpnp.ndarray, usm_ndarray, scalar}
14471463
Second input array, also expected to have numeric data type.
14481464
Both inputs `x1` and `x2` can not be scalars at the same time.
1465+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1466+
(which becomes the shape of the output).
14491467
out : {None, dpnp.ndarray, usm_ndarray}, optional
14501468
Output array to populate.
14511469
Array must have the correct shape and the expected data type.
@@ -1512,6 +1530,8 @@ def isscalar(element):
15121530
x2 : {dpnp.ndarray, usm_ndarray, scalar}
15131531
Second input array, also expected to have numeric data type.
15141532
Both inputs `x1` and `x2` can not be scalars at the same time.
1533+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1534+
(which becomes the shape of the output).
15151535
out : {None, dpnp.ndarray, usm_ndarray}, optional
15161536
Output array to populate.
15171537
Array must have the correct shape and the expected data type.
@@ -1578,6 +1598,8 @@ def isscalar(element):
15781598
x2 : {dpnp.ndarray, usm_ndarray, scalar}
15791599
Second input array.
15801600
Both inputs `x1` and `x2` can not be scalars at the same time.
1601+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1602+
(which becomes the shape of the output).
15811603
out : {None, dpnp.ndarray, usm_ndarray}, optional
15821604
Output array to populate.
15831605
Array must have the correct shape and the expected data type.
@@ -1590,6 +1612,7 @@ def isscalar(element):
15901612
-------
15911613
out : dpnp.ndarray
15921614
An array containing the element-wise logical AND results.
1615+
The shape is determined by broadcasting.
15931616
15941617
Limitations
15951618
-----------
@@ -1699,6 +1722,8 @@ def isscalar(element):
16991722
x2 : {dpnp.ndarray, usm_ndarray, scalar}
17001723
Second input array.
17011724
Both inputs `x1` and `x2` can not be scalars at the same time.
1725+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1726+
(which becomes the shape of the output).
17021727
out : {None, dpnp.ndarray, usm_ndarray}, optional
17031728
Output array to populate.
17041729
Array must have the correct shape and the expected data type.
@@ -1711,6 +1736,7 @@ def isscalar(element):
17111736
-------
17121737
out : dpnp.ndarray
17131738
An array containing the element-wise logical OR results.
1739+
The shape is determined by broadcasting.
17141740
17151741
Limitations
17161742
-----------
@@ -1767,6 +1793,8 @@ def isscalar(element):
17671793
x2 : {dpnp.ndarray, usm_ndarray, scalar}
17681794
Second input array.
17691795
Both inputs `x1` and `x2` can not be scalars at the same time.
1796+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1797+
(which becomes the shape of the output).
17701798
out : {None, dpnp.ndarray, usm_ndarray}, optional
17711799
Output array to populate.
17721800
Array must have the correct shape and the expected data type.
@@ -1779,6 +1807,7 @@ def isscalar(element):
17791807
-------
17801808
out : dpnp.ndarray
17811809
An array containing the element-wise logical XOR results.
1810+
The shape is determined by broadcasting.
17821811
17831812
Limitations
17841813
-----------
@@ -1833,6 +1862,8 @@ def isscalar(element):
18331862
x2 : {dpnp.ndarray, usm_ndarray, scalar}
18341863
Second input array, also expected to have numeric data type.
18351864
Both inputs `x1` and `x2` can not be scalars at the same time.
1865+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1866+
(which becomes the shape of the output).
18361867
out : {None, dpnp.ndarray, usm_ndarray}, optional
18371868
Output array to populate.
18381869
Array must have the correct shape and the expected data type.

dpnp/dpnp_iface_mathematical.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ def _process_ediff1d_args(arg, arg_name, ary_dtype, ary_sycl_queue, usm_type):
428428
x2 : {dpnp.ndarray, usm_ndarray, scalar}
429429
Second input array, also expected to have numeric data type.
430430
Both inputs `x1` and `x2` can not be scalars at the same time.
431+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
432+
(which becomes the shape of the output).
431433
out : {None, dpnp.ndarray, usm_ndarray}, optional
432434
Output array to populate.
433435
Array must have the correct shape and the expected data type.
@@ -791,7 +793,7 @@ def convolve(a, v, mode="full"):
791793
return call_origin(numpy.convolve, a=a, v=v, mode=mode)
792794

793795

794-
_COPYSING_DOCSTRING = """
796+
_COPYSIGN_DOCSTRING = """
795797
Composes a floating-point value with the magnitude of `x1_i` and the sign of
796798
`x2_i` for each element of input arrays `x1` and `x2`.
797799
@@ -806,6 +808,8 @@ def convolve(a, v, mode="full"):
806808
Second input array, also expected to have a real floating-point data
807809
type.
808810
Both inputs `x1` and `x2` can not be scalars at the same time.
811+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
812+
(which becomes the shape of the output).
809813
out : {None, dpnp.ndarray, usm_ndarray}, optional
810814
Output array to populate.
811815
Array must have the correct shape and the expected data type.
@@ -852,7 +856,7 @@ def convolve(a, v, mode="full"):
852856
"copysign",
853857
ti._copysign_result_type,
854858
ti._copysign,
855-
_COPYSING_DOCSTRING,
859+
_COPYSIGN_DOCSTRING,
856860
)
857861

858862

@@ -1462,6 +1466,8 @@ def diff(a, n=1, axis=-1, prepend=None, append=None):
14621466
x2 : {dpnp.ndarray, usm_ndarray, scalar}
14631467
Second input array, also expected to have numeric data type.
14641468
Both inputs `x1` and `x2` can not be scalars at the same time.
1469+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1470+
(which becomes the shape of the output).
14651471
out : {None, dpnp.ndarray, usm_ndarray}, optional
14661472
Output array to populate.
14671473
Array must have the correct shape and the expected data type.
@@ -1759,6 +1765,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
17591765
x2 : {dpnp.ndarray, usm_ndarray, scalar}
17601766
Second input array, also expected to floating-point data types.
17611767
Both inputs `x1` and `x2` can not be scalars at the same time.
1768+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1769+
(which becomes the shape of the output).
17621770
out : {None, dpnp.ndarray, usm_ndarray}, optional
17631771
Output array to populate. Array must have the correct shape and
17641772
the expected data type.
@@ -1910,6 +1918,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
19101918
x2 : {dpnp.ndarray, usm_ndarray, scalar}
19111919
Second input array, also expected to have numeric data type.
19121920
Both inputs `x1` and `x2` can not be scalars at the same time.
1921+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1922+
(which becomes the shape of the output).
19131923
out : {None, dpnp.ndarray, usm_ndarray}, optional
19141924
Output array to populate.
19151925
Array must have the correct shape and the expected data type.
@@ -1984,6 +1994,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
19841994
x2 : {dpnp.ndarray, usm_ndarray, scalar}
19851995
Second input array, also expected to have numeric data type.
19861996
Both inputs `x1` and `x2` can not be scalars at the same time.
1997+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
1998+
(which becomes the shape of the output).
19871999
out : {None, dpnp.ndarray, usm_ndarray}, optional
19882000
Output array to populate.
19892001
Array must have the correct shape and the expected data type.
@@ -2069,6 +2081,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
20692081
x2 : {dpnp.ndarray, usm_ndarray, scalar}
20702082
Second input array, also expected to have numeric data type.
20712083
Both inputs `x1` and `x2` can not be scalars at the same time.
2084+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2085+
(which becomes the shape of the output).
20722086
out : {None, dpnp.ndarray, usm_ndarray}, optional
20732087
Output array to populate.
20742088
Array must have the correct shape and the expected data type.
@@ -2151,6 +2165,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
21512165
x2 : {dpnp.ndarray, usm_ndarray, scalar}
21522166
Second input array, also expected to have a real-valued data type.
21532167
Both inputs `x1` and `x2` can not be scalars at the same time.
2168+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2169+
(which becomes the shape of the output).
21542170
out : {None, dpnp.ndarray, usm_ndarray}, optional
21552171
Output array to populate.
21562172
Array must have the correct shape and the expected data type.
@@ -2220,8 +2236,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
22202236
x2 : {dpnp.ndarray, usm_ndarray, scalar}
22212237
Second input array, also expected to have an integer data type.
22222238
Both inputs `x1` and `x2` can not be scalars at the same time.
2223-
x : {dpnp.ndarray, usm_ndarray}
2224-
An array of floats to be rounded.
2239+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2240+
(which becomes the shape of the output).
22252241
out : {None, dpnp.ndarray, usm_ndarray}, optional
22262242
Output array to populate.
22272243
Array must have the correct shape and the expected data type.
@@ -2484,6 +2500,8 @@ def gradient(f, *varargs, axis=None, edge_order=1):
24842500
x2 : {dpnp.ndarray, usm_ndarray, scalar}
24852501
The value of the function when `x1` is ``0``.
24862502
Both inputs `x1` and `x2` can not be scalars at the same time.
2503+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2504+
(which becomes the shape of the output).
24872505
out : {None, dpnp.ndarray, usm_ndarray}, optional
24882506
Output array to populate.
24892507
Array must have the correct shape and the expected data type.
@@ -2636,6 +2654,8 @@ def gradient(f, *varargs, axis=None, edge_order=1):
26362654
x2 : {dpnp.ndarray, usm_ndarray, scalar}
26372655
Second input array, also expected to have an integer data type.
26382656
Both inputs `x1` and `x2` can not be scalars at the same time.
2657+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2658+
(which becomes the shape of the output).
26392659
out : {None, dpnp.ndarray, usm_ndarray}, optional
26402660
Output array to populate.
26412661
Array must have the correct shape and the expected data type.
@@ -2693,6 +2713,8 @@ def gradient(f, *varargs, axis=None, edge_order=1):
26932713
x2 : {dpnp.ndarray, usm_ndarray, scalar}
26942714
Array of exponents of two, expected to have an integer data type.
26952715
Both inputs `x1` and `x2` can not be scalars at the same time.
2716+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2717+
(which becomes the shape of the output).
26962718
out : {None, dpnp.ndarray, usm_ndarray}, optional
26972719
Output array to populate. Array must have the correct shape and
26982720
the expected data type.
@@ -2758,6 +2780,8 @@ def gradient(f, *varargs, axis=None, edge_order=1):
27582780
x2 : {dpnp.ndarray, usm_ndarray, scalar}
27592781
Second input array, also expected to have numeric data type.
27602782
Both inputs `x1` and `x2` can not be scalars at the same time.
2783+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2784+
(which becomes the shape of the output).
27612785
out : {None, dpnp.ndarray, usm_ndarray}, optional
27622786
Output array to populate.
27632787
Array must have the correct shape and the expected data type.
@@ -2838,6 +2862,8 @@ def gradient(f, *varargs, axis=None, edge_order=1):
28382862
x2 : {dpnp.ndarray, usm_ndarray, scalar}
28392863
Second input array, also expected to have numeric data type.
28402864
Both inputs `x1` and `x2` can not be scalars at the same time.
2865+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2866+
(which becomes the shape of the output).s
28412867
out : {None, dpnp.ndarray, usm_ndarray}, optional
28422868
Output array to populate.
28432869
Array must have the correct shape and the expected data type.
@@ -2943,6 +2969,8 @@ def modf(x1, **kwargs):
29432969
x2 : {dpnp.ndarray, usm_ndarray, scalar}
29442970
Second input array, also expected to have numeric data type.
29452971
Both inputs `x1` and `x2` can not be scalars at the same time.
2972+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
2973+
(which becomes the shape of the output).
29462974
out : {None, dpnp.ndarray, usm_ndarray}, optional
29472975
Output array to populate.
29482976
Array must have the correct shape and the expected data type.
@@ -3205,6 +3233,8 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
32053233
x2 : {dpnp.ndarray, usm_ndarray, scalar}
32063234
The direction where to look for the next representable value of `x1`.
32073235
Both inputs `x1` and `x2` can not be scalars at the same time.
3236+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
3237+
(which becomes the shape of the output).
32083238
out : {None, dpnp.ndarray, usm_ndarray}, optional
32093239
Output array to populate. Array must have the correct shape and
32103240
the expected data type.
@@ -3326,6 +3356,8 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
33263356
x2 : {dpnp.ndarray, usm_ndarray, scalar}
33273357
Second input array, also expected to have numeric data type.
33283358
Both inputs `x1` and `x2` can not be scalars at the same time.
3359+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
3360+
(which becomes the shape of the output).
33293361
out : {None, dpnp.ndarray, usm_ndarray}, optional
33303362
Output array to populate. Array must have the correct shape and
33313363
the expected data type.
@@ -3688,6 +3720,8 @@ def real_if_close(a, tol=100):
36883720
x2 : {dpnp.ndarray, usm_ndarray, scalar}
36893721
Second input array, also expected to have a real-valued data type.
36903722
Both inputs `x1` and `x2` can not be scalars at the same time.
3723+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
3724+
(which becomes the shape of the output).
36913725
out : {None, dpnp.ndarray, usm_ndarray}, optional
36923726
Output array to populate.
36933727
Array must have the correct shape and the expected data type.
@@ -4114,6 +4148,8 @@ def real_if_close(a, tol=100):
41144148
x2 : {dpnp.ndarray, usm_ndarray, scalar}
41154149
Second input array, also expected to have numeric data type.
41164150
Both inputs `x1` and `x2` can not be scalars at the same time.
4151+
If ``x1.shape != x2.shape``, they must be broadcastable to a common shape
4152+
(which becomes the shape of the output).
41174153
out : {None, dpnp.ndarray, usm_ndarray}, optional
41184154
Output array to populate.
41194155
Array must have the correct shape and the expected data type.

0 commit comments

Comments
 (0)