---
title: "ClikaRT::ops::log_softmax"
sidebar_label: "log_softmax"
description: "Logarithm of the softmax along dim, computed stably (never log(softmax(x)) in two passes)."
---

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

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

## log\_softmax() {#log_softmax}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`log_softmax`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim` `=` `-1`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype` `=` [`DataType::Undefined`](../../index.md#DataType)<br />
)

</div>

Logarithm of the softmax along `dim`, computed stably (never `log(softmax(x))` in two passes).

$$
\mathrm{log\_softmax}(x)_i = x_i - \max_j x_j - \log\!\sum_j e^{\,x_j - \max_k x_k} \quad \text{along } \mathit{dim}
$$

**Parameters**

- `input`: the input tensor.
- `dim`: the reduction dimension. Negative counts from the end. Default `-1`.
- `dtype`: output dtype; [`DataType::Undefined`](../../index.md#DataType) (default) keeps `input`'s.

**Throws**

- `ClikaRT::Error`: when `dim` is out of range, or when the dtype pair is not served (`code_name()` carries the reason).

**Returns:** same shape as `input`; dtype = [`dtype`](../dtype/index.md) when set, else `input`'s.

```cpp
auto lp = ClikaRT::ops::log_softmax(logits, -1);
```

<div class="api-declared">

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

</div>
