---
title: "ClikaRT::ops::mod"
sidebar_label: "mod"
description: "Elementwise modulo with a selectable sign convention. \\[ Python: 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 fo…"
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## mod() {#mod}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`mod`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `other`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ModMode`](./index.md#ModMode) `mode` `=` [`ModMode::Python`](./index.md#ModMode)<br />
)

</div>

Elementwise modulo with a selectable sign convention.

$$
Python: a - \lfloor a/b \rfloor \cdot b \qquad C: a - trunc(a/b) \cdot b
$$

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

**Parameters**

- `input`: dividend tensor.
- `other`: divisor: tensor or scalar literal.
- `mode`: the sign convention; default [`ModMode::Python`](./index.md#ModMode).

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

**Throws**

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

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

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 1529

</div>
