code: def chunkify(
      a: torch.Tensor, dim: int, maxnumel: int
  ) -> Generator[Tuple[torch.Tensor, int, int], None, None]:
      """Splits the tensor `a` into several chunks of size `maxnumel` along the
      dimension given by `dim`.
  
      Examples
      --------
      >>> import torch
      >>> from deepchem.utils.pytorch_utils import chunkify
      >>> a = torch.arange(10)
      >>> for chunk, istart, iend in chunkify(a, 0, 3):
      ...     print(chunk, istart, iend)
      tensor([0, 1, 2]) 0 3
      tensor([3, 4, 5]) 3 6
      tensor([6, 7, 8]) 6 9
      tensor([9]) 9 12
  
      Parameters
      ----------
      a: torch.Tensor
          The big tensor to be splitted into chunks.
      dim: int
          The dimension where the tensor would be splitted.
      maxnumel: int
          Maximum number of elements in a chunk.
  
      Returns
      -------
      chunks: Generator[Tuple[torch.Tensor, int, int], None, None]
          A generator that yields a tuple of three elements: the chunk tensor, the
          starting index of the chunk and the ending index of the chunk.
  
      """
      dim = a.ndim + dim if dim < 0 else dim
  
      numel = a.numel()
      dimnumel = a.shape[dim]
      nondimnumel = numel // dimnumel
      if maxnumel < nondimnumel:
          msg = (
              "Cannot split the tensor of shape %s along dimension %s with maxnumel %d"
              % (a.shape, dim, maxnumel)
          )
          raise RuntimeError(msg)
  
      csize = min(maxnumel // nondimnumel, dimnumel)
      ioffset = 0
      lslice = (slice(None, None, None),) * dim
      rslice = (slice(None, None, None),) * (a.ndim - dim - 1)
      while ioffset < dimnumel:
          iend = ioffset + csize
          chunks = (
              a[(lslice + (slice(ioffset, iend, None),) + rslice)],
              ioffset,
              iend,
          )
          yield chunks
          ioffset = iend
  
file_path: deepchem/deepchem/utils/pytorch_utils.py
imports: import scipy
  import torch
  from typing import Callable, Union, List, Generator, Tuple
label_desc: Use image node_id 4 for calling a global function with example usage: chunkify(a, dim, maxnumel) without return types