fn

lp_pool1d

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

1-D Lp-norm 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; pp \to \infty approaches max_pool1d. Provides a smooth, fully differentiable bridge between the two extremes.

Parameters

xTensor
Input of shape (N, C, L).
norm_typefloat
Exponent p>0p > 0.
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=(mRxi,c,mp)1/py_{i,c,l} = \left( \sum_{m \in R} |x_{i,c,m}|^p \right)^{1/p}

Implemented as (avg_pool1d(|x|^p) · |R|)^(1/p) so the entire operator inherits its gradient from the average-pool engine path.

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)