[Scipy-svn] r6547 - trunk/scipy/special/tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Sun Jun 20 18:41:00 EDT 2010
Author: ptvirtan
Date: 2010-06-20 17:41:00 -0500 (Sun, 20 Jun 2010)
New Revision: 6547
Modified:
trunk/scipy/special/tests/testutils.py
Log:
ENH: special: add assert_func_equal to clean up the way dataset tests are implemented
Modified: trunk/scipy/special/tests/testutils.py
===================================================================
--- trunk/scipy/special/tests/testutils.py 2010-06-20 22:40:38 UTC (rev 6546)
+++ trunk/scipy/special/tests/testutils.py 2010-06-20 22:41:00 UTC (rev 6547)
@@ -6,6 +6,9 @@
import scipy.special as sc
+__all__ = ['with_special_errors', 'assert_tol_equal', 'assert_func_equal',
+ 'FuncData']
+
#------------------------------------------------------------------------------
# Enable convergence and loss of precision warnings -- turn off one by one
#------------------------------------------------------------------------------
@@ -46,6 +49,39 @@
# error reports
#------------------------------------------------------------------------------
+def assert_func_equal(func, results, points, rtol=None, atol=None,
+ param_filter=None, knownfailure=None,
+ vectorized=True, dtype=None):
+ if hasattr(points, 'next'):
+ # it's a generator
+ points = list(points)
+
+ points = np.asarray(points)
+ if points.ndim == 1:
+ points = points[:,None]
+
+ if hasattr(results, '__name__'):
+ # function
+ if vectorized:
+ results = results(*tuple(points.T))
+ else:
+ results = np.array([results(*tuple(p)) for p in points])
+ if results.dtype == object:
+ try:
+ results = results.astype(float)
+ except TypeError:
+ results = results.astype(complex)
+ else:
+ results = np.asarray(results)
+
+ npoints = points.shape[1]
+
+ data = np.c_[points, results]
+ fdata = FuncData(func, data, range(npoints), range(npoints, data.shape[1]),
+ rtol=rtol, atol=atol, param_filter=param_filter,
+ knownfailure=knownfailure)
+ fdata.check()
+
class FuncData(object):
"""
Data set for checking a special function.
More information about the Scipy-svn
mailing list