Skip to content
fn

max_pool1d

→Tensor
max_pool1d(input: Tensor, 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, return_indices: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

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

inputTensor
Input of shape (N, C, L), or (C, L) unbatched.
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.
ceil_modebool= False
When True, use ceil instead of floor in the output-size formula.
return_indicesbool= False
Also return where each maximum came from: (output, indices), indices holding each window's flat position in the unpadded input — the form max_unpool1d takes.

Returns

Tensor

Output of shape (N, C, L_out) where

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

Notes

Math:

yi,c,l=max⁡m=0,…,k−1xi, c, sl+dm−py_{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)

Used by 3