ReflectionPad1d

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

reflection_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 ReflectionPad1d (Padding of 2 on both sides)
pad1d = nn.ReflectionPad1d(padding=2)

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

    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(f"Shape: {list(input_tensor.shape)} -> {list(output.shape)}")

# 3. Start the interactive session
sv.pytorch_web(module=pad1d, terminal_callback=terminal_callback)
1D Reflection Logic
ReflectionPad1d image border visualization
Reflection padding mirrors the input values at the boundary. For an input [0, 1, 2] with padding 1, the result is [1, 0, 1, 2, 1]. This maintains signal continuity better than zero-padding.