Parametric ReLU (PReLU)#

API#

class warp_nn.modules.activations.PReLU(*, requires_grad: bool = True)[source]#

Bases: Module

Parametric ReLU (PReLU) operation.

This class computes the element-wise Parametric Rectified Linear Unit (PReLU) function:

\[\begin{split}\text{PReLU}(x, \text{slope}) = \begin{cases} x, & \text{ if } x \geq 0\\ \text{slope} \, x, & \text{ if } x < 0 \end{cases}\end{split}\]

Unlike PyTorch’s PReLU layer (with a learnable slope parameter), the slope is an input array with the same shape as the input array.

Parameters:

requires_grad – Whether the cached output arrays of the module require gradients.

__call__(
x: array,
slope: array,
) → array[source]#

Forward pass of the operation.

Parameters:
  • x – The input array, with up to 3 dimensions.

  • slope – The (element-wise) slope array for negative inputs, with the same shape and data type as x.

Returns:

The output array, with same shape as the input arrays.

Raises:
  • ValueError – If the input arrays’ shapes differ.

  • TypeError – If the input arrays’ data types differ, or if their data type or number of dimensions is not supported.