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

Function func_assert_same_pos

numpy/testing/_private/utils.py:661–696  ·  view source on GitHub ↗

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')

Source from the content-addressed store, hash-verified

659 return x.dtype.char in "Mm"
660
661 def func_assert_same_pos(x, y, func=isnan, hasval='nan'):
662 """Handling nan/inf.
663
664 Combine results of running func on x and y, checking that they are True
665 at the same locations.
666
667 """
668 __tracebackhide__ = True # Hide traceback for py.test
669
670 x_id = func(x)
671 y_id = func(y)
672 # We include work-arounds here to handle three types of slightly
673 # pathological ndarray subclasses:
674 # (1) all() on `masked` array scalars can return masked arrays, so we
675 # use != True
676 # (2) __eq__ on some ndarray subclasses returns Python booleans
677 # instead of element-wise comparisons, so we cast to bool_() and
678 # use isinstance(..., bool) checks
679 # (3) subclasses with bare-bones __array_function__ implementations may
680 # not implement np.all(), so favor using the .all() method
681 # We are not committed to supporting such subclasses, but it's nice to
682 # support them if possible.
683 if bool_(x_id == y_id).all() != True:
684 msg = build_err_msg([x, y],
685 err_msg + '\nx and y %s location mismatch:'
686 % (hasval), verbose=verbose, header=header,
687 names=('x', 'y'), precision=precision)
688 raise AssertionError(msg)
689 # If there is a scalar, then here we know the array has the same
690 # flag as it everywhere, so we should return the scalar flag.
691 if isinstance(x_id, bool) or x_id.ndim == 0:
692 return bool_(x_id)
693 elif isinstance(y_id, bool) or y_id.ndim == 0:
694 return bool_(y_id)
695 else:
696 return y_id
697
698 try:
699 if strict:

Callers 1

assert_array_compareFunction · 0.85

Calls 3

build_err_msgFunction · 0.85
funcFunction · 0.50
allMethod · 0.45

Tested by

no test coverage detected