---
title: "ClikaRT::nn::PReLU"
sidebar_label: "PReLU"
description: "Parametric ReLU. \\[ \\mathrm{prelu}(x) = \\begin{cases} x & x > 0 \\\\ \\mathrm{weight} \\cdot x & x \\le 0 \\end{cases} \\] weight is one value shared by every element (num_parameters = 1) or one value per ch…"
---

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

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

**Header:** `ClikaRT/nn/prelu.h`  
**Inherits:** [`ClikaRT::nn::Module`](./Module.md)

Parametric [ReLU](./ReLU.md).

$$
\mathrm{prelu}(x) = \begin{cases} x & x > 0 \\ \mathrm{weight} \cdot x
& x \le 0 \end{cases}
$$

`weight` is one value shared by every element ([`num_parameters`](./PReLU.md#num_parameters)` = 1`) or one value per channel ([`num_parameters`](./PReLU.md#num_parameters) = the channel count, broadcast against the input). The module form of [`ops::prelu`](../ops/prelu.md#prelu).

```cpp
auto act = ClikaRT::nn::PReLU::make();      // one slope, 0.25
auto y   = (*act)(x);
```

## Static member functions

### make() {#make}

<div class="api-signature">

`static` `std::shared_ptr<PReLU>` **`make`**(`std::int64_t` `num_parameters` `=` `1`, [`PReLUOptions`](./PReLUOptions.md) `options` `=` `{}`)

</div>

Construct with a real `weight` `[`[`num_parameters`](./PReLU.md#num_parameters)`]` filled with `options.init` on `options.dtype` / `options.device`; the module is usable without a checkpoint, and a bind replaces the weight. Raises [`ClikaRT::Error`](../Error.md) on a parameter count that is not positive.

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 69

</div>

## Member functions

### set\_weights() {#set_weights}

<div class="api-signature">

`void` **`set_weights`**([`Tensor`](../Tensor.md) `weight`)

</div>

Bind `weight` (`[`[`num_parameters`](./PReLU.md#num_parameters)`]`) positionally. The declared placement wins; the shape must match the declaration; the next [`forward`](./PReLU.md#forward) rebuilds. Raises [`ClikaRT::Error`](../Error.md) on a geometry mismatch.

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 78

</div>

### \~PReLU() {#PReLU}

<div class="api-signature">

**`~PReLU`**() `override`

</div>

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 82

</div>

### to\_impl(StreamOrDevice) {#to_impl}

<div class="api-signature">

`virtual` [`Result`](../Result.md)`<void>` **`to_impl`**([`StreamOrDevice`](../StreamOrDevice.md) `where`) `override`

</div>

Move to a placement ([`Device`](../Device.md) / [`Stream`](../Stream.md)) or cast to a dtype. Rebuilds over the moved weight on the next forward.

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 86

</div>

### to\_impl(DataType) {#to_impl-2}

<div class="api-signature">

`virtual` [`Result`](../Result.md)`<void>` **`to_impl`**([`DataType`](../../index.md#DataType) `dtype`) `override`

</div>

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 87

</div>

### forward() {#forward}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`forward`**([`Tensor`](../Tensor.md) `input`) `const`

</div>

Applies the activation to `input` with the held slopes; output shape and dtype follow `input`. The first call builds (once, thread-safe). Raises [`ClikaRT::Error`](../Error.md) when the weight does not broadcast against `input`.

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 94

</div>

### operator()() {#operator-call}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`operator()`**([`Tensor`](../Tensor.md) `input`) `const`

</div>

Same as [`forward`](./PReLU.md#forward).

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 98

</div>

### num\_parameters() {#num_parameters}

<div class="api-signature">

`std::int64_t` **`num_parameters`**() `const noexcept`

</div>

The slope count the module was made with.

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 103

</div>

### options() {#options}

<div class="api-signature">

`const` [`PReLUOptions`](./PReLUOptions.md)`&` **`options`**() `const noexcept`

</div>

The settings the module was made with.

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 105

</div>

## Protected member functions

### initialize\_impl() {#initialize_impl}

<div class="api-signature">

`virtual` [`Result`](../Result.md)`<void>` **`initialize_impl`**() `override`

</div>

The pack hook: builds the activation over the bound weight (idempotent, thread-safe).

<div class="api-declared">

Declared in `ClikaRT/nn/prelu.h`, line 115

</div>
