---
title: "ClikaRT::ops::nan_to_num"
sidebar_label: "nan_to_num"
description: "Replaces NaN and infinities with finite values. Each absent replacement falls back to the dtype-specific default: 0 for NaN, the dtype's largest finite value for +inf, its lowest for -inf."
---

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

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

## nan\_to\_num() {#nan_to_num}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`nan_to_num`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `nan` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `posinf` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `neginf` `=` `std::nullopt`<br />
)

</div>

Replaces NaN and infinities with finite values.

Each absent replacement falls back to the dtype-specific default: `0` for NaN, the dtype's largest finite value for `+inf`, its lowest for `-inf`.

**Parameters**

- `input`: the input tensor.
- `nan`: replacement for NaN. Default: `0`.
- `posinf`: replacement for `+inf`. Default: the dtype's max.
- `neginf`: replacement for `-inf`. Default: the dtype's lowest.

**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::nan_to_num(x);          // dtype defaults
auto z = ClikaRT::ops::nan_to_num(x, 0.0, 1e4, -1e4);
```

<div class="api-declared">

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

</div>
