MCPcopy Create free account
hub / github.com/numpy/numpy / approx

Function approx

numpy/ma/testutils.py:41–60  ·  view source on GitHub ↗

Returns true if all components of a and b are equal to given tolerances. If fill_value is True, masked values considered equal. Otherwise, masked values are considered unequal. The relative error rtol should be positive and << 1.0 The absolute error atol comes into play for th

(a, b, fill_value=True, rtol=1e-5, atol=1e-8)

Source from the content-addressed store, hash-verified

39
40
41def approx(a, b, fill_value=True, rtol=1e-5, atol=1e-8):
42 """
43 Returns true if all components of a and b are equal to given tolerances.
44
45 If fill_value is True, masked values considered equal. Otherwise,
46 masked values are considered unequal. The relative error rtol should
47 be positive and << 1.0 The absolute error atol comes into play for
48 those elements of b that are very small or zero; it says how small a
49 must be also.
50
51 """
52 m = mask_or(getmask(a), getmask(b))
53 d1 = filled(a)
54 d2 = filled(b)
55 if d1.dtype.char == "O" or d2.dtype.char == "O":
56 return np.equal(d1, d2).ravel()
57 x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
58 y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
59 d = np.less_equal(umath.absolute(x - y), atol + rtol * umath.absolute(y))
60 return d.ravel()
61
62
63def almost(a, b, decimal=6, fill_value=True):

Callers 1

compareFunction · 0.85

Calls 6

mask_orFunction · 0.85
getmaskFunction · 0.85
filledFunction · 0.85
astypeMethod · 0.80
ravelMethod · 0.45
less_equalMethod · 0.45

Tested by

no test coverage detected