code: def __next__(self):
      np.random.seed(12345 * self.i + 4321)
      torch.random.manual_seed(12345 * self.i + 4321)
  
      def generate(dim):
          shape = np.random.randint(1, 10, [dim]).tolist()
          if self.as_tensor:
              data = to_dlpack(
                  torch.rand(
                      size=[self.batch_size] + shape, device=self.device
                  )
              )
          else:
              data = [
                  to_dlpack(torch.rand(shape, device=self.device))
                  for _ in range(self.batch_size)
              ]
          return data
  
      if self.i < self.n:
          self.i += 1
          if isinstance(self.dims, (list, tuple)):
              return [generate(d) for d in self.dims]
          else:
              return generate(self.dims)
      else:
          self.i = 0
          raise StopIteration
  
file_path: DALI/dali/test/python/test_external_source_pytorch_dlpack.py
imports: import numpy
  import nvidia.dali.fn
  import nvidia.dali.ops
  import torch
  from nvidia.dali.backend_impl import *
  from nvidia.dali import Pipeline
  from torch.utils.dlpack import to_dlpack, from_dlpack
  from test_utils import check_output
label_desc: Use image node_id 4 for calling the TestIterator obj's underlying member method code with example usage: obj.__next__() and returns: data, unknown, generate