Average Pooling 1D (AvgPool1D)#

API#

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

Apply a 1D average pooling.

The output value for each window is the average of the input values in the window. The input is implicitly padded with zeros 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 zero padding added on both sides. It must be at most half of the kernel size.

  • 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.

  • count_include_pad – Whether to include the zero padding in the averaging calculation.

  • 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{kernel\_size}}{\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.