Made doctests more robust.

master
Per A Brodtkorb 6 years ago
parent 61c1d8e650
commit 75591fcd3e

@ -187,8 +187,9 @@ class PlotData(object):
>>> y = np.sin(x) >>> y = np.sin(x)
>>> ci = PlotData(np.vstack((y*.9, y*1.1)).T, x) >>> ci = PlotData(np.vstack((y*.9, y*1.1)).T, x)
>>> d = PlotData(y, x, children=[ci]) >>> d = PlotData(y, x, children=[ci])
>>> d.integrate(0, np.pi/2, return_ci=True) >>> np.allclose(d.integrate(0, np.pi/2, return_ci=True),
array([ 0.99940055, 0.89946049, 1.0993406 ]) ... [ 0.99940055, 0.89946049, 1.0993406 ])
True
>>> np.allclose(d.integrate(0, 5, return_ci=True), >>> np.allclose(d.integrate(0, 5, return_ci=True),
... d.integrate(return_ci=True)) ... d.integrate(return_ci=True))
True True
@ -209,7 +210,7 @@ class PlotData(object):
return res return res
def _plot_children(self, axis, plotflag, kwds): def _plot_children(self, axis, plotflag, kwds):
axis.hold('on') # axis.hold('on')
tmp = [] tmp = []
child_args = kwds.pop('plot_args_children', child_args = kwds.pop('plot_args_children',
tuple(self.plot_args_children)) tuple(self.plot_args_children))
@ -413,7 +414,7 @@ def plot1d(axis, args, data, dataCI, plotflag, *varargin, **kwds):
plotfun = getattr(axis, fun) plotfun = getattr(axis, fun)
h.extend(plotfun(args, data, *varargin, **kwds)) h.extend(plotfun(args, data, *varargin, **kwds))
if np.any(dataCI) and plottype < 3: if np.any(dataCI) and plottype < 3:
axis.hold(True) # axis.hold(True)
h.extend(plotfun(args, dataCI, 'r--')) h.extend(plotfun(args, dataCI, 'r--'))
elif plottype == 4: elif plottype == 4:
h = axis.errorbar(args, data, h = axis.errorbar(args, data,

@ -95,10 +95,10 @@ def dct(x, type=2, n=None, axis=-1, norm='ortho'): # @ReservedAssignment
-------- --------
>>> import numpy as np >>> import numpy as np
>>> x = np.arange(5) >>> x = np.arange(5)
>>> np.abs(x-idct(dct(x)))<1e-14 >>> np.allclose(x, idct(dct(x)))
array([ True, True, True, True, True], dtype=bool) True
>>> np.abs(x-dct(idct(x)))<1e-14 >>> np.allclose(x, dct(idct(x)))
array([ True, True, True, True, True], dtype=bool) True
References References
---------- ----------

@ -705,8 +705,8 @@ def prbnormnd(correl, a, b, abseps=1e-4, releps=1e-3, maxpts=None, method=0):
... [0.0019456719705212067, 1.0059406844578488e-05, 0]) ... [0.0019456719705212067, 1.0059406844578488e-05, 0])
True True
>>> np.abs(val-Et)< err0+terr0 >>> np.allclose(np.abs(val-Et) < err0+terr0, True)
array([ True], dtype=bool) True
>>> 'val = %2.5f' % val >>> 'val = %2.5f' % val
'val = 0.00195' 'val = 0.00195'

@ -453,8 +453,8 @@ def la_roots(n, alpha=0, method='newton'):
------- -------
>>> import numpy as np >>> import numpy as np
>>> [x,w] = h_roots(10) >>> [x,w] = h_roots(10)
>>> np.sum(x*w) >>> np.allclose(np.sum(x*w) < 1e-16, True)
1.3352627380516791e-17 True
See also See also
-------- --------

@ -273,18 +273,18 @@ def lazyselect(condlist, choicelist, arrays, default=0):
Examples Examples
-------- --------
>>> x = np.arange(6) >>> x = np.arange(6)
>>> np.select([x <3, x > 3], [x**2, x**3], default=0) >>> np.allclose(np.select([x <3, x > 3], [x**2, x**3], default=0),
array([ 0, 1, 4, 0, 64, 125]) ... [ 0, 1, 4, 0, 64, 125])
True
>>> lazyselect([x < 3, x > 3], [lambda x: x**2, lambda x: x**3], (x,)) >>> np.allclose(lazyselect([x < 3, x > 3], [lambda x: x**2, lambda x: x**3], (x,)),
array([ 0., 1., 4., 0., 64., 125.]) ... [ 0., 1., 4., 0., 64., 125.])
True
>>> a = -np.ones_like(x) >>> a = -np.ones_like(x)
>>> lazyselect([x < 3, x > 3], >>> np.allclose(lazyselect([x < 3, x > 3],
... [lambda x, a: x**2, lambda x, a: a * x**3], ... [lambda x, a: x**2, lambda x, a: a * x**3],
... (x, a)) ... (x, a)),
array([ 0., 1., 4., 0., -64., -125.]) ... [ 0., 1., 4., 0., -64., -125.])
True
""" """
arrays = np.broadcast_arrays(*arrays) arrays = np.broadcast_arrays(*arrays)
tcode = np.mintypecode([a.dtype.char for a in arrays]) tcode = np.mintypecode([a.dtype.char for a in arrays])
@ -1185,6 +1185,8 @@ def findrfc(tp, h=0.0, method='clib'):
ind, ix = clib.findrfc(y, h) ind, ix = clib.findrfc(y, h)
ix = int(ix) ix = int(ix)
else: else:
if isinstance(method, str):
method = 2
ind = numba_misc.findrfc(y, h, method) ind = numba_misc.findrfc(y, h, method)
ix = len(ind) ix = len(ind)
@ -1909,8 +1911,8 @@ def betaloge(z, w):
Example Example
------- -------
>>> import wafo.misc as wm >>> import wafo.misc as wm
>>> np.abs(wm.betaloge(3,2)+2.48490665)<1e-7 >>> np.allclose(wm.betaloge(3,2), -2.48490665)
array([ True], dtype=bool) True
See also See also
-------- --------

@ -1248,8 +1248,8 @@ class SpecData1D(PlotData):
if paramt is None: if paramt is None:
# (2.5 * mean distance between extremes) # (2.5 * mean distance between extremes)
distanceBetweenExtremes = 5 * pi * sqrt(m[1] / m[2]) distance_between_extremes = 5 * pi * sqrt(m[1] / m[2])
paramt = [0, distanceBetweenExtremes, 43] paramt = [0, distance_between_extremes, 43]
if paramu is None: if paramu is None:
paramu = [-5 * sqrt(m[0]), 5 * sqrt(m[0]), 41] paramu = [-5 * sqrt(m[0]), 5 * sqrt(m[0]), 41]

Loading…
Cancel
Save