BUG: Fix the implementation of numpy.array_api.vecdot#21928
BUG: Fix the implementation of numpy.array_api.vecdot#21928seberg merged 2 commits intonumpy:mainfrom
Conversation
|
Seems OK, I think I slightly prefer the Plus the wrapping/unwrapping stuff. Or use |
|
OK, made it use moveaxis + matmul instead of einsum. |
| ndim = max(x1.ndim, x2.ndim) | ||
| x1_shape = (1,)*(ndim - x1.ndim) + tuple(x1.shape) | ||
| x2_shape = (1,)*(ndim - x2.ndim) + tuple(x2.shape) |
There was a problem hiding this comment.
This will go away with the change.
There was a problem hiding this comment.
Maybe this can be simplified, but without this, the shape checking is not correct (because size 1 dimensions broadcast).
Also, the broadcasting is necessary because, assuming I am understanding the idea in the spec correctly, nonnegative axis should refer to the broadcasted dimensions.
There was a problem hiding this comment.
You can move the checking to later and use -1 as axis. That probably gives you better errors for bad axis values anyway.
There was a problem hiding this comment.
I'm sorry, I'm not following your suggestion here.
There was a problem hiding this comment.
I am saying that you can do the check after the broadcast+moveaxis at the point where the axis is properly normalized to -1.
There was a problem hiding this comment.
I took the liberty to do that change, unless you disagree will merge next time around (or earlier with feedback).
numpy/array_api/linalg.py
Outdated
| x1_ = np.moveaxis(x1_, axis, -1) | ||
| x2_ = np.moveaxis(x2_, axis, -1) | ||
|
|
||
| if x1_shape[-1] != x2_shape[-1]: |
There was a problem hiding this comment.
You missed some dots here.
|
I guess the spec's a little ambiguous here, but my understanding is that vecdot should not broadcast along the specified We should probably figure out which behavior we want here and update the spec to be clearer. |
|
Just to note that we ignore the lint errors in the |
9d61d5e to
285084a
Compare
|
Yeah, I missed the boardcasting part, lets go with the previous version for now. |
|
Thanks @asmeurer, sorry I had lost track of this, lets put it in. |
* Fix the implementation of numpy.array_api.vecdot See https://data-apis.org/array-api/latest/API_specification/generated/signatures.linear_algebra_functions.vecdot.html * Use moveaxis + matmul instead of einsum in vecdot
See https://data-apis.org/array-api/latest/API_specification/generated/signatures.linear_algebra_functions.vecdot.html