import torch


def smooth(x, span):
    """
    Moving average smoothing with a filter of size `span`.
    """
    x = torch.nn.functional.pad(x, (span//2, span//2))
    x = torch.stack([torch.roll(x, k, -1) for k in range(-span//2, span//2+1)]).sum(dim=0) / span
    return x