class
CircularPad1d
extends
ModuleCircularPad1d(padding: _Size2d)Pad a 3-D tensor (N, C, L) by wrapping the sequence around itself.
Circular (or periodic) padding treats the input as if it were a circular buffer: values from the right end of the sequence appear on the left, and values from the left end appear on the right.
Parameters
paddingint or tuple[int, int](left, right) circular padding sizes. A single int pads
equally on both sides. Values may be larger than the input length
(the wrap-around simply repeats).Attributes
paddingtuple[int, int]Normalised
(left, right) padding.Notes
- Input: .
- Output: .
- Circular padding is the natural choice for signals that are inherently periodic: audio spectral features, astronomical data, or any domain with wrap-around semantics.
- For 1-D convolutions on periodic signals it ensures that the convolution filter sees a seamless boundary, unlike zero or reflection padding.
Examples
**Periodic extension of an audio spectrogram feature:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.CircularPad1d(padding=8)
>>> x = lucid.zeros(4, 64, 256)
>>> pad(x).shape
(4, 64, 272)
**Asymmetric wrap-around:**
>>> pad = nn.CircularPad1d(padding=(3, 0))
>>> x = lucid.zeros(2, 16, 100)
>>> pad(x).shape
(2, 16, 103)Methods (3)
dunder
__init__
→None__init__(padding: _Size2d)Initialise the CircularPad1d module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Pad the input tensor according to the configured padding.
Parameters
inputTensorInput tensor of shape .
Returns
TensorPadded tensor with spatial dimensions expanded by the configured padding amounts.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.