Skip to content

Commit

Permalink
TST: Hardcode the expected output of two complex-related tests
Browse files Browse the repository at this point in the history
Complex exponentiation is broken for `builtins.complex` as of bpo-44698
  • Loading branch information
BvB93 authored and charris committed Aug 11, 2021
1 parent 946f8c8 commit 9c3ea35
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions numpy/core/tests/test_umath_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,18 @@ def test_scalar(self):
x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan])
y = np.array([1, 1j, -0.5+1.5j, -0.5+1.5j, 2, 3])
lx = list(range(len(x)))
# Compute the values for complex type in python
p_r = [complex(x[i]) ** complex(y[i]) for i in lx]
# Substitute a result allowed by C99 standard
p_r[4] = complex(np.inf, np.nan)
# Do the same with numpy complex scalars

# Hardcode the expected `builtins.complex` values,
# as complex exponentiation is broken as of bpo-44698
p_r = [
1+0j,
0.20787957635076193+0j,
0.35812203996480685+0.6097119028618724j,
0.12659112128185032+0.48847676699581527j,
complex(np.inf, np.nan),
complex(np.nan, np.nan),
]

n_r = [x[i] ** y[i] for i in lx]
for i in lx:
assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
Expand All @@ -385,11 +392,18 @@ def test_array(self):
x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan])
y = np.array([1, 1j, -0.5+1.5j, -0.5+1.5j, 2, 3])
lx = list(range(len(x)))
# Compute the values for complex type in python
p_r = [complex(x[i]) ** complex(y[i]) for i in lx]
# Substitute a result allowed by C99 standard
p_r[4] = complex(np.inf, np.nan)
# Do the same with numpy arrays

# Hardcode the expected `builtins.complex` values,
# as complex exponentiation is broken as of bpo-44698
p_r = [
1+0j,
0.20787957635076193+0j,
0.35812203996480685+0.6097119028618724j,
0.12659112128185032+0.48847676699581527j,
complex(np.inf, np.nan),
complex(np.nan, np.nan),
]

n_r = x ** y
for i in lx:
assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
Expand Down Expand Up @@ -583,7 +597,7 @@ class TestComplexAbsoluteMixedDTypes:
@pytest.mark.parametrize("stride", [-4,-3,-2,-1,1,2,3,4])
@pytest.mark.parametrize("astype", [np.complex64, np.complex128])
@pytest.mark.parametrize("func", ['abs', 'square', 'conjugate'])

def test_array(self, stride, astype, func):
dtype = [('template_id', '<i8'), ('bank_chisq','<f4'),
('bank_chisq_dof','<i8'), ('chisq', '<f4'), ('chisq_dof','<i8'),
Expand All @@ -602,9 +616,9 @@ def test_array(self, stride, astype, func):
myfunc = getattr(np, func)
a = vec['mycomplex']
g = myfunc(a[::stride])

b = vec['mycomplex'].copy()
h = myfunc(b[::stride])

assert_array_max_ulp(h.real, g.real, 1)
assert_array_max_ulp(h.imag, g.imag, 1)

0 comments on commit 9c3ea35

Please sign in to comment.