Skip to content

Commit 009df82

Browse files
authored
Merge pull request numpy#24448 from WarrenWeckesser/test-complex-log
TST: add some tests of np.log for complex input.
2 parents 8207e5c + 9cdefc3 commit 009df82

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

numpy/_core/src/common/npy_config.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@
126126
#undef HAVE_CPOWL
127127
#undef HAVE_CEXPL
128128

129+
/*
130+
* cygwin uses newlib, which has naive implementations of the
131+
* complex log functions.
132+
*/
133+
#undef HAVE_CLOG
134+
#undef HAVE_CLOGF
135+
#undef HAVE_CLOGL
136+
129137
#include <cygwin/version.h>
130138
#if CYGWIN_VERSION_DLL_MAJOR < 3003
131139
// rather than blocklist cabsl, hypotl, modfl, sqrtl, error out
@@ -182,6 +190,16 @@
182190
#undef HAVE_CACOSHF
183191
#undef HAVE_CACOSHL
184192

193+
/*
194+
* musl's clog is low precision for some inputs. As of MUSL 1.2.5,
195+
* the first comment in clog.c is "// FIXME".
196+
* See https://github.com/numpy/numpy/pull/24416#issuecomment-1678208628
197+
* and https://github.com/numpy/numpy/pull/24448
198+
*/
199+
#undef HAVE_CLOG
200+
#undef HAVE_CLOGF
201+
#undef HAVE_CLOGL
202+
185203
#endif /* defined(__GLIBC) */
186204
#endif /* defined(HAVE_FEATURES_H) */
187205

numpy/_core/tests/test_umath.py

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

1407+
# Reference values were computed with mpmath, with mp.dps = 200.
1408+
@pytest.mark.parametrize(
1409+
'z, wref',
1410+
[(1 + 1e-12j, 5e-25 + 1e-12j),
1411+
(1.000000000000001 + 3e-08j,
1412+
1.5602230246251546e-15 + 2.999999999999996e-08j),
1413+
(0.9999995000000417 + 0.0009999998333333417j,
1414+
7.831475869017683e-18 + 0.001j),
1415+
(0.9999999999999996 + 2.999999999999999e-08j,
1416+
5.9107901499372034e-18 + 3e-08j),
1417+
(0.99995000042 - 0.009999833j,
1418+
-7.015159763822903e-15 - 0.009999999665816696j)],
1419+
)
1420+
def test_log_precision_float64(self, z, wref):
1421+
w = np.log(z)
1422+
assert_allclose(w, wref, rtol=1e-15)
1423+
1424+
# Reference values were computed with mpmath, with mp.dps = 200.
1425+
@pytest.mark.parametrize(
1426+
'z, wref',
1427+
[(np.complex64(1.0 + 3e-6j), np.complex64(4.5e-12+3e-06j)),
1428+
(np.complex64(1.0 - 2e-5j), np.complex64(1.9999999e-10 - 2e-5j)),
1429+
(np.complex64(0.9999999 + 1e-06j),
1430+
np.complex64(-1.192088e-07+1.0000001e-06j))],
1431+
)
1432+
def test_log_precision_float32(self, z, wref):
1433+
w = np.log(z)
1434+
assert_allclose(w, wref, rtol=1e-6)
1435+
1436+
14071437
class TestExp:
14081438
def test_exp_values(self):
14091439
x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]

0 commit comments

Comments
 (0)