Rate this Page

torch.addmv#

torch.addmv(input,mat,vec,*,beta=1,alpha=1,out=None)Tensor#

Performs a matrix-vector product of the matrixmat andthe vectorvec.The vectorinput is added to the final result.

Ifmat is a(n×m)(n \times m) tensor,vec is a 1-D tensor ofsizem, theninput must bebroadcastable with a 1-D tensor of sizen andout will be 1-D tensor of sizen.

alpha andbeta are scaling factors on matrix-vector product betweenmat andvec and the added tensorinput respectively.

out=β input+α (mat@vec)\text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})

Ifbeta is 0, then the content ofinput will be ignored, andnan andinf init will not be propagated.

For inputs of typeFloatTensor orDoubleTensor, argumentsbeta 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 forinput (β\beta)

  • alpha (Number,optional) – multiplier format@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])