summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/npymath/npy_math_complex.c.src14
-rw-r--r--numpy/core/tests/test_umath.py26
2 files changed, 13 insertions, 27 deletions
diff --git a/numpy/core/src/npymath/npy_math_complex.c.src b/numpy/core/src/npymath/npy_math_complex.c.src
index 224ef0b40..0a786234e 100644
--- a/numpy/core/src/npymath/npy_math_complex.c.src
+++ b/numpy/core/src/npymath/npy_math_complex.c.src
@@ -445,17 +445,17 @@ npy_cpow@c@ (@ctype@ a, @ctype@ b)
@type@ bi = npy_cimag@c@(b);
@ctype@ r;
- //Checking if in a^b, if b is zero.
- //If a is not zero then by definition of logarithm a^0 is one.
- //If a is also zero then as per IEEE 0^0 is best defined as 1.
+ /*Checking if in a^b, if b is zero.
+ If a is not zero then by definition of logarithm a^0 is one.
+ If a is also zero then as per IEEE 0^0 is best defined as 1.*/
if(br == 0. && bi == 0.){
return npy_cpack@c@(1.,0.);
}
- //Here it is already tested that for a^b, b is not zero.
- //So we are checking behaviour of a.
+ /*Here it is already tested that for a^b, b is not zero.
+ So we are checking behaviour of a.*/
else if(ar == 0. && ai == 0.){
- //Checking if real part of power is greater than zero then the result is zero.
- //If not the result is undefined as it blows up or oscillates.
+ /*Checking if real part of power is greater than zero then the result is zero.
+ If not the result is undefined as it blows up or oscillates.*/
if(br > 0){
return npy_cpack@c@(0.,0.);
}
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index dd365b0b9..e88bcf8d3 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -847,28 +847,14 @@ class TestPower:
assert_array_equal(x.real, y.real)
assert_array_equal(x.imag, y.imag)
- with pytest.warns(None) as record_pp:
- #real part and imaginary part both greater than zero
- #This case should not generate any warning
- assert_complex_equal(np.power(zero,1+4j),zero)
- assert len(record_pp)==0
- with pytest.warns(None) as record_pn:
- #real part greater than zero imag part less than zero
- #This case should not generate any warning
- assert_complex_equal(np.power(zero,2-3j),zero)
- assert len(record_pn)==0
- with pytest.warns(None) as record_np:
- #real part less than zero imag part greater than zero
- #This case will generate a warning
+ #Complex powers with positive real part will not generate a warning
+ assert_complex_equal(np.power(zero,1+4j),zero)
+ assert_complex_equal(np.power(zero,2-3j),zero)
+ #Complex powers will negative real part will generate a NAN
+ #and hence a RUNTIME warning
+ with pytest.warns(expected_warning=RuntimeWarning):
assert_complex_equal(np.power(zero,-1+1j),cnan)
- assert len(record_np)==1
- assert record_np[0].message.args[0]=="invalid value encountered in power"
- with pytest.warns(None) as record_nn:
- #real part less than zero imag part less than zero
- #This case will generate a warning
assert_complex_equal(np.power(zero,-2-3j),cnan)
- assert len(record_nn)==1
- assert record_nn[0].message.args[0]=="invalid value encountered in power"
def test_fast_power(self):
x = np.array([1, 2, 3], np.int16)