Skip to content
fn

inner

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

Implementing kernel

C++ engine symbols that back this Python API.

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

Tensors whose last dimensions match.
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…,k y…′,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 stay independent and come out consecutively. A 0-d operand has no axis to contract: the result is x * y, with that product's dtype promotion.

Examples

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