fn

max_pool1d

Tensor
max_pool1d(x: Tensor, kernel_size: int | tuple[int, ...], stride: int | tuple[int, ...] | None = None, padding: int | tuple[int, ...] = 0, dilation: int | tuple[int, ...] = 1, return_indices: bool = False, ceil_mode: bool = False)
source

1-D max pooling over a sliding window.

For each window, takes the maximum value — a translation-invariant feature aggregator that also provides a degree of non-linearity. Standard ingredient of 1-D temporal CNNs (text, audio, sensor data).

Parameters

xTensor
Input of shape (N, C, L).
kernel_sizeint or tuple of int
Size of the pooling window.
strideint or tuple of int= None
Window step. Defaults to kernel_size (non-overlapping).
paddingint or tuple of int= 0
Implicit zero-padding on both sides of the spatial axis.
dilationint or tuple of int= 1
Spacing between window elements. Default 1.
return_indicesbool= False
Currently must be False; the engine pool op does not yet emit per-window argmax indices.
ceil_modebool= False
When True, use ceil instead of floor in the output-size formula.

Returns

Tensor

Output of shape (N, C, L_out) where

Lout=L+2pd(k1)1s+1L_{\text{out}} = \left\lfloor \frac{L + 2 p - d(k - 1) - 1}{s} + 1 \right\rfloor

Notes

Math:

yi,c,l=maxm=0,,k1xi,c,sl+dmpy_{i,c,l} = \max_{m = 0, \ldots, k-1} x_{i,\,c,\,s l + d m - p}

Max-pool is sub-differentiable: the gradient flows only through the position(s) holding the maximum in each window.

Examples

>>> import lucid
>>> from lucid.nn.functional import max_pool1d
>>> x = lucid.randn(2, 4, 16)
>>> y = max_pool1d(x, kernel_size=2)
>>> y.shape
(2, 4, 8)