Skip to content

Commit 56219eb

Browse files
committed
address comments
1 parent ffeb0ae commit 56219eb

File tree

4 files changed

+56
-35
lines changed

4 files changed

+56
-35
lines changed

dpnp/dpnp_array.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ def __eq__(self, other):
188188
def __float__(self):
189189
return self._array_obj.__float__()
190190

191-
# '__floordiv__',
191+
def __floordiv__(self, other):
192+
"""Return self//value."""
193+
return dpnp.floor_divide(self, other)
194+
192195
# '__format__',
193196

194197
def __ge__(self, other):
@@ -227,15 +230,22 @@ def __iand__(self, other):
227230
dpnp.bitwise_and(self, other, out=self)
228231
return self
229232

230-
# '__ifloordiv__',
233+
def __ifloordiv__(self, other):
234+
"""Return self//=value."""
235+
dpnp.floor_divide(self, other, out=self)
236+
return self
231237

232238
def __ilshift__(self, other):
233239
"""Return self<<=value."""
234240
dpnp.left_shift(self, other, out=self)
235241
return self
236242

237243
# '__imatmul__',
238-
# '__imod__',
244+
245+
def __imod__(self, other):
246+
"""Return self%=value."""
247+
dpnp.remainder(self, other, out=self)
248+
return self
239249

240250
def __imul__(self, other):
241251
"""Return self*=value."""
@@ -345,7 +355,8 @@ def __rand__(self, other):
345355
def __repr__(self):
346356
return dpt.usm_ndarray_repr(self._array_obj, prefix="array")
347357

348-
# '__rfloordiv__',
358+
def __rfloordiv__(self, other):
359+
return dpnp.floor_divide(self, other)
349360

350361
def __rlshift__(self, other):
351362
return dpnp.left_shift(other, self)

dpnp/dpnp_iface_mathematical.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,14 @@ def floor_divide(
901901
902902
>>> np.floor_divide(np.array([1., 2., 3., 4.]), 2.5)
903903
array([ 0., 0., 1., 1.])
904+
905+
The ``//`` operator can be used as a shorthand for ``floor_divide`` on
906+
:class:`dpnp.ndarray`.
907+
908+
>>> x1 = np.array([1., 2., 3., 4.])
909+
>>> x1 // 2.5
910+
array([0., 0., 1., 1.])
911+
904912
"""
905913

906914
return check_nd_call_func(

tests/test_mathematical.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def test_nancumsum(array):
392392
[[[1.0, -1.0], [0.1, -0.1]], [-2, -1, 0, 1, 2]],
393393
ids=["[[1., -1.], [0.1, -0.1]]", "[-2, -1, 0, 1, 2]"],
394394
)
395-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
395+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
396396
def test_negative(data, dtype):
397397
np_a = numpy.array(data, dtype=dtype)
398398
dpnp_a = dpnp.array(data, dtype=dtype)
@@ -402,36 +402,6 @@ def test_negative(data, dtype):
402402
assert_allclose(result, expected)
403403

404404

405-
def test_negative_boolean():
406-
dpnp_a = dpnp.array([True, False])
407-
408-
with pytest.raises(TypeError):
409-
dpnp.negative(dpnp_a)
410-
411-
412-
@pytest.mark.parametrize(
413-
"data",
414-
[[2, 0, -2], [1.1, -1.1]],
415-
ids=["[2, 0, -2]", "[1.1, -1.1]"],
416-
)
417-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
418-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
419-
def test_sign(data, dtype):
420-
np_a = numpy.array(data, dtype=dtype)
421-
dpnp_a = dpnp.array(data, dtype=dtype)
422-
423-
result = dpnp.sign(dpnp_a)
424-
expected = numpy.sign(np_a)
425-
assert_allclose(result, expected)
426-
427-
428-
def test_sign_boolean():
429-
dpnp_a = dpnp.array([True, False])
430-
431-
with pytest.raises(TypeError):
432-
dpnp.sign(dpnp_a)
433-
434-
435405
@pytest.mark.parametrize("val_type", get_all_dtypes(no_none=True))
436406
@pytest.mark.parametrize("data_type", get_all_dtypes())
437407
@pytest.mark.parametrize("val", [1.5, 1, 5], ids=["1.5", "1", "5"])
@@ -1177,3 +1147,31 @@ def test_mean_scalar(self):
11771147
result = dp_array.mean()
11781148
expected = np_array.mean()
11791149
assert_allclose(expected, result)
1150+
1151+
1152+
@pytest.mark.parametrize(
1153+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
1154+
)
1155+
def test_inplace_remainder(dtype):
1156+
size = 21
1157+
np_a = numpy.arange(size, dtype=dtype)
1158+
dp_a = dpnp.arange(size, dtype=dtype)
1159+
1160+
np_a %= 4
1161+
dp_a %= 4
1162+
1163+
assert_allclose(dp_a, np_a)
1164+
1165+
1166+
@pytest.mark.parametrize(
1167+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
1168+
)
1169+
def test_inplace_floor_divide(dtype):
1170+
size = 21
1171+
np_a = numpy.arange(size, dtype=dtype)
1172+
dp_a = dpnp.arange(size, dtype=dtype)
1173+
1174+
np_a //= 4
1175+
dp_a //= 4
1176+
1177+
assert_allclose(dp_a, np_a)

tests/test_usm_type.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def test_coerced_usm_types_remainder(usm_type_x, usm_type_y):
8585

8686
z = x % y
8787

88+
# inplace remainder
89+
z %= y
90+
z %= 5
91+
8892
assert x.usm_type == usm_type_x
8993
assert y.usm_type == usm_type_y
9094
assert z.usm_type == du.get_coerced_usm_type([usm_type_x, usm_type_y])

0 commit comments

Comments
 (0)