class

ReplicationPad1d

extendsModule
ReplicationPad1d(padding: _Size2d)
source

Pad a 3-D tensor (N, C, L) by replicating the edge values.

Replication padding fills out-of-bounds positions with the value of the nearest valid element (edge replication):

output[n,c,i]=x ⁣[n,c,  clip(ipleft,  0,  L1)]\text{output}[n, c, i] = x\!\left[n, c,\; \text{clip}(i - p_{\text{left}},\; 0,\; L-1)\right]

The leftmost valid element is repeated to the left; the rightmost valid element is repeated to the right.

Parameters

paddingint or tuple[int, int]
(left, right) replication padding sizes. A single int pads equally on both sides.

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}}).
  • Replication padding is particularly useful when the input represents a signal whose boundary should be extended with the last known value (e.g. padding a time series at the end with its final sample).
  • Unlike reflection padding, replication padding is valid even for padding sizes equal to or larger than the input length.

Examples

**Edge-extend a short time series before a convolution:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> pad = nn.ReplicationPad1d(padding=5)
>>> x = lucid.zeros(2, 4, 20)
>>> pad(x).shape
(2, 4, 30)
**One-sided extension (right-only):**
>>> pad = nn.ReplicationPad1d(padding=(0, 10))
>>> x = lucid.zeros(1, 8, 50)
>>> pad(x).shape
(1, 8, 60)

Methods (3)

dunder

__init__

None
__init__(padding: _Size2d)
source

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