def mixup(X, y, lam, idx_perm):
    """Mixes two channels of EEG data.

    See [1]_ for details.
    Implementation based on [2]_.

    Parameters
    ----------
    X : torch.Tensor
        EEG data in form ``batch_size, n_channels, n_times``
    y : torch.Tensor
        Target of length ``batch_size``
    lam : torch.Tensor
        Values between 0 and 1 setting the linear interpolation between
        examples.
    idx_perm: torch.Tensor
        Permuted indices of example that are mixed into original examples.

    Returns
    -------
    tuple
        ``X``, ``y``. Where ``X`` is augmented and ``y`` is a tuple  of length
        3 containing the labels of the two mixed channels and the mixing
        coefficient.

    References
    ----------
    .. [1] Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz
        (2018). mixup: Beyond Empirical Risk Minimization. In 2018
        International Conference on Learning Representations (ICLR)
        Online: https://arxiv.org/abs/1710.09412
    .. [2] https://github.com/facebookresearch/mixup-cifar10/blob/master/train.py
    """
    device = X.device
    batch_size, n_channels, n_times = X.shape

    X_mix = torch.zeros((batch_size, n_channels, n_times)).to(device)
    y_a = torch.arange(batch_size).to(device)
    y_b = torch.arange(batch_size).to(device)

    for idx in range(batch_size):
        X_mix[idx] = lam[idx] * X[idx] + (1 - lam[idx]) * X[idx_perm[idx]]
        y_a[idx] = y[idx]
        y_b[idx] = y[idx_perm[idx]]

    return X_mix, (y_a, y_b, lam)
Mixes two channels of EEG data.

    See [1]_ for details.
    Implementation based on [2]_.

    Parameters
    ----------
    X : torch.Tensor
        EEG data in form ``batch_size, n_channels, n_times``
    y : torch.Tensor
        Target of length ``batch_size``
    lam : torch.Tensor
        Values between 0 and 1 setting the linear interpolation between
        examples.
    idx_perm: torch.Tensor
        Permuted indices of example that are mixed into original examples.

    Returns
    -------
    tuple
        ``X``, ``y``. Where ``X`` is augmented and ``y`` is a tuple  of length
        3 containing the labels of the two mixed channels and the mixing
        coefficient.

    References
    ----------
    .. [1] Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz
        (2018). mixup: Beyond Empirical Risk Minimization. In 2018
        International Conference on Learning Representations (ICLR)
        Online: https://arxiv.org/abs/1710.09412
    .. [2] https://github.com/facebookresearch/mixup-cifar10/blob/master/train.py
    
braindecode/augmentation/functional.py