AdaptiveMaxPool1d

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

adaptive_maxpool1d_demo.py
import svetoviz_webgpu as sv

# 1. Create a 1D signal (100 samples)
t = torch.linspace(0, 10, 100)
input_tensor = (torch.sin(t) + torch.randn(100) * 0.1).unsqueeze(0).unsqueeze(0)

# 2. Define AdaptiveMaxPool1d
# We want exactly 16 output features, regardless of input length.
adap_pool1d = nn.AdaptiveMaxPool1d(output_size=16)

def terminal_callback(buffer, message, images, files):
    # 3. Process the sequence
    output = adap_pool1d(input_tensor)
    buffer.send_system_message(f"Input samples: {input_tensor.shape[-1]}")
    buffer.send_system_message(f"Targeting fixed output size: 16")
    buffer.send_system_message(f"Output Signal: {list(output.shape)}")

# 4. Start the interactive session
sv.pytorch_web(module=adap_pool1d, terminal_callback=terminal_callback)
Fixed-Length Temporal Pooling
AdaptiveMaxPool1d activations
Adaptive pooling automatically calculates kernel and stride to ensure the output length matches the target size (16), making it ideal for variable-length signals.