Skip to content
fn

adaptive_max_pool1d

→Tensor
adaptive_max_pool1d(input: Tensor, output_size: int | tuple[int | None, ...], return_indices: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

1-D adaptive max pooling — produces a fixed output length.

Computes kernel / stride dynamically so the output length equals output_size regardless of input length, then takes the per-window maximum. Common in NLP / audio CNNs that feed fixed-size embeddings into a head.

Parameters

inputTensor
Input of shape (N, C, L), or (C, L) unbatched.
output_sizeint or tuple of (int or None)
Desired output length.
return_indicesbool= False
Also return (output, indices): each output cell's maximum as a flat position in the input's spatial extent.

Returns

Tensor

Output of shape (N, C, output_size).

Notes

The window for output index ii is

[⌊iL/Lout⌋,  ⌈(i+1)L/Lout⌉)\big[\lfloor i L / L_{\text{out}} \rfloor,\; \lceil (i+1) L / L_{\text{out}} \rceil\big)

and the cell takes the max over that window. Equivalent to max_pool1d with kernel == stride == L / L_out when the division is exact.

Examples

>>> import lucid
>>> from lucid.nn.functional import adaptive_max_pool1d
>>> x = lucid.randn(2, 8, 21)
>>> y = adaptive_max_pool1d(x, output_size=4)
>>> y.shape
(2, 8, 4)

Used by 3