diff options
author | Loïc Estève <loic.esteve@ymail.com> | 2016-04-05 16:31:51 +0200 |
---|---|---|
committer | Loïc Estève <loic.esteve@ymail.com> | 2016-04-05 16:31:57 +0200 |
commit | 307931d804fde05ed0281c9bbb9d522a682f2762 (patch) | |
tree | cde740e8a3ec9151097735f98e89b8fda141e7cc | |
parent | 9c59de6e5771174dec5487a25d7594e4021669d6 (diff) | |
download | numpy-307931d804fde05ed0281c9bbb9d522a682f2762.tar.gz |
numpy.power(0, 0) should return 1
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index a829e4104..6f0dee123 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -917,14 +917,14 @@ NPY_NO_EXPORT void @type@ in2 = *(@type@ *)ip2; @type@ out; + if (in2 == 0) { + *((@type@ *)op1) = 1; + continue; + } if (in2 < 0 || in1 == 0) { *((@type@ *)op1) = 0; continue; } - if (in2 == 0) { - *((@type@ *)op1) = 1; - continue; - } out = in2 & 1 ? in1 : 1; in2 >>= 1; diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index d3d89f086..f2f94d7bf 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -430,6 +430,10 @@ class TestPower(TestCase): b = a ** a assert_equal(b, [437893890380859375, 437893890380859375]) + def test_integer_power_with_zero_exponent(self): + arr = np.arange(-10, 10) + assert_equal(np.power(arr, 0), np.ones_like(arr)) + class TestLog2(TestCase): def test_log2_values(self): |