class_docstr: Memory Augmented Time Series Dataset
  
  Args:
      handler (DataHandler): data handler
      segments (dict): data split segments
      seq_len (int): time series sequence length
      horizon (int): label horizon
      num_states (int): how many memory states to be added
      memory_mode (str): memory mode (daily or sample)
      batch_size (int): batch size (<0 will use daily sampling)
      n_samples (int): number of samples in the same day
      shuffle (bool): whether shuffle data
      drop_last (bool): whether drop last batch < batch_size
      input_size (int): reshape flatten rows as this input_size (backward compatibility)
class_docstr_tok: ["Memory","Augmented","Time","Series","Dataset","Args",":","handler","(","DataHandler",")",":","data","handler","segments","(","dict",")",":","data","split","segments","seq_len","(","int",")",":","time","series","sequence","length","horizon","(","int",")",":","label","horizon","num_states","(","int",")",":","how","many","memory","states","to","be","added","memory_mode","(","str",")",":","memory","mode","(","daily","or","sample",")","batch_size","(","int",")",":","batch","size","(","<","0","will","use","daily","sampling",")","n_samples","(","int",")",":","number","of","samples","in","the","same","day","shuffle","(","bool",")",":","whether","shuffle","data","drop_last","(","bool",")",":","whether","drop","last","batch","<","batch_size","input_size","(","int",")",":","reshape","flatten","rows","as","this","input_size","(","backward","compatibility",")"]
code: def __iter__(self):
      slices, batch_size = self._get_slices()
      indices = np.arange(len(slices))
      if self.shuffle:
          np.random.shuffle(indices)
  
      for i in range(len(indices))[::batch_size]:
          if self.drop_last and i + batch_size > len(indices):
              break
  
          data = []  # store features
          label = []  # store labels
          index = []  # store index
          state = []  # store memory states
          daily_index = []  # store daily index
          daily_count = []  # store number of samples for each day
  
          for j in indices[i : i + batch_size]:
              # normal sampling: self.batch_size > 0 => slices is a list => slices_subset is a slice
              # daily sampling: self.batch_size < 0 => slices is a nested list => slices_subset is a list
              slices_subset = slices[j]
  
              # daily sampling
              # each slices_subset contains a list of slices for multiple stocks
              # NOTE: daily sampling is used in 1) eval mode, 2) train mode with self.batch_size < 0
              if self.batch_size < 0:
                  # store daily index
                  idx = self._daily_index.index[
                      j
                  ]  # daily_index.index is the index of the original data
                  daily_index.append(idx)
  
                  # store daily memory if specified
                  # NOTE: daily memory always requires daily sampling (self.batch_size < 0)
                  if self.memory_mode == "daily":
                      slc = slice(
                          max(idx - self.seq_len - self.horizon, 0),
                          max(idx - self.horizon, 0),
                      )
                      state.append(
                          _maybe_padding(
                              self._memory[slc],
                              self.seq_len,
                              self._zeros,
                          )
                      )
  
                  # down-sample stocks and store count
                  if self.n_samples and 0 < self.n_samples < len(
                      slices_subset
                  ):  # intraday subsample
                      slices_subset = np.random.choice(
                          slices_subset, self.n_samples, replace=False
                      )
                  daily_count.append(len(slices_subset))
  
              # normal sampling
              # each slices_subset is a single slice
              # NOTE: normal sampling is used in train mode with self.batch_size > 0
              else:
                  slices_subset = [slices_subset]
  
              for slc in slices_subset:
                  # legacy support for Alpha360 data by `input_size`
                  if self.input_size:
                      data.append(
                          self._data[slc.stop - 1]
                          .reshape(self.input_size, -1)
                          .T
                      )
                  else:
                      data.append(
                          _maybe_padding(
                              self._data[slc], self.seq_len, self._zeros
                          )
                      )
  
                  if self.memory_mode == "sample":
                      state.append(
                          _maybe_padding(
                              self._memory[slc],
                              self.seq_len,
                              self._zeros,
                          )[: -self.horizon]
                      )
  
                  label.append(self._label[slc.stop - 1])
                  index.append(slc.stop - 1)
  
                  # end slices loop
  
              # end indices batch loop
  
          # concate
          data = _to_tensor(np.stack(data))
          state = _to_tensor(np.stack(state))
          label = _to_tensor(np.stack(label))
          index = np.array(index)
          daily_index = np.array(daily_index)
          daily_count = np.array(daily_count)
  
          # yield -> generator
          yield {
              "data": data,
              "label": label,
              "state": state,
              "index": index,
              "daily_index": daily_index,
              "daily_count": daily_count,
          }
  
imports: import copy
  import torch
  import warnings
  import numpy
  import pandas
  from qlib.data.dataset import DatasetH
label_desc: Use image node_id 12 for calling the MTSDatasetH obj's underlying member method code with example usage: obj.__iter__() without return types