class

CircularPad1d

extendsModule
CircularPad1d(padding: _Size2d)
source

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.

output[n,c,i]=x ⁣[n,c,  (ipleft)modL]\text{output}[n, c, i] = x\!\left[n, c,\; (i - p_{\text{left}}) \bmod L\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: (N,C,L)(N, C, L).
  • Output: (N,C,L+pleft+pright)(N, C, L + p_{\text{left}} + p_{\text{right}}).
  • 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)
source

Initialise the CircularPad1d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Pad the input tensor according to the configured padding.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *).

Returns

Tensor

Padded tensor with spatial dimensions expanded by the configured padding amounts.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.