Skip to main content

ClikaRT::ops::mod

function

mod()

Tensor mod(
    Tensor a,
    ScalarOrTensor other,
    ModMode mode = ModMode::Python
)

Elementwise modulo with a selectable sign convention.

Python:aa/bbC:atrunc(a/b)bPython: a - \lfloor a/b \rfloor \cdot b \qquad C: a - trunc(a/b) \cdot b

ModMode::Python (default) follows the DIVISOR's sign; ModMode::C follows the DIVIDEND's. ops::remainder is exactly the Python form, ops::fmod exactly the C form. Broadcasts and promotes as add.

Parameters

  • a: dividend tensor.
  • other: divisor: tensor or scalar literal.
  • mode: the sign convention; default ModMode::Python.

Returns: the broadcast-shaped remainders at the promoted dtype.

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) when the operand shapes are not broadcast-compatible.

    auto r = ClikaRT::ops::mod(a, 3); // sign follows the divisor

Declared in ClikaRT/compute/ops.h, line 1465