Max Pooling 1D (MaxPool1D)#

API#

class warp_nn.modules.layers.MaxPool1D(
kernel_size: int | tuple[int],
*,
stride: int | tuple[int] | None = None,
padding: int | tuple[int] = 0,
dilation: int | tuple[int] = 1,
ceil_mode: bool = False,
requires_grad: bool = True,
)[source]#

Apply a 1D max pooling.

The output value for each window is the maximum of the input values in the window. The input is implicitly padded with negative infinity values on both sides.

Parameters:
  • kernel_size – The size of the window.

  • stride – The stride of the window. If None, it is equal to kernel_size.

  • padding – The implicit padding added on both sides. It must be at most half of the kernel size.

  • dilation – The spacing between the elements in the window.

  • ceil_mode – Whether to use ceil (instead of floor) to compute the output size. If true, the last window can extend beyond the (padded) input, as long as it starts inside the input or its left padding.

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

Raises:

ValueError – If any of the arguments is not valid.

__call__(
input: array,
) → array[source]#

Forward pass of the module.

Parameters:

input – The input array, with shape (batch_size, channels, in_length).

Returns:

The output array, with shape (batch_size, channels, out_length) where:

\[L_{out} = \left\lfloor \frac{L_{in} + 2 \, \text{padding} - \text{dilation} \, (\text{kernel\_size} - 1) - 1}{\text{stride}} \right\rfloor + 1\]

(using ceil instead of floor if ceil_mode is true).

Raises:

ValueError – If the input array’s shape is not supported, or if the output size is too small.