Skip to content

Instantly share code, notes, and snippets.

@mwhudson
Created September 10, 2018 23:05
Show Gist options
  • Save mwhudson/4de914c033a53133a77a40fd08cc53e8 to your computer and use it in GitHub Desktop.
Save mwhudson/4de914c033a53133a77a40fd08cc53e8 to your computer and use it in GitHub Desktop.
Building, see build.log...
Build OK (0:00:03.004193 elapsed)
============================= test session starts ==============================
platform linux -- Python 3.6.6+, pytest-3.6.4, py-1.5.4, pluggy-0.6.0
rootdir: /root/scipy, inifile: pytest.ini
collected 1 item
scipy/special/tests/test_mpmath.py F [100%]
=================================== FAILURES ===================================
___________________________ TestSystematic.test_pcfw ___________________________
self = <scipy.special.tests.test_mpmath.TestSystematic object at 0xf538b82c>
def test_pcfw(self):
def pcfw(a, x):
return sc.pbwa(a, x)[0]
def dpcfw(a, x):
return sc.pbwa(a, x)[1]
def mpmath_dpcfw(a, x):
return mpmath.diff(mpmath.pcfw, (a, x), (0, 1))
# The Zhang and Jin implementation only uses Taylor series and
# is thus accurate in only a very small range.
assert_mpmath_equal(pcfw,
mpmath.pcfw,
> [Arg(-5, 5), Arg(-5, 5)], rtol=1e-8, n=100)
dpcfw = <function TestSystematic.test_pcfw.<locals>.dpcfw at 0xf539541c>
mpmath_dpcfw = <function TestSystematic.test_pcfw.<locals>.mpmath_dpcfw at 0xf5395464>
pcfw = <function TestSystematic.test_pcfw.<locals>.pcfw at 0xf53953d4>
self = <scipy.special.tests.test_mpmath.TestSystematic object at 0xf538b82c>
scipy/special/tests/test_mpmath.py:1712:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
scipy/special/_mptestutils.py:288: in assert_mpmath_equal
d.check()
scipy/special/_mptestutils.py:275: in check
reraise(*sys.exc_info())
scipy/_lib/six.py:203: in reraise
raise value
scipy/special/_mptestutils.py:271: in check
param_filter=self.param_filter)
scipy/special/_testutils.py:86: in assert_func_equal
fdata.check()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Data for pcfw>
data = array([[-5.00000000e+00, -5.00000000e+00],
[-5.00000000e+00, -3.33333333e+00],
[-5.00000000e+00, -1.6666....00000000e+00, 1.58113883e-15],
[ 5.00000000e+00, 2.50000000e+00],
[ 5.00000000e+00, 5.00000000e+00]])
dtype = dtype('float64')
def check(self, data=None, dtype=None):
"""Check the special function against the data."""
if self.knownfailure:
pytest.xfail(reason=self.knownfailure)
if data is None:
data = self.data
if dtype is None:
dtype = data.dtype
else:
data = data.astype(dtype)
rtol, atol = self.get_tolerances(dtype)
# Apply given filter functions
if self.param_filter:
param_mask = np.ones((data.shape[0],), np.bool_)
for j, filter in zip(self.param_columns, self.param_filter):
if filter:
param_mask &= list(filter(data[:,j]))
data = data[param_mask]
# Pick parameters from the correct columns
params = []
for j in self.param_columns:
if np.iscomplexobj(j):
j = int(j.imag)
params.append(data[:,j].astype(complex))
else:
params.append(data[:,j])
# Helper for evaluating results
def eval_func_at_params(func, skip_mask=None):
if self.vectorized:
got = func(*params)
else:
got = []
for j in range(len(params[0])):
if skip_mask is not None and skip_mask[j]:
got.append(np.nan)
continue
got.append(func(*tuple([params[i][j] for i in range(len(params))])))
got = np.asarray(got)
if not isinstance(got, tuple):
got = (got,)
return got
# Evaluate function to be tested
got = eval_func_at_params(self.func)
# Grab the correct results
if self.result_columns is not None:
# Correct results passed in with the data
wanted = tuple([data[:,icol] for icol in self.result_columns])
else:
# Function producing correct results passed in
skip_mask = None
if self.nan_ok and len(got) == 1:
# Don't spend time evaluating what doesn't need to be evaluated
skip_mask = np.isnan(got[0])
wanted = eval_func_at_params(self.result_func, skip_mask=skip_mask)
# Check the validity of each output returned
assert_(len(got) == len(wanted))
for output_num, (x, y) in enumerate(zip(got, wanted)):
if np.issubdtype(x.dtype, np.complexfloating) or self.ignore_inf_sign:
pinf_x = np.isinf(x)
pinf_y = np.isinf(y)
minf_x = np.isinf(x)
minf_y = np.isinf(y)
else:
pinf_x = np.isposinf(x)
pinf_y = np.isposinf(y)
minf_x = np.isneginf(x)
minf_y = np.isneginf(y)
nan_x = np.isnan(x)
nan_y = np.isnan(y)
olderr = np.seterr(all='ignore')
try:
abs_y = np.absolute(y)
abs_y[~np.isfinite(abs_y)] = 0
diff = np.absolute(x - y)
diff[~np.isfinite(diff)] = 0
rdiff = diff / np.absolute(y)
rdiff[~np.isfinite(rdiff)] = 0
finally:
np.seterr(**olderr)
tol_mask = (diff <= atol + rtol*abs_y)
pinf_mask = (pinf_x == pinf_y)
minf_mask = (minf_x == minf_y)
nan_mask = (nan_x == nan_y)
bad_j = ~(tol_mask & pinf_mask & minf_mask & nan_mask)
point_count = bad_j.size
if self.nan_ok:
bad_j &= ~nan_x
bad_j &= ~nan_y
point_count -= (nan_x | nan_y).sum()
if not self.distinguish_nan_and_inf and not self.nan_ok:
# If nan's are okay we've already covered all these cases
inf_x = np.isinf(x)
inf_y = np.isinf(y)
both_nonfinite = (inf_x & nan_y) | (nan_x & inf_y)
bad_j &= ~both_nonfinite
point_count -= both_nonfinite.sum()
if np.any(bad_j):
# Some bad results: inform what, where, and how bad
msg = [""]
msg.append("Max |adiff|: %g" % diff.max())
msg.append("Max |rdiff|: %g" % rdiff.max())
msg.append("Bad results (%d out of %d) for the following points (in output %d):"
% (np.sum(bad_j), point_count, output_num,))
for j in np.nonzero(bad_j)[0]:
j = int(j)
fmt = lambda x: "%30s" % np.array2string(x[j], precision=18)
a = " ".join(map(fmt, params))
b = " ".join(map(fmt, got))
c = " ".join(map(fmt, wanted))
d = fmt(rdiff)
msg.append("%s => %s != %s (rdiff %s)" % (a, b, c, d))
> assert_(False, "\n".join(msg))
E AssertionError:
E Max |adiff|: 9.94987e-10
E Max |rdiff|: 1.72855e-08
E Bad results (1 out of 121) for the following points (in output 0):
E 5. 5. => 0.000115773466171662 != 0.000115773464170455 (rdiff 1.7285542329939906e-08)
a = ' 5. 5.'
abs_y = array([5.38608397e-01, 3.15383218e-01, 6.42834862e-01, 4.73478577e-01,
4.73478576e-01, 4.73478576e-01, 4.734785...576e-01, 4.73478576e-01,
4.73478576e-01, 4.73478576e-01, 4.73478576e-01, 2.72359636e-03,
1.15773464e-04])
atol = 1e-300
b = ' 0.000115773466171662'
bad_j = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, True])
c = ' 0.000115773464170455'
d = ' 1.7285542329939906e-08'
data = array([[-5.00000000e+00, -5.00000000e+00],
[-5.00000000e+00, -3.33333333e+00],
[-5.00000000e+00, -1.6666....00000000e+00, 1.58113883e-15],
[ 5.00000000e+00, 2.50000000e+00],
[ 5.00000000e+00, 5.00000000e+00]])
diff = array([1.33226763e-15, 7.21644966e-16, 4.44089210e-16, 1.66533454e-16,
1.11022302e-16, 1.11022302e-16, 1.110223...720e-13, 1.65367720e-13,
1.65367720e-13, 1.65367720e-13, 1.65367720e-13, 6.42207641e-14,
2.00120712e-12])
dtype = dtype('float64')
eval_func_at_params = <function FuncData.check.<locals>.eval_func_at_params at 0xf5395584>
filter = None
fmt = <function FuncData.check.<locals>.<lambda> at 0xf53bae3c>
got = (array([ 5.38608397e-01, 3.15383218e-01, -6.42834862e-01, 4.73478577e-01,
4.73478576e-01, 4.73478576e-01, ... 4.73478576e-01,
4.73478576e-01, 4.73478576e-01, 4.73478576e-01, 2.72359636e-03,
1.15773466e-04]),)
j = 120
minf_mask = array([ True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True,... True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, True])
minf_x = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False])
minf_y = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False])
msg = ['', 'Max |adiff|: 9.94987e-10', 'Max |rdiff|: 1.72855e-08', 'Bad results (1 out of 121) for the following points (in ... 5. => 0.000115773466171662 != 0.000115773464170455 (rdiff 1.7285542329939906e-08)']
nan_mask = array([ True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True,... True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, True])
nan_x = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False])
nan_y = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False])
olderr = {'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under': 'ignore'}
output_num = 0
param_mask = array([ True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True,... True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, True])
params = [array([-5.00000000e+00, -5.00000000e+00, -5.00000000e+00, -5.00000000e+00,
-5.00000000e+00, -5.00000000e+00, -..., -1.00000000e-30,
0.00000000e+00, 1.00000000e-30, 1.58113883e-15, 2.50000000e+00,
5.00000000e+00])]
pinf_mask = array([ True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True,... True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, True])
pinf_x = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False])
pinf_y = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False])
point_count = 121
rdiff = array([2.47353669e-15, 2.28815271e-15, 6.90829381e-16, 3.51723313e-16,
2.34482209e-16, 2.34482209e-16, 2.344822...250e-13, 3.49261250e-13,
3.49261250e-13, 3.49261250e-13, 3.49261250e-13, 2.35793986e-11,
1.72855423e-08])
rtol = 1e-08
self = <Data for pcfw>
skip_mask = array([False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False,...False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False])
tol_mask = array([ True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True,... True, True,
True, True, True, True, True, True, True, True, True,
True, True, True, False])
wanted = (array([ 5.38608397e-01, 3.15383218e-01, -6.42834862e-01, 4.73478577e-01,
4.73478576e-01, 4.73478576e-01, ... 4.73478576e-01,
4.73478576e-01, 4.73478576e-01, 4.73478576e-01, 2.72359636e-03,
1.15773464e-04]),)
x = array([ 5.38608397e-01, 3.15383218e-01, -6.42834862e-01, 4.73478577e-01,
4.73478576e-01, 4.73478576e-01, 4...1, 4.73478576e-01,
4.73478576e-01, 4.73478576e-01, 4.73478576e-01, 2.72359636e-03,
1.15773466e-04])
y = array([ 5.38608397e-01, 3.15383218e-01, -6.42834862e-01, 4.73478577e-01,
4.73478576e-01, 4.73478576e-01, 4...1, 4.73478576e-01,
4.73478576e-01, 4.73478576e-01, 4.73478576e-01, 2.72359636e-03,
1.15773464e-04])
scipy/special/_testutils.py:305: AssertionError
=========================== 1 failed in 1.83 seconds ===========================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment