[Numpy-discussion] matmul as a ufunc

Matti Picus matti.picus at gmail.com
Mon May 21 20:42:33 EDT 2018


I have made progress with resolving the issue that matmul, the operation 
which implements `a @ b`, is not a ufunc [2]. Discussion on the issue, 
which prevents the __array_ufunc__ mechanism for overriding matmul on 
subclasses of ndarray, yeilded two approaches:

- create a wrapper that can convince the ufunc mechanism to call 
__array_ufunc__ even on functions that are not true ufuncs

- expand the semantics of core signatures so that a single matmul ufunc 
can implement matrix-matrix, vector-matrix, matrix-vector, and 
vector-vector multiplication.

I have put up prototypes of both approaches as pr 11061 [0] and 11133 
[1], they are WIP to prove the concept and are a bit rough. Either 
approach can be made to work.

Which is preferable?

What are the criteria we should use to judge the relative merits 
(backward compatibility, efficiency, code clarity, enabling further 
enhancements, ...) of the approaches?

Matti

[0] https://github.com/numpy/numpy/pull/11061
[1] https://github.com/numpy/numpy/pull/11133
[2] https://github.com/numpy/numpy/issues/9028


More information about the NumPy-Discussion mailing list