Raises an AssertionError if two items are not equal up to significant digits. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point
(actual, desired, significant=7, err_msg='',
verbose=True)
| 637 | |
| 638 | |
| 639 | def assert_approx_equal(actual, desired, significant=7, err_msg='', |
| 640 | verbose=True): |
| 641 | """ |
| 642 | Raises an AssertionError if two items are not equal up to significant |
| 643 | digits. |
| 644 | |
| 645 | .. note:: It is recommended to use one of `assert_allclose`, |
| 646 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
| 647 | instead of this function for more consistent floating point |
| 648 | comparisons. |
| 649 | |
| 650 | Given two numbers, check that they are approximately equal. |
| 651 | Approximately equal is defined as the number of significant digits |
| 652 | that agree. |
| 653 | |
| 654 | Parameters |
| 655 | ---------- |
| 656 | actual : scalar |
| 657 | The object to check. |
| 658 | desired : scalar |
| 659 | The expected object. |
| 660 | significant : int, optional |
| 661 | Desired precision, default is 7. |
| 662 | err_msg : str, optional |
| 663 | The error message to be printed in case of failure. |
| 664 | verbose : bool, optional |
| 665 | If True, the conflicting values are appended to the error message. |
| 666 | |
| 667 | Raises |
| 668 | ------ |
| 669 | AssertionError |
| 670 | If actual and desired are not equal up to specified precision. |
| 671 | |
| 672 | See Also |
| 673 | -------- |
| 674 | assert_allclose: Compare two array_like objects for equality with desired |
| 675 | relative and/or absolute precision. |
| 676 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
| 677 | |
| 678 | Examples |
| 679 | -------- |
| 680 | >>> np.testing.assert_approx_equal(0.12345677777777e-20, 0.1234567e-20) |
| 681 | >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345671e-20, |
| 682 | ... significant=8) |
| 683 | >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345672e-20, |
| 684 | ... significant=8) |
| 685 | Traceback (most recent call last): |
| 686 | ... |
| 687 | AssertionError: |
| 688 | Items are not equal to 8 significant digits: |
| 689 | ACTUAL: 1.234567e-21 |
| 690 | DESIRED: 1.2345672e-21 |
| 691 | |
| 692 | the evaluated condition that raises the exception is |
| 693 | |
| 694 | >>> abs(0.12345670e-20/1e-21 - 0.12345672e-20/1e-21) >= 10**-(8-1) |
| 695 | True |
| 696 |
searching dependent graphs…