fmod(input, other, *, out=None) → Tensor¶
Applies C++’s std::fmod for floating point tensors, and the modulus operation for integer tensors. The result has the same sign as the dividend
inputand its absolute value is less than that of
Supports broadcasting to a common shape, type promotion, and integer and float inputs.
When the divisor is zero, returns
NaNfor floating point dtypes on both CPU and GPU; raises
RuntimeErrorfor integer division by zero on CPU; Integer division by zero on GPU may return any value.
Complex inputs are not supported. In some cases, it is not mathematically possible to satisfy the definition of a modulo operation with complex numbers.
- Keyword Arguments
out (Tensor, optional) – the output tensor.
>>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2) tensor([-1., -0., -1., 1., 0., 1.]) >>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5) tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
torch.remainder()which is similar to
torch.fmod()except that if the sign of the modulus is different than the sign of the divisor
otherthen the divisor is added to the modulus.