code: def train_valid_splitter(x, y, split, shuffle=True):
      """Generate training and validation tensors from whole dataset data and label tensors
  
      Args:
          x (torch.Tensor): Data tensor for whole dataset
          y (torch.Tensor): Label tensor for whole dataset
          split (float): Fraction of dataset to be used for validation
          shuffle (bool): If True randomize tensor order before splitting else do not randomize
  
      Returns:
          Training and validation tensors (training data, training labels, validation data, validation labels)
      """
      num_samples_x = x.size()[0]
      num_valid_samples = int(math.floor(num_samples_x * split))
  
      if shuffle:
          indicies = torch.randperm(num_samples_x)
          x, y = x[indicies], y[indicies]
  
      x_val, y_val = x[:num_valid_samples], y[:num_valid_samples]
      x, y = x[num_valid_samples:], y[num_valid_samples:]
  
      return x, y, x_val, y_val
  
file_path: torchbearer/torchbearer/cv_utils.py
imports: import math
  import torch
  from torch.utils.data import TensorDataset, Dataset
  import random
label_desc: Use image node_id 1 for calling a global function with example usage: train_valid_splitter(x, y, split, shuffle) and returns: x,  y,  x_val,  y_val