fn
addcmul
→Tensoraddcmul(input: Tensor, t1: Tensor, t2: Tensor, value: float = ...)Element-wise fused multiply-add with a scalar weight.
Computes element-wise, where 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
inputTensorTensor that is added to the scaled element-wise product.
t1TensorLeft operand of the element-wise product. Must broadcast with
input and t2.t2TensorRight operand of the element-wise product. Must broadcast with
input and t1.valuefloatScalar multiplier applied to the product
t1 * t2 before
addition. Defaults to 1.0 (plain multiply-and-add).Returns
TensorElement-wise result with the broadcast shape of the three input tensors.
Notes
Mathematical definition:
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.])