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)
| 539 | |
| 540 | @np._no_nep50_warning() |
| 541 | def assert_approx_equal(actual, desired, significant=7, err_msg='', |
| 542 | verbose=True): |
| 543 | """ |
| 544 | Raises an AssertionError if two items are not equal up to significant |
| 545 | digits. |
| 546 | |
| 547 | .. note:: It is recommended to use one of `assert_allclose`, |
| 548 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
| 549 | instead of this function for more consistent floating point |
| 550 | comparisons. |
| 551 | |
| 552 | Given two numbers, check that they are approximately equal. |
| 553 | Approximately equal is defined as the number of significant digits |
| 554 | that agree. |
| 555 | |
| 556 | Parameters |
| 557 | ---------- |
| 558 | actual : scalar |
| 559 | The object to check. |
| 560 | desired : scalar |
| 561 | The expected object. |
| 562 | significant : int, optional |
| 563 | Desired precision, default is 7. |
| 564 | err_msg : str, optional |
| 565 | The error message to be printed in case of failure. |
| 566 | verbose : bool, optional |
| 567 | If True, the conflicting values are appended to the error message. |
| 568 | |
| 569 | Raises |
| 570 | ------ |
| 571 | AssertionError |
| 572 | If actual and desired are not equal up to specified precision. |
| 573 | |
| 574 | See Also |
| 575 | -------- |
| 576 | assert_allclose: Compare two array_like objects for equality with desired |
| 577 | relative and/or absolute precision. |
| 578 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
| 579 | |
| 580 | Examples |
| 581 | -------- |
| 582 | >>> np.testing.assert_approx_equal(0.12345677777777e-20, 0.1234567e-20) |
| 583 | >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345671e-20, |
| 584 | ... significant=8) |
| 585 | >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345672e-20, |
| 586 | ... significant=8) |
| 587 | Traceback (most recent call last): |
| 588 | ... |
| 589 | AssertionError: |
| 590 | Items are not equal to 8 significant digits: |
| 591 | ACTUAL: 1.234567e-21 |
| 592 | DESIRED: 1.2345672e-21 |
| 593 | |
| 594 | the evaluated condition that raises the exception is |
| 595 | |
| 596 | >>> abs(0.12345670e-20/1e-21 - 0.12345672e-20/1e-21) >= 10**-(8-1) |
| 597 | True |
| 598 |
nothing calls this directly
no test coverage detected