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)
| 43 | |
| 44 | |
| 45 | def 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 | |
| 69 | def almost(a, b, decimal=6, fill_value=True): |