Skip to content

Commit aac66a6

Browse files
committed
address comments
1 parent ffeb0ae commit aac66a6

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,3 +1177,31 @@ def test_mean_scalar(self):
11771177
result = dp_array.mean()
11781178
expected = np_array.mean()
11791179
assert_allclose(expected, result)
1180+
1181+
1182+
@pytest.mark.parametrize(
1183+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
1184+
)
1185+
def test_inplace_remainder(dtype):
1186+
size = 21
1187+
np_a = numpy.arange(size, dtype=dtype)
1188+
dp_a = dpnp.arange(size, dtype=dtype)
1189+
1190+
np_a %= 4
1191+
dp_a %= 4
1192+
1193+
assert_allclose(dp_a, np_a)
1194+
1195+
1196+
@pytest.mark.parametrize(
1197+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
1198+
)
1199+
def test_inplace_floor_divide(dtype):
1200+
size = 21
1201+
np_a = numpy.arange(size, dtype=dtype)
1202+
dp_a = dpnp.arange(size, dtype=dtype)
1203+
1204+
np_a //= 4
1205+
dp_a //= 4
1206+
1207+
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)