class
ReplicationPad1d
extends
ModuleReplicationPad1d(padding: _Size2d)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):
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: .
- Output: .
- 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)Initialise the ReplicationPad1d 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.