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

Skip to content

Commit 34b5f9f

Browse files
ewmoorecharris
authored andcommitted
TST: Add tests for complex ufuncs.
The test for precision needed to have difference changed from 2*eps to 2.1*eps for the system supplied sinh.
1 parent 6906823 commit 34b5f9f

1 file changed

Lines changed: 60 additions & 44 deletions

File tree

numpy/core/tests/test_umath.py

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,45 +1363,53 @@ def test_precisions_consistent(self) :
13631363

13641364
def test_branch_cuts(self):
13651365
# check branch cuts and continuity on them
1366-
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1
1367-
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1
1368-
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1
1369-
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1
1370-
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1
1366+
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True
1367+
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True
1368+
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
1369+
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
1370+
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True
13711371

1372-
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, -1j], 1, -1
1373-
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, -1j], 1, -1
1374-
yield _check_branch_cut, np.arctan, [-2j, 2j], [1, -1 ], -1, 1
1372+
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True
1373+
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True
1374+
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1 ], -1, 1, True
13751375

1376-
yield _check_branch_cut, np.arcsinh, [-2j, 2j], [-1, 1], -1, 1
1377-
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1
1378-
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, -1j], 1, -1
1376+
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True
1377+
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True
1378+
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True
13791379

13801380
# check against bogus branch cuts: assert continuity between quadrants
1381-
yield _check_branch_cut, np.arcsin, [-2j, 2j], [ 1, 1], 1, 1
1382-
yield _check_branch_cut, np.arccos, [-2j, 2j], [ 1, 1], 1, 1
1381+
yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1
1382+
yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1
13831383
yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1
13841384

13851385
yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1 ], 1, 1
1386-
yield _check_branch_cut, np.arccosh, [-2j, 2j, 2], [1, 1, 1j], 1, 1
1387-
yield _check_branch_cut, np.arctanh, [-2j, 2j, 0], [1, 1, 1j], 1, 1
1386+
yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1
1387+
yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1
13881388

1389-
@dec.knownfailureif(True, "These branch cuts are known to fail")
1390-
def test_branch_cuts_failing(self):
1391-
# XXX: signed zero not OK with ICC on 64-bit platform for log, see
1392-
# http://permalink.gmane.org/gmane.comp.python.numeric.general/25335
1393-
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True
1394-
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True
1395-
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
1396-
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
1397-
# XXX: signed zeros are not OK for sqrt or for the arc* functions
1398-
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True
1399-
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, -1j], 1, -1, True
1400-
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, -1j], 1, -1, True
1401-
yield _check_branch_cut, np.arctan, [-2j, 2j], [1, -1 ], -1, 1, True
1402-
yield _check_branch_cut, np.arcsinh, [-2j, 2j], [-1, 1], -1, 1, True
1403-
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True
1404-
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, -1j], 1, -1, True
1389+
def test_branch_cuts_complex64(self):
1390+
# check branch cuts and continuity on them
1391+
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True, np.complex64
1392+
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True, np.complex64
1393+
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
1394+
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
1395+
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True, np.complex64
1396+
1397+
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
1398+
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
1399+
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1 ], -1, 1, True, np.complex64
1400+
1401+
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64
1402+
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64
1403+
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
1404+
1405+
# check against bogus branch cuts: assert continuity between quadrants
1406+
yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64
1407+
yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64
1408+
yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64
1409+
1410+
yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1 ], 1, 1, False, np.complex64
1411+
yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64
1412+
yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64
14051413

14061414
def test_against_cmath(self):
14071415
import cmath, sys
@@ -1466,7 +1474,7 @@ def check(x, rtol):
14661474
# So, give more leeway for long complex tests here:
14671475
check(x_series, 50*eps)
14681476
else:
1469-
check(x_series, 2*eps)
1477+
check(x_series, 2.1*eps)
14701478
check(x_basic, 2*eps/1e-3)
14711479

14721480
# Check a few points
@@ -1565,8 +1573,12 @@ def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False,
15651573
x0 = np.atleast_1d(x0).astype(dtype)
15661574
dx = np.atleast_1d(dx).astype(dtype)
15671575

1568-
scale = np.finfo(dtype).eps * 1e3
1569-
atol = 1e-4
1576+
if np.dtype(dtype).char == 'F':
1577+
scale = np.finfo(dtype).eps * 1e2
1578+
atol = np.float32(1e-2)
1579+
else:
1580+
scale = np.finfo(dtype).eps * 1e3
1581+
atol = 1e-4
15701582

15711583
y0 = f(x0)
15721584
yp = f(x0 + dx*scale*np.absolute(x0)/np.absolute(dx))
@@ -1581,16 +1593,20 @@ def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False,
15811593
# check that signed zeros also work as a displacement
15821594
jr = (x0.real == 0) & (dx.real != 0)
15831595
ji = (x0.imag == 0) & (dx.imag != 0)
1584-
1585-
x = -x0
1586-
x.real[jr] = 0.*dx.real
1587-
x.imag[ji] = 0.*dx.imag
1588-
x = -x
1589-
ym = f(x)
1590-
ym = ym[jr | ji]
1591-
y0 = y0[jr | ji]
1592-
assert_(np.all(np.absolute(y0.real - ym.real*re_sign) < atol), (y0, ym))
1593-
assert_(np.all(np.absolute(y0.imag - ym.imag*im_sign) < atol), (y0, ym))
1596+
if np.any(jr):
1597+
x = x0[jr]
1598+
x.real = np.NZERO
1599+
ym = f(x)
1600+
assert_(np.all(np.absolute(y0[jr].real - ym.real*re_sign) < atol), (y0[jr], ym))
1601+
assert_(np.all(np.absolute(y0[jr].imag - ym.imag*im_sign) < atol), (y0[jr], ym))
1602+
1603+
1604+
if np.any(ji):
1605+
x = x0[ji]
1606+
x.imag = np.NZERO
1607+
ym = f(x)
1608+
assert_(np.all(np.absolute(y0[ji].real - ym.real*re_sign) < atol), (y0[ji], ym))
1609+
assert_(np.all(np.absolute(y0[ji].imag - ym.imag*im_sign) < atol), (y0[ji], ym))
15941610

15951611
def test_copysign():
15961612
assert_(np.copysign(1, -1) == -1)

0 commit comments

Comments
 (0)