Rate this Page

torch.addr#

torch.addr(input,vec1,vec2,*,beta=1,alpha=1,out=None)Tensor#

Performs the outer-product of vectorsvec1 andvec2and adds it to the matrixinput.

Optional valuesbeta andalpha are scaling factors on theouter product betweenvec1 andvec2 and the added matrixinput respectively.

out=β input+α (vec1vec2)\text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})

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

Ifvec1 is a vector of sizen andvec2 is a vectorof sizem, theninput must bebroadcastable with a matrix of size(n×m)(n \times m) andout will be a matrix of size(n×m)(n \times m).

Parameters
  • input (Tensor) – matrix to be added

  • vec1 (Tensor) – the first vector of the outer product

  • vec2 (Tensor) – the second vector of the outer product

Keyword Arguments

Example:

>>>vec1=torch.arange(1.,4.)>>>vec2=torch.arange(1.,3.)>>>M=torch.zeros(3,2)>>>torch.addr(M,vec1,vec2)tensor([[ 1.,  2.],        [ 2.,  4.],        [ 3.,  6.]])