class
MaxPool1d
extends
ModuleMaxPool1d(kernel_size: int, stride: int | None = None, padding: int = 0, dilation: int = 1, return_indices: bool = False, ceil_mode: bool = False)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.
where is kernel_size, is stride, and
is dilation.
The output length is computed as:
When ceil_mode=True the floor is replaced by a ceiling, which may
include one extra partial window at the right boundary.
Parameters
kernel_sizeintSize of the sliding window.
strideint or None= NoneStep between successive windows. Defaults to
kernel_size when
None.paddingint= 0Zero-padding added to both ends of the input before pooling.
Default:
0.dilationint= 1Spacing between kernel elements (dilated / atrous pooling).
dilation=1 gives the standard contiguous window.
Default: 1.return_indicesbool= FalseIf
True, the forward pass also returns the flat indices of
the selected maxima. Currently not supported (raises
NotImplementedError). Default: False.ceil_modebool= FalseWhen
True, use ceiling instead of floor to compute the output
length. Default: False.Attributes
kernel_sizeintstrideint or Nonepaddingintdilationintceil_modeboolNotes
- Input:
(N, C, L_in) - Output:
(N, C, L_out)
- Dilation inserts 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)Initialise the MaxPool1d module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the pooling operation to the input tensor.
Parameters
inputTensorInput tensor of shape where are the
spatial dimensions appropriate for this pooling layer.
Returns
TensorPooled output tensor.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.