From 5cde31bad1b1e698010fa2801255b5bd8ba3de90 Mon Sep 17 00:00:00 2001 From: Eric Moore Date: Thu, 19 May 2016 15:40:30 -0400 Subject: [PATCH] BUG: one to any power is still 1. Broken edgecase for int arrays Fixes gh-7648. --- numpy/core/src/umath/loops.c.src | 4 ++++ numpy/core/tests/test_umath.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 6f0dee123bcc..157b30e70964 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -921,6 +921,10 @@ NPY_NO_EXPORT void *((@type@ *)op1) = 1; continue; } + if (in1 == 1) { + *((@type@ *)op1) = 1; + continue; + } if (in2 < 0 || in1 == 0) { *((@type@ *)op1) = 0; continue; diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index f2f94d7bf3a6..759e996e31bb 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -434,6 +434,10 @@ def test_integer_power_with_zero_exponent(self): arr = np.arange(-10, 10) assert_equal(np.power(arr, 0), np.ones_like(arr)) + def test_integer_power_of_1(self): + arr = np.arange(-10, 10) + assert_equal(np.power(1, arr), np.ones_like(arr)) + class TestLog2(TestCase): def test_log2_values(self):