fn

rsub

Tensor
rsub(a: Tensor, b: Tensor | Scalar, alpha: float = ...)
source

Reverse subtraction: bαab - \alpha \cdot a.

Useful when b is a Python scalar that cannot left-bind the - operator against a tensor in a particular calling convention.

Parameters

aTensor
Right operand (subtrahend, multiplied by alpha).
bTensor | Scalar
Left operand (minuend).
alphafloat
Scalar multiplier applied to a. Defaults to 1.0.

Returns

Tensor

Element-wise difference of the broadcast shape of a and b.

Notes

Mathematical definition:

outi=biαai\text{out}_i = b_i - \alpha \cdot a_i

Equivalent to subtract with the operands reversed (and alpha re-attached to the new second argument). Gradient w.r.t. a is α-\alpha; w.r.t. b is 11.

Examples

>>> import lucid
>>> a = lucid.tensor([1.0, 2.0])
>>> lucid.rsub(a, 10.0)
Tensor([9., 8.])