def cumulative_norm(input):
    eps = 1e-10
    device = input.device
    data_type = input.dtype
    n_dim = input.ndim
    assert (n_dim in (3, 4))
    if (n_dim == 3):
        n_channels = 1
        (batch_size, n_freqs, n_frames) = input.size()
    else:
        (batch_size, n_channels, n_freqs, n_frames) = input.size()
        input = input.reshape((batch_size * n_channels), n_freqs, n_frames)
    step_sum = torch.sum(input, dim=1)
    step_pow_sum = torch.sum(torch.square(input), dim=1)
    cumulative_sum = torch.cumsum(step_sum, dim=(- 1))
    cumulative_pow_sum = torch.cumsum(step_pow_sum, dim=(- 1))
    entry_count = torch.arange(n_freqs, ((n_freqs * n_frames) + 1), n_freqs, dtype=data_type, device=device)
    entry_count = entry_count.reshape(1, n_frames)
    entry_count = entry_count.expand_as(cumulative_sum)
    cum_mean = (cumulative_sum / entry_count)
    cum_var = (((cumulative_pow_sum - ((2 * cum_mean) * cumulative_sum)) / entry_count) + cum_mean.pow(2))
    cum_std = (cum_var + eps).sqrt()
    cum_mean = cum_mean.reshape((batch_size * n_channels), 1, n_frames)
    cum_std = cum_std.reshape((batch_size * n_channels), 1, n_frames)
    x = ((input - cum_mean) / cum_std)
    if (n_dim == 4):
        x = x.reshape(batch_size, n_channels, n_freqs, n_frames)
    return x
def cumulative_norm(input):
    eps = 1e-10
    device = input.device
    data_type = input.dtype
    n_dim = input.ndim
    assert (n_dim in (3, 4))
    if (n_dim == 3):
        n_channels = 1
        (batch_size, n_freqs, n_frames) = input.size()
    else:
        (batch_size, n_channels, n_freqs, n_frames) = input.size()
        input = input.reshape((batch_size * n_channels), n_freqs, n_frames)
    step_sum = torch.sum(input, dim=1)
    step_pow_sum = torch.sum(torch.square(input), dim=1)
    cumulative_sum = torch.cumsum(step_sum, dim=(- 1))
    cumulative_pow_sum = torch.cumsum(step_pow_sum, dim=(- 1))
    entry_count = torch.arange(n_freqs, ((n_freqs * n_frames) + 1), n_freqs, dtype=data_type, device=device)
    entry_count = entry_count.reshape(1, n_frames)
    entry_count = entry_count.expand_as(cumulative_sum)
    cum_mean = (cumulative_sum / entry_count)
    cum_var = (((cumulative_pow_sum - ((2 * cum_mean) * cumulative_sum)) / entry_count) + cum_mean.pow(2))
    cum_std = (cum_var + eps).sqrt()
    cum_mean = cum_mean.reshape((batch_size * n_channels), 1, n_frames)
    cum_std = cum_std.reshape((batch_size * n_channels), 1, n_frames)
    x = ((input - cum_mean) / cum_std)
    if (n_dim == 4):
        x = x.reshape(batch_size, n_channels, n_freqs, n_frames)
    return x