class

CircularPad3d

extendsModule
CircularPad3d(padding: int | tuple[int, int, int, int, int, int])
source

Pad a 5-D tensor (N, C, D, H, W) with wrap-around in all three axes.

Treats the depth, height, and width dimensions as periodic: the volume wraps around in all three spatial directions, like a 3-D torus.

output[n,c,k,i,j]=x ⁣[n,c,  (kpf)modD,  (ipt)modH,  (jpl)modW]\text{output}[n, c, k, i, j] = x\!\left[n, c,\; (k - p_f) \bmod D,\; (i - p_t) \bmod H,\; (j - p_l) \bmod W \right]

Parameters

paddingint or tuple[int, int, int, int, int, int]
(left, right, top, bottom, front, back) circular padding sizes. A single int pads equally on all six faces.

Attributes

paddingtuple[int, int, int, int, int, int]
Normalised 6-element padding tuple.

Notes

  • Input: (N,C,D,H,W)(N, C, D, H, W).
  • Output: (N,C,Dout,Hout,Wout)(N, C, D_{\text{out}}, H_{\text{out}}, W_{\text{out}}).
  • Applicable to volumetric data with inherent periodicity, such as crystallographic unit cells or periodic boundary condition simulations in computational physics.

Examples

**Toroidal padding for a periodic 3-D simulation box:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.CircularPad3d(padding=1)
>>> x = lucid.zeros(1, 4, 32, 32, 32)
>>> pad(x).shape
(1, 4, 34, 34, 34)
**Temporal wrap-around for a looping video sequence:**
>>> pad = nn.CircularPad3d(padding=(0, 0, 0, 0, 4, 4))  # time axis only
>>> x = lucid.zeros(2, 3, 16, 112, 112)
>>> pad(x).shape
(2, 3, 24, 112, 112)

Methods (3)

dunder

__init__

None
__init__(padding: int | tuple[int, int, int, int, int, int])
source

Initialise the CircularPad3d 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.