Shortcuts

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

Performs the outer-product of vectors vec1 and vec2 and adds it to the matrix input.

Optional values beta and alpha are scaling factors on the outer product between vec1 and vec2 and the added matrix input respectively.

$\text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})$

If beta is 0, then input will be ignored, and nan and inf in it will not be propagated.

If vec1 is a vector of size n and vec2 is a vector of size m, then input must be broadcastable with a matrix of size $(n \times m)$ and out will be a matrix of size $(n \times m)$ .

For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers

Warning

This function is deprecated and may be removed in a future release. It can be implemented using torch.outer() as alpha * torch.outer(vec1, vec2) + beta * input when beta is not zero, and as alpha * torch.outer(vec1, vec2) when beta is zero.

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
• beta (Number, optional) – multiplier for input ($\beta$ )

• alpha (Number, optional) – multiplier for $\text{vec1} \otimes \text{vec2}$ ($\alpha$ )

• out (Tensor, optional) – the output tensor.

Example:

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


## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials