fn

add

Tensor
add(input: Tensor, other: Tensor | Scalar)
source

Element-wise addition with broadcasting and dtype promotion.

Computes input + other element-wise. Scalars are promoted to a tensor of matching dtype; tensors with different shapes are broadcast following the standard rules. Mixed-dtype operands are promoted to their common type prior to the operation.

Parameters

inputTensor
Left operand.
otherTensor or scalar
Right operand. Broadcasts against input following the standard broadcasting rules; Python scalars are promoted to a tensor of matching dtype.

Returns

Tensor

Element-wise result with shape broadcast(input.shape, other.shape) and dtype determined by the usual type-promotion rules.

Notes

Mathematical definition:

outi=inputi+otheri\text{out}_i = \text{input}_i + \text{other}_i

Autograd: gradient flows back to both operands as the identity (out/input=1\partial \text{out}/\partial \text{input} = 1, out/other=1\partial \text{out}/\partial \text{other} = 1), with broadcasted dimensions summed.

Examples

>>> import lucid
>>> a = lucid.tensor([1.0, 2.0, 3.0])
>>> b = lucid.tensor([4.0, 5.0, 6.0])
>>> lucid.add(a, b)
Tensor([...])