API: Set __array_priority__ for MatrixExpr and MatrixExprCons
#1172
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The subclass of
np.ndarrayuses__array_priority__to decide the priority.If we have
a(np.ndarray),b(MatrixExpr), andc(MatrixExprCons).Without setting
__array_priority__,__array_priority__are 0.0.The priority is the same. And the operation will be called from left to right.
So we call
a >= b, it will bea.__ge__(b). Calla + b, it will bea.__add__(b).With setting
__array_priority__. The operation will call the bigger one.So we call
a >= b, it will beb.__le__(a). Calla + b, it will beb.__radd__(a).This is useful for
a + c. It could skipa.__add__(c). And callc.__radd__(a)directly and raise NotImplementError.See
numpy.class.__array_priority__