Skip to content
class

MaxPool1d

extendsModule
MaxPool1d(kernel_size: int, stride: int | None = None, padding: int = 0, dilation: int = 1, return_indices: bool = False, ceil_mode: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

Applies 1-D max pooling over a sequence.

For each position in the output, the module selects the maximum value from a sliding window of length kernel_size applied along the last (length) dimension of the input.

y[n,c,i]=max⁡0≤k<ksx ⁣[n, c, i⋅s+k⋅d]y[n, c, i] = \max_{0 \le k < k_s} x\!\left[n,\, c,\, i \cdot s + k \cdot d\right]

where ksk_s is kernel_size, ss is stride, and dd is dilation.

The output length is computed as:

Lout=⌊Lin+2p−d(ks−1)−1s+1⌋L_{out} = \left\lfloor \frac{L_{in} + 2p - d(k_s - 1) - 1}{s} + 1 \right\rfloor

When ceil_mode=True the floor is replaced by a ceiling, which may include one extra partial window at the right boundary.

Parameters

kernel_sizeint
Size of the sliding window.
strideint or None= None
Step between successive windows. Defaults to kernel_size when None.
paddingint= 0
Zero-padding added to both ends of the input before pooling. Default: 0.
dilationint= 1
Spacing between kernel elements (dilated / atrous pooling). dilation=1 gives the standard contiguous window. Default: 1.
return_indicesbool= False
If True, the forward pass returns (output, indices) where indices holds the argmax locations for MaxUnpool1d. Default: False.
ceil_modebool= False
When True, use ceiling instead of floor to compute the output length. Default: False.

Attributes

kernel_sizeint
strideint or None
paddingint
dilationint
ceil_modebool

Notes

  • Input: (N, C, L_in)
  • Output: (N, C, L_out)
  • Dilation inserts d−1d - 1 gaps between consecutive kernel elements, effectively enlarging the receptive field without increasing the number of comparisons.
  • Only the largest value in each window is propagated; gradients flow back exclusively to the winning element.

Examples

Basic non-overlapping pooling (stride equals kernel_size by default):
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.MaxPool1d(kernel_size=3)
>>> x = lucid.ones((1, 4, 12))
>>> y = pool(x)
>>> y.shape
(1, 4, 4)
Keeping where each maximum came from, for
lucid.nn.MaxUnpool1d:
>>> pool = nn.MaxPool1d(kernel_size=2, return_indices=True)
>>> y, idx = pool(lucid.randn(2, 8, 16))
>>> tuple(idx.shape), idx.dtype
((2, 8, 8), lucid.int64)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(kernel_size: int, stride: int | None = None, padding: int = 0, dilation: int = 1, return_indices: bool = False, ceil_mode: bool = False)

Initialise the MaxPool1d module. See the class docstring for parameter semantics.

Instance methods

2
fn

extra_repr

→str
extra_repr()

Return a string representation of the layer's configuration.