fn

inner

Tensor
inner(x: Tensor, y: Tensor)
source

Inner product over the last axes of two tensors.

Behaves like dot for 1-D inputs and like a generalised outer-then-contract for higher ranks.

Parameters

xTensor
Tensors whose last dimensions match.
yTensor
Tensors whose last dimensions match.

Returns

Tensor

Result with shape x.shape[:-1] + y.shape[:-1].

Notes

Contracts the last axis of both operands and sums:

inner(x,y),=kx,ky,k.\mathrm{inner}(x, y)_{\ldots, \ldots'} \,=\, \sum_{k} x_{\ldots, k}\, y_{\ldots', k}.

For 1-D inputs, this is the standard vector dot product. For higher ranks the leading axes of x and y are kept independent and appear consecutively in the output — handy for batched dot products when the contraction axis is the trailing one.

Examples

>>> import lucid
>>> from lucid.linalg import inner
>>> inner(lucid.tensor([1.0, 2.0]), lucid.tensor([3.0, 4.0]))
Tensor(11.0)