---
title: "ClikaRT::ops::threshold"
sidebar_label: "threshold"
description: "Elementwise threshold: keeps values above threshold, replaces the rest with value."
---

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

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

## threshold() {#threshold}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`threshold`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `threshold`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `value`<br />
)

</div>

Elementwise threshold: keeps values above [`threshold`](./threshold.md#threshold), replaces the rest with `value`.

$$
\mathrm{threshold}(x) = \begin{cases} x & x > \mathrm{threshold} \\ \mathrm{value} & \text{otherwise} \end{cases}
$$

**Parameters**

- `input`: the input tensor.
- `threshold`: the comparison bound.
- `value`: the replacement for elements at or below the bound.

**Throws**

- `ClikaRT::Error`: when the input's dtype is not served for this operation (the machine-readable reason rides `code_name()`).

**Returns:** a new tensor, same shape and dtype as `input`.

```cpp
auto y = ClikaRT::ops::threshold(x, 0.0, 0.0);  // == relu
```

<div class="api-declared">

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

</div>
