Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8f13ee

Browse files
committed
TST: Enable signed zero branch cut tests
Now we have our own implementations that can pass these tests and we only link against the system versions if they can also pass. Additionally, run the branch cut tests for complex64.
1 parent def6327 commit c8f13ee

1 file changed

Lines changed: 55 additions & 39 deletions

File tree

numpy/core/tests/test_umath.py

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,19 +1114,19 @@ def test_precisions_consistent(self) :
11141114

11151115
def test_branch_cuts(self):
11161116
# check branch cuts and continuity on them
1117-
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1
1118-
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1
1119-
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1
1120-
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1
1121-
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1
1117+
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True
1118+
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True
1119+
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
1120+
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
1121+
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True
11221122

1123-
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1
1124-
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1
1125-
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1 ], -1, 1
1123+
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True
1124+
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True
1125+
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1 ], -1, 1, True
11261126

1127-
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1
1128-
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1
1129-
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1
1127+
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True
1128+
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True
1129+
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True
11301130

11311131
# check against bogus branch cuts: assert continuity between quadrants
11321132
yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1
@@ -1137,22 +1137,30 @@ def test_branch_cuts(self):
11371137
yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1
11381138
yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1
11391139

1140-
@dec.knownfailureif(True, "These branch cuts are known to fail")
1141-
def test_branch_cuts_failing(self):
1142-
# XXX: signed zero not OK with ICC on 64-bit platform for log, see
1143-
# http://permalink.gmane.org/gmane.comp.python.numeric.general/25335
1144-
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True
1145-
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True
1146-
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
1147-
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
1148-
# XXX: signed zeros are not OK for sqrt or for the arc* functions
1149-
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True
1150-
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True
1151-
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True
1152-
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1 ], -1, 1, True
1153-
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True
1154-
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True
1155-
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True
1140+
def test_branch_cuts_complex64(self):
1141+
# check branch cuts and continuity on them
1142+
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True, np.complex64
1143+
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True, np.complex64
1144+
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
1145+
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
1146+
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True, np.complex64
1147+
1148+
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
1149+
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
1150+
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1 ], -1, 1, True, np.complex64
1151+
1152+
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64
1153+
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64
1154+
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
1155+
1156+
# check against bogus branch cuts: assert continuity between quadrants
1157+
yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64
1158+
yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64
1159+
yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64
1160+
1161+
yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1 ], 1, 1, False, np.complex64
1162+
yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64
1163+
yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64
11561164

11571165
def test_against_cmath(self):
11581166
import cmath, sys
@@ -1316,8 +1324,12 @@ def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False,
13161324
x0 = np.atleast_1d(x0).astype(dtype)
13171325
dx = np.atleast_1d(dx).astype(dtype)
13181326

1319-
scale = np.finfo(dtype).eps * 1e3
1320-
atol = 1e-4
1327+
if np.dtype(dtype).char == 'F':
1328+
scale = np.finfo(dtype).eps * 1e2
1329+
atol = np.float32(1e-2)
1330+
else:
1331+
scale = np.finfo(dtype).eps * 1e3
1332+
atol = 1e-4
13211333

13221334
y0 = f(x0)
13231335
yp = f(x0 + dx*scale*np.absolute(x0)/np.absolute(dx))
@@ -1332,16 +1344,20 @@ def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False,
13321344
# check that signed zeros also work as a displacement
13331345
jr = (x0.real == 0) & (dx.real != 0)
13341346
ji = (x0.imag == 0) & (dx.imag != 0)
1335-
1336-
x = -x0
1337-
x.real[jr] = 0.*dx.real
1338-
x.imag[ji] = 0.*dx.imag
1339-
x = -x
1340-
ym = f(x)
1341-
ym = ym[jr | ji]
1342-
y0 = y0[jr | ji]
1343-
assert_(np.all(np.absolute(y0.real - ym.real*re_sign) < atol), (y0, ym))
1344-
assert_(np.all(np.absolute(y0.imag - ym.imag*im_sign) < atol), (y0, ym))
1347+
if np.any(jr):
1348+
x = x0[jr]
1349+
x.real = np.NZERO
1350+
ym = f(x)
1351+
assert_(np.all(np.absolute(y0[jr].real - ym.real*re_sign) < atol), (y0[jr], ym))
1352+
assert_(np.all(np.absolute(y0[jr].imag - ym.imag*im_sign) < atol), (y0[jr], ym))
1353+
1354+
1355+
if np.any(ji):
1356+
x = x0[ji]
1357+
x.imag = np.NZERO
1358+
ym = f(x)
1359+
assert_(np.all(np.absolute(y0[ji].real - ym.real*re_sign) < atol), (y0[ji], ym))
1360+
assert_(np.all(np.absolute(y0[ji].imag - ym.imag*im_sign) < atol), (y0[ji], ym))
13451361

13461362
def test_copysign():
13471363
assert_(np.copysign(1, -1) == -1)

0 commit comments

Comments
 (0)