class_docstr: Reorder the bytes in a 1-dimensional buffer.
class_docstr_tok: ["Reorder","the","bytes","in","a","1-dimensional","buffer","."]
docstr: Reorder the bytes of a 1-dimensional buffer.
  
  Args:
      data: A dictionary containing a key called "samples", which contains
          a tensor of shape [N], where N is the number of bytes.
  
  Returns:
      The transformed data.
docstr_tok: ["Reorder","the","bytes","of","a","1-dimensional","buffer",".","Args",":","data",":","A","dictionary","containing","a","key","called","``","samples","''",",","which","contains","a","tensor","of","shape","[","N","]",",","where","N","is","the","number","of","bytes",".","Returns",":","The","transformed","data","."]
code: def __call__(
      self, data: Dict[str, Union[torch.Tensor, int]]
  ) -> Dict[str, Union[torch.Tensor, int]]:
      """
      Reorder the bytes of a 1-dimensional buffer.
  
      Args:
          data: A dictionary containing a key called "samples", which contains
              a tensor of shape [N], where N is the number of bytes.
  
      Returns:
          The transformed data.
      """
      x = data["samples"]
      if not x.dim() == 1:
          raise ValueError(f"Expected 1d input, got {x.shape}")
  
      if self.mode == "reverse":
          x = torch.fliplr(x.view(1, -1))[0]
      elif self.mode == "random_shuffle":
          x = x[torch.randperm(x.shape[0])]
      elif self.mode == "cyclic_half_length":
          x = torch.roll(x, x.shape[0] // 2)
      elif self.mode == "stride":
          l = len(x)
          values = []
          for i in range(self.stride):
              values.append(x[i :: self.stride])
          x = torch.cat(values, dim=0)
          assert len(x) == l
      elif self.mode == "window_shuffle":
          l = len(x)
          window_size = self.window_shuffle.shape[0]
          num_windows = l // window_size
          values = []
          for i in range(num_windows):
              chunk = x[i * window_size : (i + 1) * window_size]
              values.append(chunk[self.window_shuffle])
  
          # Add the last bits that fall outside the shuffling window.
          values.append(x[num_windows * window_size :])
          x = torch.cat(values, dim=0)
          assert len(x) == l
      else:
          raise NotImplementedError(
              f"mode={self.mode} not implemented. Expected one of 'reverse, random_shuffle, cyclic_half_length, stride, window_shuffle'."
          )
      data["samples"] = x
      return data
  
imports: import argparse
  import io
  from typing import Dict, Union
  import numpy
  import torch
  from PIL import Image
  from data.transforms import TRANSFORMATIONS_REGISTRY, BaseTransformation
label_desc: Use image node_id 2 for calling the ShuffleBytes obj's underlying member method code with example usage: obj.__call__(data) and returns: data