MCPcopy
hub / github.com/numpy/numpy / assert_allclose

Function assert_allclose

numpy/testing/_private/utils.py:1671–1782  ·  view source on GitHub ↗

Raises an AssertionError if two objects are not equal up to desired tolerance. Given two array_like objects, check that their shapes and all elements are equal (but see the Notes for the special handling of a scalar). An exception is raised if the shapes mismatch or any values

(actual, desired, rtol=1e-7, atol=0, equal_nan=True,
                    err_msg='', verbose=True, *, strict=False)

Source from the content-addressed store, hash-verified

1669
1670
1671def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,
1672 err_msg='', verbose=True, *, strict=False):
1673 """
1674 Raises an AssertionError if two objects are not equal up to desired
1675 tolerance.
1676
1677 Given two array_like objects, check that their shapes and all elements
1678 are equal (but see the Notes for the special handling of a scalar). An
1679 exception is raised if the shapes mismatch or any values conflict. In
1680 contrast to the standard usage in numpy, NaNs are compared like numbers,
1681 no assertion is raised if both objects have NaNs in the same positions.
1682
1683 The test is equivalent to ``allclose(actual, desired, rtol, atol)``,
1684 except that it is stricter: it doesn't broadcast its operands, and has
1685 tighter default tolerance values. It compares the difference between
1686 `actual` and `desired` to ``atol + rtol * abs(desired)``.
1687
1688 Parameters
1689 ----------
1690 actual : array_like
1691 Array obtained.
1692 desired : array_like
1693 Array desired.
1694 rtol : float, optional
1695 Relative tolerance.
1696 atol : float | np.timedelta64, optional
1697 Absolute tolerance.
1698 equal_nan : bool, optional.
1699 If True, NaNs will compare equal.
1700 err_msg : str, optional
1701 The error message to be printed in case of failure.
1702 verbose : bool, optional
1703 If True, the conflicting values are appended to the error message.
1704 strict : bool, optional
1705 If True, raise an ``AssertionError`` when either the shape or the data
1706 type of the arguments does not match. The special handling of scalars
1707 mentioned in the Notes section is disabled.
1708
1709 .. versionadded:: 2.0.0
1710
1711 Raises
1712 ------
1713 AssertionError
1714 If actual and desired are not equal up to specified precision.
1715
1716 See Also
1717 --------
1718 assert_array_almost_equal_nulp, assert_array_max_ulp
1719
1720 Notes
1721 -----
1722 When one of `actual` and `desired` is a scalar and the other is array_like, the
1723 function performs the comparison as if the scalar were broadcasted to the shape
1724 of the array. Note that empty arrays are therefore considered equal to scalars.
1725 This behaviour can be disabled by setting ``strict==True``.
1726
1727 Examples
1728 --------

Callers 15

test_gauss_invMethod · 0.90
test_uniform_doubleMethod · 0.90
test_uniform_floatMethod · 0.90
test_typical_casesMethod · 0.90
test_basicMethod · 0.90
test_complexMethod · 0.90
test_unary_PyUFuncMethod · 0.90
test_binary_PyUFuncMethod · 0.90

Calls 1

assert_array_compareFunction · 0.70

Tested by 15

test_gauss_invMethod · 0.72
test_uniform_doubleMethod · 0.72
test_uniform_floatMethod · 0.72
test_typical_casesMethod · 0.72
test_basicMethod · 0.72
test_complexMethod · 0.72
test_unary_PyUFuncMethod · 0.72
test_binary_PyUFuncMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…