ReplicationPad1d

https://pytorch.org/docs/stable/generated/torch.nn.ReplicationPad1d.html

replication_pad1d_demo.py
import svetoviz_webgpu as sv

# 1. Create a 1D signal (10 samples)
input_tensor = torch.arange(10, dtype=torch.float32).view(1, 1, 10)

# 2. Define ReplicationPad1d
# Pads 3 samples on the left and 3 on the right
pad1d = nn.ReplicationPad1d(padding=3)

def terminal_callback(buffer, message, images, files):
    output = pad1d(input_tensor)

    # Result will show the first and last values repeated
    buffer.send_system_message(f"Input Signal: {input_tensor.tolist()[0][0]}")
    buffer.send_system_message(f"Padded Signal: {output.tolist()[0][0]}")
    buffer.send_system_message("Edge values repeated 3 times.")

# 3. Start the interactive session
sv.pytorch_web(module=pad1d, terminal_callback=terminal_callback)
Edge Clamping Logic
ReplicationPad1d image border visualization
Replication padding repeats the last pixel value at the boundary. For an input [1, 2, 3] with padding 2, the result is [1, 1, 1, 2, 3, 3, 3]. This is useful for maintaining local statistics at boundaries.