torch / torch
torch.addr¶
-
torch.
addr
(input, vec1, vec2, *, beta=1, alpha=1, out=None) → Tensor¶ Performs the outer-product of vectors
vec1
andvec2
and adds it to the matrixinput
.Optional values
beta
andalpha
are scaling factors on the outer product betweenvec1
andvec2
and the added matrixinput
respectively.If
beta
is 0, theninput
will be ignored, and nan and inf in it will not be propagated.If
vec1
is a vector of size n andvec2
is a vector of size m, theninput
must be broadcastable with a matrix of size andout
will be a matrix of size .For inputs of type FloatTensor or DoubleTensor, arguments
beta
andalpha
must be real numbers, otherwise they should be integersWarning
This function is deprecated and may be removed in a future release. It can be implemented using
torch.outer()
asalpha * torch.outer(vec1, vec2) + beta * input
whenbeta
is not zero, and asalpha * torch.outer(vec1, vec2)
whenbeta
is zero.- Parameters
- Keyword Arguments
beta (Number, optional) – multiplier for
input
( )alpha (Number, optional) – multiplier for ( )
out (Tensor, optional) – the output tensor.
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.]])
此页内容是否对您有帮助