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)