fn

addcmul

Tensor
addcmul(input: Tensor, t1: Tensor, t2: Tensor, value: float = ...)
source

Element-wise fused multiply-add with a scalar weight.

Computes input+value(t1t2)\text{input} + \text{value} \cdot (t_1 \odot t_2) element-wise, where \odot denotes the Hadamard (element-wise) product. Provided as a single named op for readability and to give the dispatcher the chance to fuse the three steps into one kernel on backends that support it.

Parameters

inputTensor
Tensor that is added to the scaled element-wise product.
t1Tensor
Left operand of the element-wise product. Must broadcast with input and t2.
t2Tensor
Right operand of the element-wise product. Must broadcast with input and t1.
valuefloat
Scalar multiplier applied to the product t1 * t2 before addition. Defaults to 1.0 (plain multiply-and-add).

Returns

Tensor

Element-wise result with the broadcast shape of the three input tensors.

Notes

Mathematical definition:

outi=inputi+value(t1,it2,i).\text{out}_i = \text{input}_i + \text{value} \cdot (t_{1,i} \cdot t_{2,i}).

Sister op of addcdiv (input + value * t1 / t2). Common in optimisers (e.g. running-mean / running-variance updates) where a bias-correction term is added to an existing accumulator.

Examples

>>> import lucid
>>> a = lucid.tensor([1.0, 2.0, 3.0])
>>> b = lucid.tensor([4.0, 5.0, 6.0])
>>> c = lucid.tensor([0.5, 0.5, 0.5])
>>> lucid.addcmul(a, b, c, value=2.0)
Tensor([5., 7., 9.])