#NEWLINE# def gen_even_slices( n , n_packs , n_samples = None ) : #NEWLINE# #INDENT# 'Generator to create n_packs slices going up to n.\n\n    Pass n_samples when the slices are to be used for sparse matrix indexing;\n    slicing off-the-end raises an exception, while it works for NumPy arrays.\n\n    Examples\n    --------\n    >>> from sklearn.utils import gen_even_slices\n    >>> list(gen_even_slices(10, 1))\n    [slice(0, 10, None)]\n    >>> list(gen_even_slices(10, 10))                     #doctest: +ELLIPSIS\n    [slice(0, 1, None), slice(1, 2, None), ..., slice(9, 10, None)]\n    >>> list(gen_even_slices(10, 5))                      #doctest: +ELLIPSIS\n    [slice(0, 2, None), slice(2, 4, None), ..., slice(8, 10, None)]\n    >>> list(gen_even_slices(10, 3))\n    [slice(0, 4, None), slice(4, 7, None), slice(7, 10, None)]\n    ' #NEWLINE# start = 0 #NEWLINE# for pack_num in range ( n_packs ) : #NEWLINE# #INDENT# this_n = ( n // n_packs ) #NEWLINE# if ( pack_num < ( n % n_packs ) ) : #NEWLINE# #INDENT# this_n += 1 #NEWLINE# #UNINDENT# if ( pack_num > 0 ) : #NEWLINE# #INDENT# end = ( start + this_n ) #NEWLINE# if ( n_samples is not None ) : #NEWLINE# #INDENT# end = min ( n_samples , end ) #NEWLINE# #UNINDENT# ( yield slice ( start , end , None ) ) #NEWLINE# start = end