Skip to content
fn

adaptive_avg_pool1d

→Tensor
adaptive_avg_pool1d(input: Tensor, output_size: _OutSize)

Implementing kernel

C++ engine symbols that back this Python API.

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

Computes kernel / stride dynamically so that the output's spatial length equals output_size regardless of input length. Handy when feeding variable-length sequences into a head expecting a fixed embedding size.

Parameters

inputTensor
Input of shape (N, C, L), or (C, L) unbatched.
output_sizeint or tuple of (int or None)
Desired length of the output spatial axis.

Returns

Tensor

Output of shape (N, C, output_size).

Notes

For each output index ii, the corresponding input window is

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

and the cell is the mean over that window. When L divides evenly by L_out the operation reduces to plain avg_pool1d with kernel == stride == L / L_out; otherwise Lucid falls back to a per-slot Python-level computation that still keeps all data on the original device.

Examples

>>> import lucid
>>> from lucid.nn.functional import adaptive_avg_pool1d
>>> x = lucid.randn(2, 32, 13)
>>> y = adaptive_avg_pool1d(x, output_size=5)
>>> y.shape
(2, 32, 5)

Used by 3