fn

vecdot

Tensor
vecdot(x: Tensor, y: Tensor, dim: int = -1)
source

Compute a batched vector dot product along an axis.

Reduces the chosen axis with a sum of element-wise products:

(xy)=kx,k,y,k,.(x \cdot y)_{\ldots} \,=\, \sum_{k} x_{\ldots, k, \ldots}\, y_{\ldots, k, \ldots}.

Parameters

xTensor
First operand.
yTensor
Second operand, broadcast-compatible with x.
dimint= -1
Axis to contract. Default -1.

Returns

Tensor

Reduced tensor with dim removed.

Notes

Equivalent to (x * y).sum(dim=dim). Useful for computing many independent dot products in one shot (e.g., per-row inner products of two matrices).

Examples

>>> import lucid
>>> from lucid.linalg import vecdot
>>> x = lucid.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
>>> y = lucid.tensor([[1.0, 0.0, -1.0], [0.0, 1.0, 0.0]])
>>> vecdot(x, y)
Tensor([-2.0000,  5.0000])