Skip to content

Commit a78ae52

Browse files
authored
implement dpnp.rint (#1537)
* implement dpnp.int * address comments
1 parent 1595ab7 commit a78ae52

File tree

8 files changed

+134
-46
lines changed

8 files changed

+134
-46
lines changed

dpnp/dpnp_iface_logic.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ def all(x, /, axis=None, out=None, keepdims=False, *, where=True):
9494
9595
Returns
9696
-------
97-
dpnp.ndarray
98-
An array with a data type of `bool`
99-
containing the results of the logical AND reduction.
97+
out : dpnp.ndarray
98+
An array with a data type of `bool`
99+
containing the results of the logical AND reduction.
100100
101101
Limitations
102102
-----------
@@ -198,7 +198,7 @@ def any(x, /, axis=None, out=None, keepdims=False, *, where=True):
198198
199199
Returns
200200
-------
201-
dpnp.ndarray
201+
out : dpnp.ndarray
202202
An array with a data type of `bool`
203203
containing the results of the logical OR reduction.
204204
@@ -276,7 +276,7 @@ def equal(
276276
Returns
277277
-------
278278
out : dpnp.ndarray
279-
Output array of bool type, element-wise comparison of `x1` and `x2`.
279+
Output array of bool type, element-wise comparison of `x1` and `x2`.
280280
281281
Limitations
282282
-----------
@@ -352,7 +352,7 @@ def greater(
352352
Returns
353353
-------
354354
out : dpnp.ndarray
355-
Output array of bool type, element-wise comparison of `x1` and `x2`.
355+
Output array of bool type, element-wise comparison of `x1` and `x2`.
356356
357357
Limitations
358358
-----------
@@ -422,7 +422,7 @@ def greater_equal(
422422
Returns
423423
-------
424424
out : dpnp.ndarray
425-
Output array of bool type, element-wise comparison of `x1` and `x2`.
425+
Output array of bool type, element-wise comparison of `x1` and `x2`.
426426
427427
Limitations
428428
-----------
@@ -678,7 +678,7 @@ def less(
678678
Returns
679679
-------
680680
out : dpnp.ndarray
681-
Output array of bool type, element-wise comparison of `x1` and `x2`.
681+
Output array of bool type, element-wise comparison of `x1` and `x2`.
682682
683683
Limitations
684684
-----------
@@ -748,7 +748,7 @@ def less_equal(
748748
Returns
749749
-------
750750
out : dpnp.ndarray
751-
Output array of bool type, element-wise comparison of `x1` and `x2`.
751+
Output array of bool type, element-wise comparison of `x1` and `x2`.
752752
753753
Limitations
754754
-----------
@@ -818,8 +818,8 @@ def logical_and(
818818
Returns
819819
-------
820820
out : dpnp.ndarray
821-
Boolean result of the logical AND operation applied to the elements
822-
of `x1` and `x2`; the shape is determined by broadcasting.
821+
Boolean result of the logical AND operation applied to the elements
822+
of `x1` and `x2`; the shape is determined by broadcasting.
823823
824824
Limitations
825825
-----------
@@ -891,8 +891,8 @@ def logical_not(
891891
Returns
892892
-------
893893
out : dpnp.ndarray
894-
Boolean result with the same shape as `x` of the NOT operation
895-
on elements of `x`.
894+
Boolean result with the same shape as `x` of the NOT operation
895+
on elements of `x`.
896896
897897
Limitations
898898
-----------
@@ -953,8 +953,8 @@ def logical_or(
953953
Returns
954954
-------
955955
out : dpnp.ndarray
956-
Boolean result of the logical OR operation applied to the elements
957-
of `x1` and `x2`; the shape is determined by broadcasting.
956+
Boolean result of the logical OR operation applied to the elements
957+
of `x1` and `x2`; the shape is determined by broadcasting.
958958
959959
Limitations
960960
-----------
@@ -1027,8 +1027,8 @@ def logical_xor(
10271027
Returns
10281028
-------
10291029
out : dpnp.ndarray
1030-
Boolean result of the logical XOR operation applied to the elements
1031-
of `x1` and `x2`; the shape is determined by broadcasting.
1030+
Boolean result of the logical XOR operation applied to the elements
1031+
of `x1` and `x2`; the shape is determined by broadcasting.
10321032
10331033
Limitations
10341034
-----------

dpnp/dpnp_iface_mathematical.py

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"power",
103103
"prod",
104104
"remainder",
105+
"rint",
105106
"round",
106107
"sign",
107108
"subtract",
@@ -145,7 +146,7 @@ def absolute(x, /, out=None, *, where=True, dtype=None, subok=True, **kwargs):
145146
146147
Returns
147148
-------
148-
y : dpnp.ndarray
149+
out : dpnp.ndarray
149150
An array containing the absolute value of each element in `x`.
150151
151152
Limitations
@@ -219,7 +220,7 @@ def add(
219220
220221
Returns
221222
-------
222-
y : dpnp.ndarray
223+
out : dpnp.ndarray
223224
The sum of `x1` and `x2`, element-wise.
224225
225226
Limitations
@@ -275,6 +276,11 @@ def around(x, /, decimals=0, out=None):
275276
276277
For full documentation refer to :obj:`numpy.around`.
277278
279+
Returns
280+
-------
281+
out : dpnp.ndarray
282+
The rounded value of elements of the array.
283+
278284
Limitations
279285
-----------
280286
Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
@@ -284,7 +290,9 @@ def around(x, /, decimals=0, out=None):
284290
285291
See Also
286292
--------
287-
:obj:`dpnp.round` : equivalent function; see for details.
293+
:obj:`dpnp.round` : Equivalent function; see for details.
294+
:obj:`dpnp.ndarray.round` : Equivalent function.
295+
:obj:`dpnp.rint` : Round elements of the array to the nearest integer.
288296
:obj:`dpnp.ceil` : Compute the ceiling of the input, element-wise.
289297
:obj:`dpnp.floor` : Return the floor of the input, element-wise.
290298
:obj:`dpnp.trunc` : Return the truncated value of the input, element-wise.
@@ -659,7 +667,7 @@ def divide(
659667
660668
Returns
661669
-------
662-
y : dpnp.ndarray
670+
out : dpnp.ndarray
663671
The quotient `x1/x2`, element-wise.
664672
665673
Limitations
@@ -865,6 +873,11 @@ def floor_divide(
865873
866874
For full documentation refer to :obj:`numpy.floor_divide`.
867875
876+
Returns
877+
-------
878+
out : dpnp.ndarray
879+
The floordivide of each element of `x`.
880+
868881
Limitations
869882
-----------
870883
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
@@ -1215,6 +1228,11 @@ def mod(
12151228
12161229
For full documentation refer to :obj:`numpy.mod`.
12171230
1231+
Returns
1232+
-------
1233+
out : dpnp.ndarray
1234+
The element-wise remainder of the quotient `floor_divide(x1, x2)`.
1235+
12181236
Limitations
12191237
-----------
12201238
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
@@ -1298,7 +1316,7 @@ def multiply(
12981316
12991317
Returns
13001318
-------
1301-
y : {dpnp.ndarray, scalar}
1319+
out : {dpnp.ndarray, scalar}
13021320
The product of `x1` and `x2`, element-wise.
13031321
13041322
Limitations
@@ -1503,7 +1521,7 @@ def negative(
15031521
Returns
15041522
-------
15051523
out : dpnp.ndarray
1506-
The numerical negative of each element of `x`.
1524+
The numerical negative of each element of `x`.
15071525
15081526
Limitations
15091527
-----------
@@ -1555,7 +1573,7 @@ def power(x1, x2, /, out=None, *, where=True, dtype=None, subok=True, **kwargs):
15551573
15561574
Returns
15571575
-------
1558-
y : dpnp.ndarray
1576+
out : dpnp.ndarray
15591577
The bases in `x1` raised to the exponents in `x2`.
15601578
15611579
Limitations
@@ -1702,6 +1720,64 @@ def prod(
17021720
)
17031721

17041722

1723+
def rint(
1724+
x,
1725+
/,
1726+
out=None,
1727+
*,
1728+
order="K",
1729+
where=True,
1730+
dtype=None,
1731+
subok=True,
1732+
**kwargs,
1733+
):
1734+
"""
1735+
Round elements of the array to the nearest integer.
1736+
1737+
For full documentation refer to :obj:`numpy.rint`.
1738+
1739+
Returns
1740+
-------
1741+
out : dpnp.ndarray
1742+
The rounded value of elements of the array to the nearest integer.
1743+
1744+
Limitations
1745+
-----------
1746+
Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
1747+
Parameters `where`, `dtype` and `subok` are supported with their default values.
1748+
Keyword argument `kwargs` is currently unsupported.
1749+
Otherwise the function will be executed sequentially on CPU.
1750+
Input array data types are limited by supported DPNP :ref:`Data types`.
1751+
1752+
See Also
1753+
--------
1754+
:obj:`dpnp.round` : Evenly round to the given number of decimals.
1755+
:obj:`dpnp.ceil` : Compute the ceiling of the input, element-wise.
1756+
:obj:`dpnp.floor` : Return the floor of the input, element-wise.
1757+
:obj:`dpnp.trunc` : Return the truncated value of the input, element-wise.
1758+
1759+
Examples
1760+
--------
1761+
>>> import dpnp as np
1762+
>>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0])
1763+
>>> np.rint(a)
1764+
array([-2., -2., -0., 0., 2., 2., 2.])
1765+
1766+
"""
1767+
1768+
return check_nd_call_func(
1769+
numpy.rint,
1770+
dpnp_round,
1771+
x,
1772+
out=out,
1773+
where=where,
1774+
order=order,
1775+
dtype=dtype,
1776+
subok=subok,
1777+
**kwargs,
1778+
)
1779+
1780+
17051781
def remainder(
17061782
x1,
17071783
x2,
@@ -1719,6 +1795,11 @@ def remainder(
17191795
17201796
For full documentation refer to :obj:`numpy.remainder`.
17211797
1798+
Returns
1799+
-------
1800+
out : dpnp.ndarray
1801+
The element-wise remainder of the quotient `floor_divide(x1, x2)`.
1802+
17221803
Limitations
17231804
-----------
17241805
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
@@ -1773,6 +1854,11 @@ def round(x, decimals=0, out=None):
17731854
17741855
For full documentation refer to :obj:`numpy.round`.
17751856
1857+
Returns
1858+
-------
1859+
out : dpnp.ndarray
1860+
The rounded value of elements of the array.
1861+
17761862
Limitations
17771863
-----------
17781864
Parameter `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
@@ -1782,7 +1868,9 @@ def round(x, decimals=0, out=None):
17821868
17831869
See Also
17841870
--------
1785-
:obj:`dpnp.around` : equivalent function; see for details.
1871+
:obj:`dpnp.around` : Equivalent function; see for details.
1872+
:obj:`dpnp.ndarray.round` : Equivalent function.
1873+
:obj:`dpnp.rint` : Round elements of the array to the nearest integer.
17861874
:obj:`dpnp.ceil` : Compute the ceiling of the input, element-wise.
17871875
:obj:`dpnp.floor` : Return the floor of the input, element-wise.
17881876
:obj:`dpnp.trunc` : Return the truncated value of the input, element-wise.
@@ -1832,7 +1920,7 @@ def sign(
18321920
Returns
18331921
-------
18341922
out : dpnp.ndarray
1835-
The indication of the sign of each element of `x`.
1923+
The indication of the sign of each element of `x`.
18361924
18371925
Limitations
18381926
-----------
@@ -1899,7 +1987,7 @@ def subtract(
18991987
19001988
Returns
19011989
-------
1902-
y : dpnp.ndarray
1990+
out : dpnp.ndarray
19031991
The difference of `x1` and `x2`, element-wise.
19041992
19051993
Limitations
@@ -1965,7 +2053,7 @@ def sum(
19652053
19662054
Returns
19672055
-------
1968-
y : dpnp.ndarray
2056+
out : dpnp.ndarray
19692057
an array containing the sums. If the sum was computed over the
19702058
entire array, a zero-dimensional array is returned. The returned
19712059
array has the data type as described in the `dtype` parameter
@@ -2134,7 +2222,6 @@ def true_divide(*args, **kwargs):
21342222
-----
21352223
This function works the same as :obj:`dpnp.divide`.
21362224
2137-
21382225
"""
21392226

21402227
return dpnp.divide(*args, **kwargs)

dpnp/dpnp_iface_trigonometric.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def cos(
429429
430430
Returns
431431
-------
432-
y : dpnp.ndarray
432+
out : dpnp.ndarray
433433
The cosine of each element of `x`.
434434
435435
Limitations
@@ -738,7 +738,7 @@ def log(
738738
739739
Returns
740740
-------
741-
y : dpnp.ndarray
741+
out : dpnp.ndarray
742742
The natural logarithm of `x`, element-wise.
743743
744744
Limitations
@@ -982,7 +982,7 @@ def sin(
982982
983983
Returns
984984
-------
985-
y : dpnp.ndarray
985+
out : dpnp.ndarray
986986
The sine of each element of `x`.
987987
988988
Limitations
@@ -1069,7 +1069,7 @@ def sqrt(
10691069
10701070
Returns
10711071
-------
1072-
y : dpnp.ndarray
1072+
out : dpnp.ndarray
10731073
An array of the same shape as `x`, containing the positive
10741074
square-root of each element in `x`. If any element in `x` is
10751075
complex, a complex array is returned (and the square-roots of
@@ -1129,7 +1129,7 @@ def square(
11291129
11301130
Returns
11311131
-------
1132-
y : dpnp.ndarray
1132+
out : dpnp.ndarray
11331133
Element-wise `x * x`, of the same shape and dtype as `x`.
11341134
11351135
Limitations

0 commit comments

Comments
 (0)