class_docstr: Crop random sub-sequences from time series.
  
  To guarantee all output series have the same length, if the crop size is not
  deterministic, all crops must be resize to a fixed length.
  
  Parameters
  ----------
  size : int, tuple, list
      The length of random crops.
  
      - If int, all crops have the same length.
      - If list, a crop from a series has a length sampled from this list
        randomly.
      - If 2-tuple, a crop from a series has a length sampled from this
        interval randomly.
  
  resize : int, optional
      The length that all crops are resized to. Only necessary if the crop
      size is not fixed.
  
  repeats : int, optional
      The number of times a series is augmented. If greater than one, a series
      will be augmented so many times independently. This parameter can also
      be set by operator `*`. Default: 1.
  
  prob : float, optional
      The probability of a series is augmented. It must be in (0.0, 1.0]. If
      multiple output is expected, this value must be 1.0, so that all output
      have the same length. This parameter can also be set by operator `@`.
      Default: 1.0.
  
  seed : int, optional
      The random seed. Default: None.
class_docstr_tok: ["Crop","random","sub-sequences","from","time","series",".","To","guarantee","all","output","series","have","the","same","length",",","if","the","crop","size","is","not","deterministic",",","all","crops","must","be","resize","to","a","fixed","length",".","Parameters","--","--","--","--","--","size",":","int",",","tuple",",","list","The","length","of","random","crops",".","-","If","int",",","all","crops","have","the","same","length",".","-","If","list",",","a","crop","from","a","series","has","a","length","sampled","from","this","list","randomly",".","-","If","2-tuple",",","a","crop","from","a","series","has","a","length","sampled","from","this","interval","randomly",".","resize",":","int",",","optional","The","length","that","all","crops","are","resized","to",".","Only","necessary","if","the","crop","size","is","not","fixed",".","repeats",":","int",",","optional","The","number","of","times","a","series","is","augmented",".","If","greater","than","one",",","a","series","will","be","augmented","so","many","times","independently",".","This","parameter","can","also","be","set","by","operator","`","*","`",".","Default",":","1.","prob",":","float",",","optional","The","probability","of","a","series","is","augmented",".","It","must","be","in","(","0.0",",","1.0","]",".","If","multiple","output","is","expected",",","this","value","must","be","1.0",",","so","that","all","output","have","the","same","length",".","This","parameter","can","also","be","set","by","operator","`","@","`",".","Default",":","1.0.","seed",":","int",",","optional","The","random","seed",".","Default",":","None","."]
docstr: Overwrite the memory-expensive base method.
docstr_tok: ["Overwrite","the","memory-expensive","base","method","."]
code: def _augment(
      self, X: np.ndarray, Y: Optional[np.ndarray]
  ) -> Tuple[np.ndarray, Optional[np.ndarray]]:
      """
      Overwrite the memory-expensive base method.
      """
      N, T, C = X.shape
      rand = np.random.RandomState(self.seed)
  
      if self.prob != 1.0:
          # it implies N == 1 and self.repeats == 1
          if rand.uniform() > self.prob:
              if Y is None:
                  return X.copy(), None
              else:
                  return X.copy(), Y.copy()
  
      if isinstance(self.size, int):
          size = [self.size]
      elif isinstance(self.size, tuple):
          size = list(range(self.size[0], self.size[1]))
      else:
          size = self.size
  
      if self.resize is not None:
          resize = self.resize
      else:
          if len(size) > 1:
              raise ValueError(
                  "Parameter `resize` must be specified if parameter `size` "
                  "is not a single value."
              )
          else:
              resize = size[0]
  
      X_aug = np.zeros((N * self.repeats, resize, C))
      if Y is None:
          Y_aug = None
      else:
          L = Y.shape[2]
          Y_aug = np.zeros((N * self.repeats, resize, L))
  
      crop_size = rand.choice(size, size=N * self.repeats)
      resizer = Resize(resize)
      for s in np.unique(crop_size):
          n = (crop_size == s).sum()
          crop_start = rand.choice(T - s + 1, size=n)
          X_aug[crop_size == s, :, :] = resizer.augment(
              X[
                  np.repeat(
                      np.repeat(np.arange(N), self.repeats)[
                          crop_size == s
                      ],
                      s,
                  )
                  .reshape(n, s)
                  .astype(int),
                  (
                      crop_start.reshape(n, 1)
                      + np.arange(s).reshape(1, s)
                  ).astype(int),
                  :,
              ].reshape((n, s, C))
          )
          if (Y is not None) and (Y_aug is not None):
              Y_aug[crop_size == s, :, :] = resizer.augment(
                  Y[
                      np.repeat(
                          np.repeat(np.arange(N), self.repeats)[
                              crop_size == s
                          ],
                          s,
                      )
                      .reshape(n, s)
                      .astype(int),
                      (
                          crop_start.reshape(n, 1)
                          + np.arange(s).reshape(1, s)
                      ).astype(int),
                      :,
                  ].reshape((n, s, L))
              )
  
      return X_aug, Y_aug
  
file_path: tsaug/src/tsaug/_augmenter/crop.py
imports: from typing import List, Optional, Tuple, Union
  import numpy
  from .base import _Augmenter, _default_seed
  from .resize import Resize
label_desc: Use image node_id 8 for calling the Crop obj's underlying member method code with example usage: obj._augment(X, Y) and returns: X_aug,  Y_aug, X,  None, X,  Y