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

Function assert_allclose

numpy/testing/_private/utils.py:1438–1505  ·  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)

Source from the content-addressed store, hash-verified

1436
1437
1438def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,
1439 err_msg='', verbose=True):
1440 """
1441 Raises an AssertionError if two objects are not equal up to desired
1442 tolerance.
1443
1444 Given two array_like objects, check that their shapes and all elements
1445 are equal (but see the Notes for the special handling of a scalar). An
1446 exception is raised if the shapes mismatch or any values conflict. In
1447 contrast to the standard usage in numpy, NaNs are compared like numbers,
1448 no assertion is raised if both objects have NaNs in the same positions.
1449
1450 The test is equivalent to ``allclose(actual, desired, rtol, atol)`` (note
1451 that ``allclose`` has different default values). It compares the difference
1452 between `actual` and `desired` to ``atol + rtol * abs(desired)``.
1453
1454 .. versionadded:: 1.5.0
1455
1456 Parameters
1457 ----------
1458 actual : array_like
1459 Array obtained.
1460 desired : array_like
1461 Array desired.
1462 rtol : float, optional
1463 Relative tolerance.
1464 atol : float, optional
1465 Absolute tolerance.
1466 equal_nan : bool, optional.
1467 If True, NaNs will compare equal.
1468 err_msg : str, optional
1469 The error message to be printed in case of failure.
1470 verbose : bool, optional
1471 If True, the conflicting values are appended to the error message.
1472
1473 Raises
1474 ------
1475 AssertionError
1476 If actual and desired are not equal up to specified precision.
1477
1478 See Also
1479 --------
1480 assert_array_almost_equal_nulp, assert_array_max_ulp
1481
1482 Notes
1483 -----
1484 When one of `actual` and `desired` is a scalar and the other is
1485 array_like, the function checks that each element of the array_like
1486 object is equal to the scalar.
1487
1488 Examples
1489 --------
1490 >>> x = [1e-5, 1e-3, 1e-1]
1491 >>> y = np.arccos(np.cos(x))
1492 >>> np.testing.assert_allclose(x, y, rtol=1e-5, atol=0)
1493
1494 """
1495 __tracebackhide__ = True # Hide traceback for py.test

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