class_docstr: Iterator that caches a number of indices sampled according to given weights.
  
  This gives a great performance speedup since np.random.choice is the bottleneck
  of the data loading. This class samples and caches a certain number of indices and
  return them until new ones need to be sampled.
class_docstr_tok: ["Iterator","that","caches","a","number","of","indices","sampled","according","to","given","weights",".","This","gives","a","great","performance","speedup","since","np.random.choice","is","the","bottleneck","of","the","data","loading",".","This","class","samples","and","caches","a","certain","number","of","indices","and","return","them","until","new","ones","need","to","be","sampled","."]
docstr: Args:
      weights:  np.ndarray, containing the sample weights
      num_cache: the number of indices to cache
docstr_tok: ["Args",":","weights",":","np.ndarray",",","containing","the","sample","weights","num_cache",":","the","number","of","indices","to","cache"]
code: def __init__(self, weights: np.ndarray, num_cache: int = 1024):
      """
      Args:
          weights:  np.ndarray, containing the sample weights
          num_cache: the number of indices to cache
      """
      self.weights = weights
      self.num_cache = num_cache
  
imports: from __future__ import annotations
  import numpy
  import pandas
  from dataclasses import dataclass, fields
  from typing import Iterator, List, Optional
  import torch
  from torch.utils.data import IterableDataset, Dataset
  from .dataset import TimeSeries, TimeSeriesDataset
label_desc: Use image node_id 1 to create a new WeightedIndexIterator object  with example: obj = WeightedIndexIterator(weights, num_cache)