8000 TST: add some tests of np.log for complex input. · numpy/numpy@a9425df · GitHub
[go: up one dir, main page]

Skip to content

Commit a9425df

Browse files
TST: add some tests of np.log for complex input.
These are values where some platforms might lose precision. [skip circle]
1 parent 160c16f commit a9425df

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

numpy/core/tests/test_umath.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,36 @@ def test_log_strides(self):
13841384
assert_array_almost_equal_nulp(np.log(x_f64[::jj]), y_true[::jj], nulp=2)
13851385
assert_array_almost_equal_nulp(np.log(x_special[::jj]), y_special[::jj], nulp=2)
13861386

1387+
# Reference values were computed with mpmath, with mp.dps = 200.
1388+
@pytest.mark.parametrize(
1389+
'z, wref',
1390+
[(1 + 1e-12j, 5e-25 + 1e-12j),
1391+
(1.000000000000001 + 3e-08j,
1392+
1.5602230246251546e-15 + 2.999999999999996e-08j),
1393+
(0.9999995000000417 + 0.0009999998333333417j,
1394+
7.831475869017683e-18 + 0.001j),
1395+
(0.9999999999999996 + 2.999999999999999e-08j,
1396+
5.9107901499372034e-18 + 3e-08j),
1397+
(0.99995000042 - 0.009999833j,
1398+
-7.015159763822903e-15 - 0.009999999665816696j)],
1399+
)
1400+
def test_log_precision_float64(self, z, wref):
1401+
w = np.log(z)
1402+
assert_allclose(w, wref, rtol=1e-15)
1403+
1404+
# Reference values were computed with mpmath, with mp.dps = 200.
1405+
@pytest.mark.parametrize(
1406+
'z, wref',
1407+
[(np.complex64(1.0 + 3e-6j), np.complex64(4.5e-12+3e-06j)),
1408+
(np.complex64(1.0 - 2e-5j), np.complex64(1.9999999e-10 - 2e-5j)),
1409+
(np.complex64(0.9999999 + 1e-06j),
1410+
np.complex64(-1.192088e-07+1.0000001e-06j))],
1411+
)
1412+
def test_log_precision_float32(self, z, wref):
1413+
w = np.log(z)
1414+
assert_allclose(w, wref, rtol=1e-6)
1415+
1416+
13871417
class TestExp:
13881418
def test_exp_values(self):
13891419
x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]

0 commit comments

Comments
 (0)
0