Skip to content

BUG: vecdot does not conjugate first element #200

Closed
@mhvk

Description

@mhvk

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions