code: def gen_even_slices(n, n_packs, n_samples=None):
      """Generator to create n_packs slices going up to n.
  
      Pass n_samples when the slices are to be used for sparse matrix indexing;
      slicing off-the-end raises an exception, while it works for NumPy arrays.
  
      Examples
      --------
      >>> from sklearn.utils import gen_even_slices
      >>> list(gen_even_slices(10, 1))
      [slice(0, 10, None)]
      >>> list(gen_even_slices(10, 10))                     #doctest: +ELLIPSIS
      [slice(0, 1, None), slice(1, 2, None), ..., slice(9, 10, None)]
      >>> list(gen_even_slices(10, 5))                      #doctest: +ELLIPSIS
      [slice(0, 2, None), slice(2, 4, None), ..., slice(8, 10, None)]
      >>> list(gen_even_slices(10, 3))
      [slice(0, 4, None), slice(4, 7, None), slice(7, 10, None)]
      """
      start = 0
      if n_packs < 1:
          raise ValueError(
              "gen_even_slices got n_packs=%s, must be >=1" % n_packs
          )
      for pack_num in range(n_packs):
          this_n = n // n_packs
          if pack_num < n % n_packs:
              this_n += 1
          if this_n > 0:
              end = start + this_n
              if n_samples is not None:
                  end = min(n_samples, end)
              yield slice(start, end, None)
              start = end
  
imports: from collections import Sequence
  import numpy
  from scipy.sparse import issparse
  import warnings
  from .murmurhash import murmurhash3_32
  from .validation import as_float_array, assert_all_finite, check_random_state, column_or_1d, check_array, check_consistent_length, check_X_y, indexable, check_symmetric
  from .deprecation import deprecated
  from .class_weight import compute_class_weight, compute_sample_weight
  from ..externals.joblib import cpu_count
  from ..exceptions import ConvergenceWarning
  from ..exceptions import DataConversionWarning
label_desc: Use image node_id 8 for calling a global function with example usage: gen_even_slices(n, n_packs, n_samples) without return types