PyTorch torch.addcmul Function
Pytorch torch Reference Manual
torch.addcmulIs a function in PyTorch used to performinput + value * (tensor1 * tensor2)element-wise operations.
Function Definition
torch.addcmul(input, tensor1, tensor2, value=1, out=None)
Parameter Description
input: input tensortensor1: first multiplier tensortensor2: second multiplier tensorvalue: multiplier, defaults to 1out: output tensor (optional)
Usage Example
Example
import torch
# Create tensor
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])
# Execute input + value * (tensor1 * tensor2)
result = torch.addcmul(input, tensor1, tensor2, value=1)
print(result)
# Create tensor
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])
# Execute input + value * (tensor1 * tensor2)
result = torch.addcmul(input, tensor1, tensor2, value=1)
print(result)
The output is:
tensor([ 7., 14., 23.])
Other Extensions