diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2018-06-01 17:14:32 -0400 |
---|---|---|
committer | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2018-07-17 17:12:35 -0400 |
commit | ea0322bd6310462c1485ce82ff08775816f7b3a6 (patch) | |
tree | 0d49321fa811e479ae5d2b3b04a00cff84c895b9 /doc | |
parent | 472c7e9b41df6463b47d4ed2883e6c5571c9967f (diff) | |
download | numpy-ea0322bd6310462c1485ce82ff08775816f7b3a6.tar.gz |
DOC: Release note for flexible dimensions.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/release/1.16.0-notes.rst | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/release/1.16.0-notes.rst b/doc/release/1.16.0-notes.rst index 1fd4a17e6..c264d4ad8 100644 --- a/doc/release/1.16.0-notes.rst +++ b/doc/release/1.16.0-notes.rst @@ -77,6 +77,30 @@ differently from variable ones indicated with a name starting with a letter; the loop still is passed the corresponding size, but it can now count on that size being equal to the fixed one given in the signature. +Generalized ufunc signatures now allow flexible dimensions +---------------------------------------------------------- + +Some functions, in particular numpy's implementation of ``@`` as ``matmul``, +are very similar to generalized ufuncs in that they operate over core +dimensions, but one could not present them as such because they were able to +deal with inputs in which a dimension is missing. To support this, it is now +allowed to postfix 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)->()``. + Changes ======= |