ConstantPad1d

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

constant_pad1d_demo.py
import svetoviz_webgpu as sv

# 1. Create a 1D signal (10 samples)
input_tensor = torch.ones(1, 1, 10)

# 2. Define ConstantPad1d
# Pads 4 units on the left and 4 on the right with the value 5.0
pad1d = nn.ConstantPad1d(padding=4, value=5.0)

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 (Value 5.0): {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)
Constant Value Injection
ConstantPad1d image border visualization
Constant padding allows for any arbitrary scalar to be used as a boundary filler. This is particularly useful in specialized architectures where zero-padding might bias the mean activation or where a specific "mask" value is required.