---
title: "ClikaRT::ops::snake"
sidebar_label: "snake"
description: "Periodic \"snake\" activation (neural vocoders), per channels-last channel."
---

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

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

## snake() {#snake}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`snake`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`OptionalTensor`](../../index.md#OptionalTensor) `alpha` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`OptionalTensor`](../../index.md#OptionalTensor) `beta` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `eps` `=` `1e-9`<br />
)

</div>

Periodic "snake" activation (neural vocoders), per channels-last channel.

$$
\mathrm{snake}(x)_{\ldots c} = x + \frac{\sin^2(\alpha_c \, x)}{\beta_c + \varepsilon}
$$

`alpha` (frequency) and `beta` (magnitude) are rank-1 `[C]` tensors over `input`'s last dim, in the REAL domain. Apply [`exp`](./exp.md#exp) once at setup for a log-scale checkpoint parameterization. `beta` absent selects the plain form (`beta = alpha`). One fused pass; the composed spelling costs five elementwise calls over the whole stream.

**Parameters**

- `input`: the input tensor, channels-last `[..., C]`.
- `alpha`: the `[C]` frequency tensor. Absent uses the alpha held by the bound primitive (module usage).
- `beta`: the `[C]` magnitude tensor. Absent selects the plain form.
- `eps`: the no-division-by-zero guard added to `beta`.

**Throws**

- `ClikaRT::Error`: when a param's length does not match `input`'s last dim, when `alpha` is absent with none bound, or when the dtype is not served (`code_name()` carries the reason).

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

```cpp
auto y = ClikaRT::ops::snake(x, freq, magnitude);   // freq/magnitude: [C]
```

<div class="api-declared">

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

</div>
