Possibly missing dimensions. This part is almost entirely driven by the wish to wrap matmul
in a gufunc. matmul
stands for matrix multiplication, and if it did only that, it could be covered with the signature (m,n),(n,p)->(m,p)
. However, it has special cases for when a dimension is missing, allowing either argument to be treated as a single vector, with the function thus becoming, effectively, vector-matrix, matrix-vector, or vector-vector multiplication (but with no broadcasting). To support this, it is suggested to allow postfixing a dimension name with a question mark to indicate that the dimension does not necessarily have to be present.
With this addition, the signature for matmul
can be expressed as (m?,n),(n,p?)->(m?,p?)
. This indicates that if, e.g., the second operand has only one dimension, for the purposes of the elementary function it will be treated as if that input has core shape (n, 1)
, and the output has the corresponding core shape of (m, 1)
. The actual output array, however, has the flexible dimension removed, i.e., it will have shape (..., m)
. Similarly, if both arguments have only a single dimension, the inputs will be presented as having shapes (1, n)
and (n, 1)
to the elementary function, and the output as (1, 1)
, while the actual output array returned will have shape ()
. In this way, the signature allows one to use a single elementary function for four related but different signatures, (m,n),(n,p)->(m,p)
, (n),(n,p)->(p)
, (m,n),(n)->(m)
and (n),(n)->()
.