Skip to content

Commit 6c461cc

Browse files
committed
address reviewer's comments
1 parent 1ed5053 commit 6c461cc

File tree

5 files changed

+90
-36
lines changed

5 files changed

+90
-36
lines changed

dpnp/dpnp_iface_mathematical.py

+51-20
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def add(
220220
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
221221
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
222222
Parameters `where`, `dtype` and `subok` are supported with their default values.
223-
Keyword arguments ``kwargs`` are currently unsupported.
223+
Keyword arguments `kwargs` are currently unsupported.
224224
Otherwise the function will be executed sequentially on CPU.
225225
Input array data types are limited by supported DPNP :ref:`Data types`.
226226
@@ -626,14 +626,14 @@ def divide(
626626
Returns
627627
-------
628628
y : dpnp.ndarray
629-
The quotient ``x1/x2``, element-wise.
629+
The quotient `x1/x2`, element-wise.
630630
631631
Limitations
632632
-----------
633633
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
634634
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
635-
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
636-
Keyword arguments ``kwargs`` are currently unsupported.
635+
Parameters `where`, `dtype` and `subok` are supported with their default values.
636+
Keyword arguments `kwargs` are currently unsupported.
637637
Otherwise the function will be executed sequentially on CPU.
638638
Input array data types are limited by supported DPNP :ref:`Data types`.
639639
@@ -823,7 +823,7 @@ def floor_divide(
823823
824824
See Also
825825
--------
826-
:obj:`dpnp.reminder` : Remainder complementary to floor_divide.
826+
:obj:`dpnp.remainder` : Remainder complementary to floor_divide.
827827
:obj:`dpnp.divide` : Standard division.
828828
:obj:`dpnp.floor` : Round a number to the nearest integer toward minus infinity.
829829
:obj:`dpnp.ceil` : Round a number to the nearest integer toward infinity.
@@ -910,7 +910,7 @@ def fmod(x1, x2, dtype=None, out=None, where=True, **kwargs):
910910
911911
See Also
912912
--------
913-
:obj:`dpnp.reminder` : Remainder complementary to floor_divide.
913+
:obj:`dpnp.remainder` : Remainder complementary to floor_divide.
914914
:obj:`dpnp.divide` : Standard division.
915915
916916
Examples
@@ -1137,16 +1137,36 @@ def minimum(x1, x2, dtype=None, out=None, where=True, **kwargs):
11371137
)
11381138

11391139

1140-
def mod(*args, **kwargs):
1140+
def mod(
1141+
x1,
1142+
x2,
1143+
/,
1144+
out=None,
1145+
*,
1146+
where=True,
1147+
order="K",
1148+
dtype=None,
1149+
subok=True,
1150+
**kwargs,
1151+
):
11411152
"""
11421153
Compute element-wise remainder of division.
11431154
11441155
For full documentation refer to :obj:`numpy.mod`.
11451156
1157+
Limitations
1158+
-----------
1159+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
1160+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
1161+
Parameters `where`, `dtype` and `subok` are supported with their default values.
1162+
Keyword arguments `kwargs` are currently unsupported.
1163+
Otherwise the function will be executed sequentially on CPU.
1164+
Input array data types are limited by supported DPNP :ref:`Data types`.
1165+
11461166
See Also
11471167
--------
11481168
:obj:`dpnp.fmod` : Calculate the element-wise remainder of division
1149-
:obj:`dpnp.reminder` : Remainder complementary to floor_divide.
1169+
:obj:`dpnp.remainder` : Remainder complementary to floor_divide.
11501170
:obj:`dpnp.divide` : Standard division.
11511171
11521172
Notes
@@ -1155,7 +1175,16 @@ def mod(*args, **kwargs):
11551175
11561176
"""
11571177

1158-
return dpnp.remainder(*args, **kwargs)
1178+
return dpnp.remainder(
1179+
x1,
1180+
x2,
1181+
out=out,
1182+
where=where,
1183+
order=order,
1184+
dtype=dtype,
1185+
subok=subok,
1186+
**kwargs,
1187+
)
11591188

11601189

11611190
def modf(x1, **kwargs):
@@ -1602,18 +1631,20 @@ def remainder(
16021631
16031632
Limitations
16041633
-----------
1605-
Parameters ``x1`` and ``x2`` are supported as either :obj:`dpnp.ndarray`,
1606-
:class:`dpctl.tensor.usm_ndarray` or scalar.
1607-
Parameters `where`, `dtype` and `subok` are supported with their default values.
1608-
Keyword arguments `kwargs` are currently unsupported.
1609-
Otherwise the functions will be executed sequentially on CPU.
1610-
Input array data types are limited by supported DPNP :ref:`Data types`.
1634+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
1635+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
1636+
Parameters `where`, `dtype` and `subok` are supported with their default values.
1637+
Keyword arguments `kwargs` are currently unsupported.
1638+
Otherwise the function will be executed sequentially on CPU.
1639+
Input array data types are limited by supported DPNP :ref:`Data types`.
16111640
16121641
See Also
16131642
--------
1614-
:obj:`dpnp.fmod` : Calculate the element-wise remainder of division.
1615-
:obj:`dpnp.divide` : Standard division.
1616-
:obj:`dpnp.floor` : Round a number to the nearest integer toward minus infinity.
1643+
:obj:`dpnp.fmod` : Calculate the element-wise remainder of division.
1644+
:obj:`dpnp.divide` : Standard division.
1645+
:obj:`dpnp.floor` : Round a number to the nearest integer toward minus infinity.
1646+
:obj:`dpnp.floor_divide` : Compute the largest integer smaller or equal to the division of the inputs.
1647+
:obj:`dpnp.mod` : Calculate the element-wise remainder of division.
16171648
16181649
Example
16191650
-------
@@ -1718,8 +1749,8 @@ def subtract(
17181749
-----------
17191750
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
17201751
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
1721-
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
1722-
Keyword arguments ``kwargs`` are currently unsupported.
1752+
Parameters `where`, `dtype` and `subok` are supported with their default values.
1753+
Keyword arguments `kwargs` are currently unsupported.
17231754
Otherwise the function will be executed sequentially on CPU.
17241755
Input array data types are limited by supported DPNP :ref:`Data types`.
17251756

tests/test_mathematical.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ def _test_mathematical(self, name, dtype, lhs, rhs):
136136
else:
137137
result = getattr(dpnp, name)(a_dpnp, b_dpnp)
138138
expected = getattr(numpy, name)(a_np, b_np)
139+
if (
140+
name == "remainder"
141+
and result.dtype != expected.dtype
142+
and not has_support_aspect64()
143+
):
144+
pytest.skip("skipping since output is promoted differently")
139145
assert_allclose(result, expected, rtol=1e-6)
140146

141147
@pytest.mark.parametrize("dtype", get_all_dtypes())
@@ -210,9 +216,7 @@ def test_minimum(self, dtype, lhs, rhs):
210216
def test_multiply(self, dtype, lhs, rhs):
211217
self._test_mathematical("multiply", dtype, lhs, rhs)
212218

213-
@pytest.mark.parametrize(
214-
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
215-
)
219+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_complex=True))
216220
def test_remainder(self, dtype, lhs, rhs):
217221
self._test_mathematical("remainder", dtype, lhs, rhs)
218222

tests/test_strides.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,30 @@ def test_strides_fmod(dtype, shape):
233233

234234
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
235235
@pytest.mark.parametrize("shape", [(3, 3)], ids=["(3, 3)"])
236-
def test_strides_true_devide(dtype, shape):
236+
def test_strides_true_divide(dtype, shape):
237237
a = numpy.arange(numpy.prod(shape), dtype=dtype).reshape(shape)
238238
b = a.T + 1
239239

240240
dpa = dpnp.reshape(dpnp.arange(numpy.prod(shape), dtype=dtype), shape)
241241
dpb = dpa.T + 1
242242

243-
result = dpnp.fmod(dpa, dpb)
244-
expected = numpy.fmod(a, b)
243+
result = dpnp.true_divide(dpa, dpb)
244+
expected = numpy.true_divide(a, b)
245+
246+
assert_allclose(result, expected, atol=1e-08)
247+
248+
249+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
250+
@pytest.mark.parametrize("shape", [(3, 3)], ids=["(3, 3)"])
251+
def test_strides_remainder(dtype, shape):
252+
a = numpy.arange(numpy.prod(shape), dtype=dtype).reshape(shape)
253+
b = a.T + 1
254+
255+
dpa = dpnp.reshape(dpnp.arange(numpy.prod(shape), dtype=dtype), shape)
256+
dpb = dpa.T + 1
257+
258+
result = dpnp.remainder(dpa, dpb)
259+
expected = numpy.remainder(a, b)
245260

246261
assert_allclose(result, expected)
247262

tests/test_usm_type.py

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ def test_coerced_usm_types_divide(usm_type_x, usm_type_y):
7474
assert z.usm_type == du.get_coerced_usm_type([usm_type_x, usm_type_y])
7575

7676

77+
@pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
78+
@pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types)
79+
def test_coerced_usm_types_remainder(usm_type_x, usm_type_y):
80+
x = dp.arange(100, usm_type=usm_type_x).reshape(10, 10)
81+
y = dp.arange(100, usm_type=usm_type_y).reshape(10, 10)
82+
y = y.T + 1
83+
84+
z = x % y
85+
86+
assert x.usm_type == usm_type_x
87+
assert y.usm_type == usm_type_y
88+
assert z.usm_type == du.get_coerced_usm_type([usm_type_x, usm_type_y])
89+
90+
7791
@pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
7892
@pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types)
7993
def test_coerced_usm_types_power(usm_type_x, usm_type_y):

tests/third_party/cupy/math_tests/test_arithmetic.py

-10
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,6 @@ def check_binary(self, xp):
199199
elif is_array_arg2 and not is_array_arg1:
200200
y = y.astype(dtype2)
201201

202-
# NumPy returns different values (nan/inf) on division by zero
203-
# depending on the architecture.
204-
# As it is not possible for CuPy to replicate this behavior, we ignore
205-
# the difference here.
206-
# if self.name in ('floor_divide', 'remainder', 'mod'):
207-
# if y.dtype in (float_types + complex_types) and (np2 == 0).any():
208-
# y = xp.asarray(y)
209-
# y[y == numpy.inf] = numpy.nan
210-
# y[y == -numpy.inf] = numpy.nan
211-
212202
return y
213203

214204

0 commit comments

Comments
 (0)