From f7766b40b64c83a328916de92362cd5d98febb32 Mon Sep 17 00:00:00 2001 From: mattip Date: Mon, 30 Apr 2018 18:13:10 +0300 Subject: ENH: test, document, implement flexible signature. Goal is allow signatures like (m?,n),(n,p?)->(m?,p?) for matmul. --- doc/source/reference/c-api.generalized-ufuncs.rst | 51 +++++++++++++++-------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'doc/source/reference') diff --git a/doc/source/reference/c-api.generalized-ufuncs.rst b/doc/source/reference/c-api.generalized-ufuncs.rst index dd8cf6558..59aa11d00 100644 --- a/doc/source/reference/c-api.generalized-ufuncs.rst +++ b/doc/source/reference/c-api.generalized-ufuncs.rst @@ -127,34 +127,49 @@ The formal syntax of signatures is as follows:: ::= ::= nil | | "," ::= "(" ")" - ::= nil | | - "," - ::= valid Python variable name - + ::= nil | | + "," + ::= + ::= valid Python variable name | valid integer + ::= nil | "?" Notes: #. All quotes are for clarity. -#. Core dimensions that share the same name must have the exact same size. +#. Unmodified core dimensions that share the same name must have the same size. Each dimension name typically corresponds to one level of looping in the elementary function's implementation. #. White spaces are ignored. +#. An integer as a dimension name freezes that dimension to the value. +#. If the name is suffixed with the "?" modifier, the dimension is a core + dimension only if it exists on all inputs and outputs that share it; + otherwise it is ignored (and replaced by a dimension of size 1 for the + elementary function). Here are some examples of signatures: -+-------------+------------------------+-----------------------------------+ -| add | ``(),()->()`` | | -+-------------+------------------------+-----------------------------------+ -| inner1d | ``(i),(i)->()`` | | -+-------------+------------------------+-----------------------------------+ -| sum1d | ``(i)->()`` | | -+-------------+------------------------+-----------------------------------+ -| dot2d | ``(m,n),(n,p)->(m,p)`` | matrix multiplication | -+-------------+------------------------+-----------------------------------+ -| outer_inner | ``(i,t),(j,t)->(i,j)`` | inner over the last dimension, | -| | | outer over the second to last, | -| | | and loop/broadcast over the rest. | -+-------------+------------------------+-----------------------------------+ ++-------------+----------------------------+-----------------------------------+ +| add | ``(),()->()`` | | ++-------------+----------------------------+-----------------------------------+ +| sum1d | ``(i)->()`` | | ++-------------+----------------------------+-----------------------------------+ +| inner1d | ``(i),(i)->()`` | | ++-------------+----------------------------+-----------------------------------+ +| matmat | ``(m,n),(n,p)->(m,p)`` | matrix multiplication | ++-------------+----------------------------+-----------------------------------+ +| vecmat | ``(n),(n,p)->(p)`` | vector-matrix multiplication | ++-------------+----------------------------+-----------------------------------+ +| matvec | ``(m,n),(n)->(m)`` | matrix-vector multiplication | ++-------------+----------------------------+-----------------------------------+ +| matmul | ``(m?,n),(n,p?)->(m?,p?)`` | combination of the four above | ++-------------+----------------------------+-----------------------------------+ +| cross1d | ``(3),(3)->(3)`` | cross product where the last | +| | | dimension must be 3 | ++-------------+----------------------------+-----------------------------------+ +| outer_inner | ``(i,t),(j,t)->(i,j)`` | inner over the last dimension, | +| | | outer over the second to last, | +| | | and loop/broadcast over the rest. | ++-------------+----------------------------+-----------------------------------+ C-API for implementing Elementary Functions ------------------------------------------- -- cgit v1.2.1