[Numpy-discussion] Bringing order to higher dimensional operations

Stéfan van der Walt stefan at sun.ac.za
Fri Jul 19 11:36:56 EDT 2013


On Fri, Jul 19, 2013 at 5:31 PM, Nathaniel Smith <njs at pobox.com> wrote:
> 3) Extend the gufunc machinery to understand the idea that some core
> dimensions are allowed to take on a special "nonexistent" size. So the
> signature for dot would be:
>   (m*,k) x (k, n*) -> (m*, n*)
> where '*' denotes dimensions who are allowed to take on the
> "nonexistent" size if necessary. So dot(ones((2, 3)), ones((3, 4)))
> would have
>   m = 2
>   k = 3
>   n = 4
> and produce an output with shape (m, n) = (2, 4). But dot(ones((2,
> 3)), ones((3,))) would have
>   m = 2
>   k = 3
>   n = <nothing>
> and produce an output with shape (m, n) = (2, <nothing>) = (2,). And
> dot(ones((3,)), ones((3,))) would have
>   m = <nothing>
>   k = 3
>   n = <nothing>
> and produce an output with shape (m, n) = (<nothing>, <nothing>) = (),
> i.e., dot(vector, vector) would return a scalar.

This looks like a fairly clean solution; it could be implemented in a
shape pre- and post-processing step, where we pad the array dimensions
to match the full signature, and remove it again afterwards.

Stéfan



More information about the NumPy-Discussion mailing list