PyTorch torch.addcmul Function
PyTorch torch reference manual
torch.addcmul is a function in PyTorch used to perform input + value * (tensor1 * tensor2) element-wise operations.
Function definition
torch.addcmul(input, tensor1, tensor2, value=1, out=None)
Parameter Description
input: the input tensortensor1: the first multiplier tensortensor2: the second multiplier tensorvalue: the multiplier, defaulting to 1out: the output tensor (optional)
Usage examples
Example
import
torch
Creating tensors
input
=
torch.
tensor
(
[
1.0
,
2.0
,
3.0
]
)
tensor1
=
torch.
tensor
(
[
2.0
,
3.0
,
4.0
]
)
tensor2
=
torch.
tensor
(
[
3.0
,
4.0
,
5.0
]
)
Perform input + value * (tensor1 * tensor2)
result
=
torch.
addcmul
(
input
,
tensor1
,
tensor2
,
value
=
1
)
(
result
)
The output is:
tensor([ 7., 14., 23.])