---
title: "ClikaRT::ops::glu"
sidebar_label: "glu"
description: "Gated linear unit: splits input in half along dim and gates the first half with the sigmoid of the second."
---

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

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

## glu() {#glu}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`glu`**([`Tensor`](../Tensor.md) `input`, `int64_t` `dim` `=` `-1`)

</div>

Gated linear unit: splits `input` in half along `dim` and gates the first half with the sigmoid of the second.

$$
\mathrm{glu}(x) = a \cdot \sigma(b), \qquad x = [\,a \,\|\, b\,] \text{ along } \mathit{dim}
$$

The size of `dim` must be even; the output halves it.

**Parameters**

- `input`: the input tensor.
- `dim`: the dimension to split. Negative counts from the end. Default `-1` (the last).

**Throws**

- `ClikaRT::Error`: when `dim` is out of range or its size is odd, or when the input's dtype is not served (`code_name()` carries the reason).

**Returns:** the input shape with `dim` halved; dtype of `input`.

```cpp
auto h = ClikaRT::ops::glu(proj);      // [.., 2d] -> [.., d]
```

<div class="api-declared">

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

</div>
