Skip to content

BUG: vecdot does not conjugate first element #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mhvk opened this issue Nov 19, 2024 · 0 comments · Fixed by #201
Closed

BUG: vecdot does not conjugate first element #200

mhvk opened this issue Nov 19, 2024 · 0 comments · Fixed by #201

Comments

@mhvk
Copy link

mhvk commented Nov 19, 2024

The implementation for vecdot should conjugate its first argument for complex numbers, but unfortunately the present implementation does not:

def vecdot(x1: ndarray, x2: ndarray, /, xp, *, axis: int = -1) -> ndarray:
if x1.shape[axis] != x2.shape[axis]:
raise ValueError("x1 and x2 must have the same size along the given axis")
if hasattr(xp, 'broadcast_tensors'):
_broadcast = xp.broadcast_tensors
else:
_broadcast = xp.broadcast_arrays
x1_ = xp.moveaxis(x1, axis, -1)
x2_ = xp.moveaxis(x2, axis, -1)
x1_, x2_ = _broadcast(x1_, x2_)
res = x1_[..., None, :] @ x2_[..., None]
return res[..., 0, 0]

p.s. Found this while implementing a new quantity class that uses the array API to handle any type of array that can be passed in -- array_api_compat has been a great boon!

p.s.2 I found the problem for dask, which actually seems to be able to handle np.vecdot fine (and give the correct answer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant