8000 Comparing numpy:main...pv:numpyufunc-binop-subclass-fix · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: numpy/numpy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: pv/numpy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: numpyufunc-binop-subclass-fix
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 24, 2014

  1. BUG: core: ensure binop execution uses ufuncs as fallback

    These changes only affect objects defining __numpy_ufunc__. Other
    objects use the __array_priority__ mechanism to decide whether
    NotImplemented should be returned or not.
    
    The binops previously returned NotImplemented even if other._r<op>__ is
    ndarray.__r<op>__, rather than trying to evaluate the result via ufuncs.
    This causes problems in binops of two objects that both subclass from
    ndarray and define __numpy_ufunc__.
    
    The solution added here makes the total logic as follows:
    
        def __binop__(self, other):
            if (hasattr(other, '__numpy_ufunc__') and
                not isinstance(other, self.__class__) and
                hasattr(other, '__rop__') and
                other.__class__.__rop__ is not self.__class__.__rop__):
                return NotImplemented
            return np.binop(self, other)
    pv committed Jul 24, 2014
    Configuration menu
    Copy the full SHA
    9ef3687 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4617e4c View commit details
    Browse the repository at this point in the history
Loading
0