code: def gen_batches(n, batch_size, *, min_batch_size=0):
      """Generator to create slices containing `batch_size` elements from 0 to `n`.
  
      The last slice may contain less than `batch_size` elements, when
      `batch_size` does not divide `n`.
  
      Parameters
      ----------
      n : int
          Size of the sequence.
      batch_size : int
          Number of elements in each batch.
      min_batch_size : int, default=0
          Minimum number of elements in each batch.
  
      Yields
      ------
      slice of `batch_size` elements
  
      See Also
      --------
      gen_even_slices: Generator to create n_packs slices going up to n.
  
      Examples
      --------
      >>> from sklearn.utils import gen_batches
      >>> list(gen_batches(7, 3))
      [slice(0, 3, None), slice(3, 6, None), slice(6, 7, None)]
      >>> list(gen_batches(6, 3))
      [slice(0, 3, None), slice(3, 6, None)]
      >>> list(gen_batches(2, 3))
      [slice(0, 2, None)]
      >>> list(gen_batches(7, 3, min_batch_size=0))
      [slice(0, 3, None), slice(3, 6, None), slice(6, 7, None)]
      >>> list(gen_batches(7, 3, min_batch_size=2))
      [slice(0, 3, None), slice(3, 7, None)]
      """
      start = 0
      for _ in range(int(n // batch_size)):
          end = start + batch_size
          if end + min_batch_size > n:
              continue
          yield slice(start, end)
          start = end
      if start < n:
          yield slice(start, n)
  
imports: import math
  import numbers
  import platform
  import struct
  import timeit
  import warnings
  from collections.abc import Sequence
  from contextlib import contextmanager, suppress
  from itertools import compress, islice
  import numpy
  from scipy.sparse import issparse
  from ..None import get_config
  from ..exceptions import DataConversionWarning
  from .None import _joblib, metadata_routing
  from ._bunch import Bunch
  from ._estimator_html_repr import estimator_html_repr
  from ._param_validation import Integral, Interval, validate_params
  from .class_weight import compute_class_weight, compute_sample_weight
  from .deprecation import deprecated
  from .discovery import all_estimators
  from .fixes import parse_version, threadpool_info
  from .murmurhash import murmurhash3_32
  from .validation import _is_arraylike_not_scalar, _is_pandas_df, _is_polars_df, _use_interchange_protocol, as_float_array, assert_all_finite, check_array, check_consistent_length, check_random_state, check_scalar, check_symmetric, check_X_y, column_or_1d, indexable
label_desc: Use image node_id 18 for calling a global function with example usage: gen_batches(n, batch_size) without return types