fn

addmv

Tensor
addmv(input: Tensor, mat: Tensor, vec: Tensor, beta: float = ..., alpha: float = ...)
source

Matrix-vector multiply with a scaled accumulator (BLAS-2 gemv).

Computes βinput+α(matvec)\beta \cdot \text{input} + \alpha \cdot (\text{mat} \cdot \text{vec}), the canonical BLAS-2 gemv operation.

Parameters

inputTensor
Accumulator vector of shape (M,).
matTensor
Matrix of shape (M, N).
vecTensor
Vector of shape (N,).
betafloat
Scalar multiplier on input. Defaults to 1.0.
alphafloat
Scalar multiplier on mat @ vec. Defaults to 1.0.

Returns

Tensor

Vector of shape (M,).

Notes

Mathematical definition:

outi=βinputi+αj=0N1matijvecj.\text{out}_i = \beta \cdot \text{input}_i + \alpha \cdot \sum_{j = 0}^{N - 1} \text{mat}_{ij} \cdot \text{vec}_j.

Implemented by promoting vec to a column (N, 1), calling lucid.matmul, and squeezing the trailing axis.

Examples

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