import torch


def split_train_test(X, y, train_size=0.8, shuffle=True):
    """
    Split data into training and testing sets

    Parameters:
    X (Tensor): The input data
    y (Tensor): The labels
    train_size (float): The fraction of data used for the training
    shuffle (boolean): Whether to randomly shuffle data before splitting

    Returns:
    Tensor: The training data
    Tensor: The training labels
    Tensor: The testing data
    Tensor: The testing labels
    """

    if shuffle:
        perm = torch.randperm(X.size(0))
        X = X[perm]
        y = y[perm]

    cut = int(train_size * X.size(0))
    X_train = X[:cut]
    y_train = y[:cut]
    X_val = X[cut:]
    y_val = y[cut:]

    return X_train, y_train, X_val, y_val