lerp

paddle. lerp ( x: Tensor, y: Tensor, weight: float | Tensor, name: str | None = None, *, out: Tensor | None = None ) → Tensor [source]

Does a linear interpolation between x and y based on weight.

Equation:
\[lerp(x, y, weight) = x + weight * (y - x).\]
Parameters
  • x (Tensor) – An N-D Tensor with starting points, the data type is bfloat16, float16, float32, float64. Alias: input

  • y (Tensor) – An N-D Tensor with ending points, the data type is bfloat16, float16, float32, float64. Alias: end

  • weight (float|Tensor) – The weight for the interpolation formula. When weight is Tensor, the data type is bfloat16, float16, float32, float64.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_Name.

  • out (Tensor, optional) – The output Tensor. If set, the result will be stored in this Tensor. Default: None.

Returns

An N-D Tensor, the shape and data type is the same with input.

Return type

out (Tensor)

Example

>>> import paddle

>>> x = paddle.arange(1.0, 5.0, dtype='float32')
>>> y = paddle.empty([4], dtype='float32')
>>> y.fill_(10.0)
>>> out = paddle.lerp(x, y, 0.5)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[5.50000000, 6.        , 6.50000000, 7.        ])

>>> # Using out parameter
>>> result = paddle.empty([4], dtype='float32')
>>> paddle.lerp(x, y, 0.5, out=result)
>>> result
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[5.50000000, 6.        , 6.50000000, 7.        ])

>>> # Using parameter aliases (input for x, end for y)
>>> out = paddle.lerp(input=x, end=y, weight=0.5)  # type: ignore[call-arg]
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[5.50000000, 6.        , 6.50000000, 7.        ])