Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations.
(x, y, func=isnan, hasval="nan")
| 574 | ox, oy = x, y |
| 575 | |
| 576 | def func_assert_same_pos(x, y, func=isnan, hasval="nan"): |
| 577 | """Handling nan/inf. |
| 578 | |
| 579 | Combine results of running func on x and y, checking that they are True |
| 580 | at the same locations. |
| 581 | |
| 582 | """ |
| 583 | __tracebackhide__ = True # Hide traceback for py.test |
| 584 | x_id = func(x) |
| 585 | y_id = func(y) |
| 586 | # We include work-arounds here to handle three types of slightly |
| 587 | # pathological ndarray subclasses: |
| 588 | # (1) all() on `masked` array scalars can return masked arrays, so we |
| 589 | # use != True |
| 590 | # (2) __eq__ on some ndarray subclasses returns Python booleans |
| 591 | # instead of element-wise comparisons, so we cast to bool_() and |
| 592 | # use isinstance(..., bool) checks |
| 593 | # (3) subclasses with bare-bones __array_function__ implementations may |
| 594 | # not implement np.all(), so favor using the .all() method |
| 595 | # We are not committed to supporting such subclasses, but it's nice to |
| 596 | # support them if possible. |
| 597 | if (x_id == y_id).all().item() is not True: |
| 598 | msg = build_err_msg( |
| 599 | [x, y], |
| 600 | err_msg + "\nx and y %s location mismatch:" % (hasval), |
| 601 | verbose=verbose, |
| 602 | header=header, |
| 603 | names=("x", "y"), |
| 604 | precision=precision, |
| 605 | ) |
| 606 | raise AssertionError(msg) |
| 607 | # If there is a scalar, then here we know the array has the same |
| 608 | # flag as it everywhere, so we should return the scalar flag. |
| 609 | if isinstance(x_id, bool) or x_id.ndim == 0: |
| 610 | return bool_(x_id) |
| 611 | elif isinstance(y_id, bool) or y_id.ndim == 0: |
| 612 | return bool_(y_id) |
| 613 | else: |
| 614 | return y_id |
| 615 | |
| 616 | try: |
| 617 | if strict: |
no test coverage detected
searching dependent graphs…