MCPcopy
hub / github.com/numpy/numpy / approx

Function approx

numpy/ma/testutils.py:45–66  ·  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

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

Callers 1

compareFunction · 0.85

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…