fn

fmod

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

Element-wise C-style floating-point remainder.

Returns input - n * other where n is the result of truncating input / other toward zero. The sign of the result matches the sign of input (C / FORTRAN convention), in contrast to remainder which follows Python semantics.

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=inputiotheritrunc(inputi/otheri)\text{out}_i = \text{input}_i - \text{other}_i \cdot \mathrm{trunc}(\text{input}_i / \text{other}_i)

Useful for matching the behaviour of fmod from <math.h>.

Examples

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