text: import math
  import random
  import numpy as np
  from dezero import cuda
  
  
  class Dataset:
      def __getitem__(self, index):
          raise NotImplementedError
  
      def __len__(self):
          raise NotImplementedError
  
  
  class DatasetLoader:
      def __init__(self, dataset, batch_size, shuffle=True, gpu=False):
          self.dataset = dataset
          self.batch_size = batch_size
          self.shuffle = shuffle
          self.data_size = len(dataset)
          self.max_iter_per_epoch = math.ceil(self.data_size / batch_size)
          self.gpu = gpu
  
          self.reset()
  
      def reset(self):
          self.iteration = 0
          if self.shuffle:
              random.shuffle(self.dataset)
  
      def __iter__(self):
          return self
  
      def __next__(self):
          if self.iteration >= self.max_iter_per_epoch:
              self.reset()
              raise StopIteration
  
          i = self.iteration % self.max_iter_per_epoch
          start_idx = i * self.batch_size
          end_idx = (i + 1) * self.batch_size
          batch = self.dataset[start_idx:end_idx]
  
          xp = cuda.cupy if self.gpu else np
          x = xp.array([example[0] for example in batch])
          t = xp.array([example[1] for example in batch])
  
          self.iteration += 1
  
          return x, t
  
      def next(self):
          return self.__next__()
  
      def to_cpu(self):
          self.gpu = False
  
      def to_gpu(self):
          self.gpu = True