class_docstr: ### Parity dataset
docstr: Generate a sample
docstr_tok: ["Generate","a","sample"]
code: def __getitem__(self, idx: int) -> Tuple[torch.Tensor, torch.Tensor]:
      """
      Generate a sample
      """
  
      # Empty vector
      x = torch.zeros((self.n_elems,))
      # Number of non-zero elements - a random number between $1$ and total number of elements
      n_non_zero = torch.randint(1, self.n_elems + 1, (1,)).item()
      # Fill non-zero elements with $1$'s and $-1$'s
      x[:n_non_zero] = torch.randint(0, 2, (n_non_zero,)) * 2 - 1
      # Randomly permute the elements
      x = x[torch.randperm(self.n_elems)]
  
      # The parity
      y = (x == 1.0).sum() % 2
  
      #
      return x, y
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/adaptive_computation/parity.py
imports: from typing import Tuple
  import torch
  from torch.utils.data import Dataset
label_desc: Use image node_id 3 for calling the ParityDataset obj's underlying member method code with example usage: obj.__getitem__(idx) and returns: x,  y