def METHOD_NAME(self, x: torch.Tensor, d: torch.Tensor) -> torch.Tensor:
    assert 0 <= len(x) - d.sum() < self.reduction_factor
    d_cumsum = F.pad(d.cumsum(dim=0), (1, 0))
    x_avg = [
        x[start:end].mean() if len(x[start:end]) != 0 else x.new_tensor(0.0)
        for start, end in zip(d_cumsum[:-1], d_cumsum[1:])
    ]
    return torch.stack(x_avg)