fn

adaptive_max_pool1d

Tensor
adaptive_max_pool1d(x: Tensor, output_size: int | tuple[int, ...], return_indices: bool = False)
source

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

xTensor
Input of shape (N, C, L).
output_sizeint or tuple of int
Desired output length.
return_indicesbool= False
Must currently be False.

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)