torch.addmv — PyTorch 2.7 documentation (original) (raw)
torch.addmv(input, mat, vec, *, beta=1, alpha=1, out=None) → Tensor¶
Performs a matrix-vector product of the matrix mat
and the vector vec
. The vector input
is added to the final result.
If mat
is a (n×m)(n \times m) tensor, vec
is a 1-D tensor of size m, then input
must bebroadcastable with a 1-D tensor of size n andout
will be 1-D tensor of size n.
alpha
and beta
are scaling factors on matrix-vector product betweenmat
and vec
and the added tensor input
respectively.
out=β input+α (mat@vec)\text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
If beta
is 0, then the content of input
will be ignored, and nan and inf in it will not be propagated.
For inputs of type FloatTensor or DoubleTensor, arguments beta
andalpha
must be real numbers, otherwise they should be integers.
Parameters
- input (Tensor) – vector to be added
- mat (Tensor) – matrix to be matrix multiplied
- vec (Tensor) – vector to be matrix multiplied
Keyword Arguments
- beta (Number , optional) – multiplier for
input
(β\beta) - alpha (Number , optional) – multiplier for mat@vecmat @ vec (α\alpha)
- out (Tensor, optional) – the output tensor.
Example:
M = torch.randn(2) mat = torch.randn(2, 3) vec = torch.randn(3) torch.addmv(M, mat, vec) tensor([-0.3768, -5.5565])