MCPcopy
hub / github.com/numpy/numpy / allclose

Function allclose

numpy/_core/numeric.py:2226–2312  ·  view source on GitHub ↗

Returns True if two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (`rtol` * abs(`b`)) and the absolute difference `atol` are added together to compare against the absolute difference b

(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False)

Source from the content-addressed store, hash-verified

2224
2225@array_function_dispatch(_allclose_dispatcher)
2226def allclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
2227 """
2228 Returns True if two arrays are element-wise equal within a tolerance.
2229
2230 The tolerance values are positive, typically very small numbers. The
2231 relative difference (`rtol` * abs(`b`)) and the absolute difference
2232 `atol` are added together to compare against the absolute difference
2233 between `a` and `b`.
2234
2235 .. warning:: The default `atol` is not appropriate for comparing numbers
2236 with magnitudes much smaller than one (see Notes).
2237
2238 NaNs are treated as equal if they are in the same place and if
2239 ``equal_nan=True``. Infs are treated as equal if they are in the same
2240 place and of the same sign in both arrays.
2241
2242 Parameters
2243 ----------
2244 a, b : array_like
2245 Input arrays to compare.
2246 rtol : array_like
2247 The relative tolerance parameter (see Notes).
2248 atol : array_like
2249 The absolute tolerance parameter (see Notes).
2250 equal_nan : bool
2251 Whether to compare NaN's as equal. If True, NaN's in `a` will be
2252 considered equal to NaN's in `b` in the output array.
2253
2254 Returns
2255 -------
2256 allclose : bool
2257 Returns True if the two arrays are equal within the given
2258 tolerance; False otherwise.
2259
2260 See Also
2261 --------
2262 isclose, all, any, equal
2263
2264 Notes
2265 -----
2266 If the following equation is element-wise True, then allclose returns
2267 True.::
2268
2269 absolute(a - b) <= (atol + rtol * absolute(b))
2270
2271 The above equation is not symmetric in `a` and `b`, so that
2272 ``allclose(a, b)`` might be different from ``allclose(b, a)`` in
2273 some rare cases.
2274
2275 The default value of `atol` is not appropriate when the reference value
2276 `b` has magnitude smaller than one. For example, it is unlikely that
2277 ``a = 1e-9`` and ``b = 2e-9`` should be considered "close", yet
2278 ``allclose(1e-9, 2e-9)`` is ``True`` with default settings. Be sure
2279 to select `atol` for the use case at hand, especially for defining the
2280 threshold below which a non-zero value in `a` will be considered "close"
2281 to a very small or zero value in `b`.
2282
2283 The comparison of `a` and `b` uses standard broadcasting, which

Callers 1

test_roundtripMethod · 0.90

Calls 2

allFunction · 0.85
iscloseFunction · 0.85

Tested by 1

test_roundtripMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…