
    0Ph>              
       |   d dl Z d dlmZ d dlmZ d dlZddlmZ ddl	m
Z
mZ d Z e e
eddd	
          g e
eddd	
          g e
ed dd	
          gdd          d dd            Z e e
eddd	
          g e
eddd	
          g e
eddd	
          dgdd          ddd            ZddddZdS )    N)islice)Integral   )
get_config   )Intervalvalidate_paramsc              #   V   K   	 t          t          | |                    }|r|V  ndS ')zzChunk generator, ``gen`` into lists of length ``chunksize``. The last
    chunk may have a length less than ``chunksize``.TN)listr   )gen	chunksizechunks      W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/utils/_chunking.pychunk_generatorr      s?      VC++,, 	KKKKF    left)closed)n
batch_sizemin_batch_sizeT)prefer_skip_nested_validation)r   c             #      K   d}t          t          | |z                      D ]%}||z   }||z   | k    rt          ||          V  |}&|| k     rt          ||           V  dS dS )a,  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)]
    r   N)rangeintslice)r   r   r   start_ends         r   gen_batchesr      s      Z E3qJ''((  j !##E3qyyE1oo yr   )r   n_packs	n_samples)r!   c             #      K   d}t          |          D ]G}| |z  }|| |z  k     r|dz  }|dk    r,||z   }|t          ||          }t          ||d          V  |}HdS )a  Generator to create `n_packs` evenly spaced slices going up to `n`.

    If `n_packs` does not divide `n`, except for the first `n % n_packs`
    slices, remaining slices may contain fewer elements.

    Parameters
    ----------
    n : int
        Size of the sequence.
    n_packs : int
        Number of slices to generate.
    n_samples : int, default=None
        Number of samples. 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.

    Yields
    ------
    `slice` representing a set of indices from 0 to n.

    See Also
    --------
    gen_batches: Generator to create slices containing batch_size elements
        from 0 to n.

    Examples
    --------
    >>> from sklearn.utils import gen_even_slices
    >>> list(gen_even_slices(10, 1))
    [slice(0, 10, None)]
    >>> list(gen_even_slices(10, 10))
    [slice(0, 1, None), slice(1, 2, None), ..., slice(9, 10, None)]
    >>> list(gen_even_slices(10, 5))
    [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)]
    r   r   N)r   minr   )r   r    r!   r   pack_numthis_nr   s          r   gen_even_slicesr&   Q   s      \ E'NN 	 	ga'k!!aKFA::&.C$)S))sD)))))E	 	r   )
max_n_rowsworking_memoryc                    |t                      d         }t          |dz  | z            }|t          ||          }|dk     r0t          j        d|t          j        | dz            fz             d}|S )a  Calculate how many rows can be processed within `working_memory`.

    Parameters
    ----------
    row_bytes : int
        The expected number of bytes of memory that will be consumed
        during the processing of each row.
    max_n_rows : int, default=None
        The maximum return value.
    working_memory : int or float, default=None
        The number of rows to fit inside this number of MiB will be
        returned. When None (default), the value of
        ``sklearn.get_config()['working_memory']`` is used.

    Returns
    -------
    int
        The number of rows which can be processed within `working_memory`.

    Warns
    -----
    Issues a UserWarning if `row_bytes exceeds `working_memory` MiB.
    Nr(   i   r   zOCould not adhere to working_memory config. Currently %.0fMiB, %.0fMiB required.g      >)r   r   r#   warningswarnnpceil)	row_bytesr'   r(   chunk_n_rowss       r   get_chunk_n_rowsr0      s    2 #&67~/9<==L<44a3rwy6'9::;<	
 	
 	

 r   )r*   	itertoolsr   numbersr   numpyr,   _configr   _param_validationr   r	   r   r   r&   r0    r   r   <module>r7      s                                8 8 8 8 8 8 8 8   hxD8889x!T&AAAB#8HafEEEF 
 #'   23 - - - - -` hxD8889HXq$v>>>?hxD@@@$G 
 #'   .2 0 0 0 0 0f /34 & & & & & & &r   