import torch


def decimate(tensor, m):
    """
    Decimate a tensor by a factor of 'm', i.e. downsample by keeping every 'm'th value.
    """
    assert tensor.dim() == len(m)
    for d in range(tensor.dim()):
        if m[d] is not None:
            tensor = tensor.index_select(
                dim=d, index=torch.arange(start=0, end=tensor.size(d), step=m[d]).long()
            )
    return tensor