Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-02 Thread Marten van Kerkwijk
Hi Matti, In the original implementation of what was then __numpy_ufunc__, we had overrides for both `np.dot` and `np.matmul` that worked exactly as your option (2), but we decided in the end that those really are not true ufuncs and we should not include ufunc mimics in the mix as someone using `

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-02 Thread Matti Picus
On 01/05/18 21:08, Marten van Kerkwijk wrote: Just for completeness: there are *four* gufuncs (matmat, matvec, vecmat, and vecvec). I remain torn about the best way forward. The main argument against using them inside matmul is that in order to decide which of the four to use, matmul has to have

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-02 Thread Stephan Hoyer
On Wed, May 2, 2018 at 8:39 AM Marten van Kerkwijk < m.h.vankerkw...@gmail.com> wrote: > I think we should not decide too readily on what is "reasonable" to > expect for a ufunc input. > I agree strongly with this. I can think of a couple of other use-cases off hand: - xarray.Dataset is a dict-l

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-02 Thread Marten van Kerkwijk
On Wed, May 2, 2018 at 6:24 AM, Hameer Abbasi wrote: > There is always the option of any downstream object overriding matmul, and I > fail to see which objects won't have a shape. - Hameer I think we should not decide too readily on what is "reasonable" to expect for a ufunc input. For instance,

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-02 Thread Hameer Abbasi
There is always the option of any downstream object overriding matmul, and I fail to see which objects won't have a shape. - Hameer On 01/05/2018 at 21:08, Marten wrote: Just for completeness: there are *four* gufuncs (matmat, matvec, vecmat, and vecvec). I remain torn about the best way forwar

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-01 Thread Marten van Kerkwijk
Just for completeness: there are *four* gufuncs (matmat, matvec, vecmat, and vecvec). I remain torn about the best way forward. The main argument against using them inside matmul is that in order to decide which of the four to use, matmul has to have access to the `shape` of the arguments. This me

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-01 Thread Matti Picus
On 01/05/18 00:38, Eric Wieser wrote: I think I’m -1 on this - this just makes things harder on the implementers of |_array_ufunc__| who now might have to work out which signature matches. I’d prefer the solution where |np.matmul| is a wrapper around one of three gufuncs (or maybe just around

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-05-01 Thread Hameer Abbasi
I agree with Eric here. As one of the users of __array_ufunc__, I'd much rather have three separate gufuncs or a single one with axis insertion and removal. On 30/04/2018 at 23:38, Eric wrote: I think I’m -1 on this - this just makes things harder on the implementers of _array_ufunc__ who now might

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-04-30 Thread Matti Picus
On 01/05/18 01:45, Allan Haldane wrote: On 04/29/2018 05:46 AM, Matti Picus wrote: In looking to solve issue #9028 "no way to override matmul/@ if __array_ufunc__ is set", it seems there is consensus around the idea of making matmul a true gufunc, but matmul can behave differently for differen

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-04-30 Thread Allan Haldane
On 04/29/2018 05:46 AM, Matti Picus wrote: > In looking to solve issue #9028 "no way to override matmul/@ if > __array_ufunc__ is set", it seems there is consensus around the idea of > making matmul a true gufunc, but matmul can behave differently for > different combinations of array and vector: >

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-04-30 Thread Eric Wieser
I think I’m -1 on this - this just makes things harder on the implementers of _array_ufunc__ who now might have to work out which signature matches. I’d prefer the solution where np.matmul is a wrapper around one of three gufuncs (or maybe just around one with axis insertion) - this is similar to h

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-04-30 Thread Stephan Hoyer
On Sun, Apr 29, 2018 at 2:48 AM Matti Picus wrote: > The proposed solution to issue #9029 is to extend the meaning of a > signature so "syntax like (n?,k),(k,m?)->(n?,m?) could mean that n and m > are optional dimensions; if missing in the input, they're treated as 1, and > then dropped from the

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-04-30 Thread Marten van Kerkwijk
I thought a bit further about this proposal: a disadvantage for matmul specifically is that is does not solve the need for `matvec`, `vecmat`, and `vecvec` gufuncs. That said, it might make sense to implement those as "pseudo-ufuncs" that just add a 1 in the right place and call `matmul`... -- Mart

Re: [Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-04-29 Thread Marten van Kerkwijk
Hi Matti, This sounds great. For completeness, you omitted the vector-vector case for matmul '(k),(k)->()' - but the suggested new signature for `matmul` would cover that case as well, so not a problem. All the best, Marten ___ NumPy-Discussion mailing

[Numpy-discussion] Extending ufunc signature syntax for matmul, frozen dimensions

2018-04-29 Thread Matti Picus
In looking to solve issue #9028 "no way to override matmul/@ if __array_ufunc__ is set", it seems there is consensus around the idea of making matmul a true gufunc, but matmul can behave differently for different combinations of array and vector: (n,k),(k,m)->(n,m) (n,k),(k) -> (n) (k),(k,m)->