fn

lerp

Tensor
lerp(input: Tensor)
source

Linearly interpolate between input and an endpoint with a weight.

Computes the affine combination

out  =  x+w(endx)  =  (1w)x+wend,\text{out} \;=\; x + w \cdot (\text{end} - x) \;=\; (1 - w) \cdot x + w \cdot \text{end} ,

where ww is the interpolation weight. weight may be a scalar or a tensor broadcastable to input.

Parameters

inputTensor
Start point.

Returns

Tensor

Interpolated tensor of the broadcast shape.

Notes

With w = 0 the result equals input; with w = 1 it equals end; out-of-range weights extrapolate beyond the endpoints.

Examples

>>> import lucid
>>> a = lucid.tensor([0.0, 0.0, 0.0])
>>> b = lucid.tensor([1.0, 2.0, 4.0])
>>> lucid.lerp(a, b, 0.5)
Tensor([0.5, 1. , 2. ])