fn

mv

Tensor
mv(mat: Tensor, vec: Tensor)
source

Matrix-vector product.

Computes the standard matrix-vector product y=Mvy = M v. Equivalent to M @ v for 2-D / 1-D inputs.

Parameters

matTensor
2-D matrix of shape (M, N).
vecTensor
1-D vector of shape (N,).

Returns

Tensor

1-D tensor of shape (M,).

Notes

Element-wise definition:

yi=j=0N1matijvecj.y_i = \sum_{j = 0}^{N - 1} \text{mat}_{ij} \cdot \text{vec}_j.

Implemented by promoting vec to a column vector, calling lucid.matmul, and then squeezing the trailing axis. Dispatches to BLAS-2 gemv on the CPU stream and the matmul kernel on the GPU stream.

Examples

>>> import lucid
>>> M = lucid.tensor([[1., 2.], [3., 4.]])
>>> v = lucid.tensor([5., 6.])
>>> lucid.mv(M, v)
Tensor([17., 39.])