Skip to content

Commit 77b8529

Browse files
committed
Return NotImplemented when non-default mod is passed to __pow__ and __rpow__
1 parent 649f01f commit 77b8529

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

dpnp/dpnp_array.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ def __pos__(self, /):
480480

481481
def __pow__(self, other, mod=None, /):
482482
r"""Return :math:`\text{self ** value}`."""
483+
if mod is not None:
484+
return NotImplemented
483485
return dpnp.power(self, other)
484486

485487
def __radd__(self, other, /):
@@ -524,6 +526,8 @@ def __ror__(self, other, /):
524526

525527
def __rpow__(self, other, mod=None, /):
526528
r"""Return :math:`\text{value ** self}`."""
529+
if mod is not None:
530+
return NotImplemented
527531
return dpnp.power(other, self)
528532

529533
def __rrshift__(self, other, /):

dpnp/tests/test_ndarray.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,15 @@ def test_rmatmul_numpy_array():
550550

551551
with pytest.raises(TypeError):
552552
b @ a
553+
554+
555+
@pytest.mark.parametrize("xp", [dpnp, numpy])
556+
def test_pow_modulo(xp):
557+
a = xp.array([2, 3, 4])
558+
b = xp.array([5, 2, 3])
559+
560+
assert a.__pow__(b, 10) == NotImplemented
561+
assert a.__rpow__(b, 10) == NotImplemented
562+
563+
assert (a.__pow__(b, None) == a**b).all()
564+
assert (a.__rpow__(b, None) == b**a).all()

0 commit comments

Comments
 (0)