code: def test_reweighter():
      sampler = ReweightedBatchSampler(
          MyDataset(),
          batch_size=11,
          class_weights=np.array([1, 2, 1, 3]),
      )
      assert len(sampler) == 5
      one_part = 1 / (1 + 2 + 1 + 3)
      batches = list(itertools.islice(sampler, 10))
      assert len(batches) == 5
      counts = Counter()
      for _ in range(1000):
          for batch in sampler:
              assert len(batch) == 11
              counts.update(map(idx_to_class, batch))
      assert len(counts) == 4
      total = sum(counts.values())
      assert total == 1000 * 5 * 11
      assert round(abs(counts["1"] / total - one_part), 2) == 0
      assert round(abs(counts["2"] / total - 2 * one_part), 2) == 0
      assert round(abs(counts["3"] / total - one_part), 2) == 0
      assert round(abs(counts["4"] / total - 3 * one_part), 2) == 0
  
file_path: pykale/tests/loaddata/test_sampler.py
imports: import itertools
  from collections import Counter
  import numpy
  from kale.loaddata.sampler import BalancedBatchSampler, ReweightedBatchSampler
label_desc: Use image node_id 4 for calling a global function with example usage: test_reweighter() without return types