1 import numpy as np
2
3 __all__ = ['assert_allclose']
4
5 try:
6 from numpy.testing.utils import assert_allclose
7 except ImportError:
8 - def assert_allclose(actual, desired, rtol=1e-7, atol=0,
9 err_msg='', verbose=True):
10 ''' Backporting assert_allclose from Numpy 1.5 to 1.4 '''
11 from numpy.testing.utils import assert_array_compare
12
13 def compare(x, y):
14 return np.allclose(x, y, rtol=rtol, atol=atol)
15
16 actual, desired = np.asanyarray(actual), np.asanyarray(desired)
17 header = 'Not equal to tolerance rtol=%g, atol=%g' % (rtol, atol)
18 assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
19 verbose=verbose, header=header)
20