Skip to content

Commit 5cde31b

Browse files
committed
BUG: one to any power is still 1. Broken edgecase for int arrays
Fixes numpygh-7648.
1 parent cd96464 commit 5cde31b

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎numpy/core/src/umath/loops.c.src‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,10 @@ NPY_NO_EXPORT void
921921
*((@type@ *)op1) = 1;
922922
continue;
923923
}
924+
if (in1 == 1) {
925+
*((@type@ *)op1) = 1;
926+
continue;
927+
}
924928
if (in2 < 0 || in1 == 0) {
925929
*((@type@ *)op1) = 0;
926930
continue;

‎numpy/core/tests/test_umath.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ def test_integer_power_with_zero_exponent(self):
434434
arr = np.arange(-10, 10)
435435
assert_equal(np.power(arr, 0), np.ones_like(arr))
436436

437+
def test_integer_power_of_1(self):
438+
arr = np.arange(-10, 10)
439+
assert_equal(np.power(1, arr), np.ones_like(arr))
440+
437441

438442
class TestLog2(TestCase):
439443
def test_log2_values(self):

0 commit comments

Comments
 (0)