summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime <jaime.frio@gmail.com>2016-04-05 17:24:18 +0200
committerJaime <jaime.frio@gmail.com>2016-04-05 17:24:18 +0200
commitb7a83d6f67be66b43a0b61f80ce5fa551a760a89 (patch)
treecde740e8a3ec9151097735f98e89b8fda141e7cc
parent9c59de6e5771174dec5487a25d7594e4021669d6 (diff)
parent307931d804fde05ed0281c9bbb9d522a682f2762 (diff)
downloadnumpy-b7a83d6f67be66b43a0b61f80ce5fa551a760a89.tar.gz
Merge pull request #7511 from lesteve/fix-power-with-zero-exponent
numpy.power(0, 0) should return 1
-rw-r--r--numpy/core/src/umath/loops.c.src8
-rw-r--r--numpy/core/tests/test_umath.py4
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):