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)
source

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]=max0k<ksx ⁣[n,c,is+kd]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+2pd(ks1)1s+1L_{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 also returns the flat indices of the selected maxima. Currently not supported (raises NotImplementedError). 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 d1d - 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)
Overlapping windows with explicit stride and dilation:
>>> pool = nn.MaxPool1d(kernel_size=3, stride=1, dilation=2)
>>> x = lucid.ones((2, 8, 16))
>>> y = pool(x)
>>> y.shape
(2, 8, 12)

Methods (3)

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)
source

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

fn

forward

Tensor
forward(x: Tensor)
source

Apply the pooling operation to the input tensor.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *) where * are the spatial dimensions appropriate for this pooling layer.

Returns

Tensor

Pooled output tensor.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.