Skip to content
fn

lp_pool1d

→Tensor
lp_pool1d(input: Tensor, norm_type: float, kernel_size: int | tuple[int], stride: int | tuple[int] | None = None, ceil_mode: bool = False)

1-D power-average pooling — (∑xp)1/p\big(\sum x^p\big)^{1/p}.

Generalises average and max pooling under a single parameter p=norm_typep = \text{norm\_type}. p=1p = 1 recovers sum-pooling (= |R| × avg_pool1d); p=2p = 2 is energy / RMS-style pooling; p=∞p = \infty is max_pool1d of ∣x∣|x|.

Parameters

inputTensor
Input of shape (N, C, L), or (C, L) unbatched.
norm_typefloat
Exponent p>0p > 0, or inf.
kernel_sizeint or tuple of int
Size of the pooling window.
strideint or tuple of int= None
Window step. Defaults to kernel_size.
ceil_modebool= False
Use ceil instead of floor in the output-size formula.

Returns

Tensor

Output of shape (N, C, L_out).

Notes

Math (per window RR):

yi,c,l=(∑m∈Rxi,c,mp)1/py_{i,c,l} = \left( \sum_{m \in R} x_{i,c,m}^p \right)^{1/p}

The power keeps the sign of xx, as the reference's does: it is the ℓp\ell^p norm of the window only for a non-negative input or an even pp. A window whose sum is negative, or a negative element under a fractional pp, gives nan; pool lucid.abs(x) for the norm. A window whose sum is zero has a zero gradient. Computed as (avg_pool1d(x^p) · |R|)^(1/p).

Examples

>>> import lucid
>>> from lucid.nn.functional import lp_pool1d
>>> x = lucid.randn(2, 4, 12)
>>> y = lp_pool1d(x, norm_type=2.0, kernel_size=2)
>>> y.shape
(2, 4, 6)

Used by 2