o
    ¡ØÆh–  ã                   @   s@   d dl Z d dlmZ d dlmZ d	dd„Zeeddfdd„ZdS )
é    N)Úpartition_all)Ú
no_defaultc                 C   s"   |d u r
t  | |¡S t  | ||¡S ©N)Ú	functoolsÚreduce)ÚfuncÚseqÚinitial© r
   úc/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/toolz/sandbox/parallel.pyÚ_reduce   s   r   é€   c                 C   s€   |dksJ ‚|du r| }t ||ƒ}|tkr|t t| ¡|ƒ}n|tjt| |d�|ƒ}t|ƒ}t|ƒdkr8|d S t||||d�S )aƒ  
    Reduce without guarantee of ordered reduction.

    Parameters
    ----------
    binops
        Associative operator. The associative property allows us to
        leverage a parallel map to perform reductions in parallel.


    inputs:

    ``binop``     - associative operator. The associative property allows us to
                    leverage a parallel map to perform reductions in parallel.

    ``seq``       - a sequence to be aggregated
    ``default``   - an identity element like 0 for ``add`` or 1 for mul

    ``map``       - an implementation of ``map``. This may be parallel and
                    determines how work is distributed.
    ``chunksize`` - Number of elements of ``seq`` that should be handled
                    within a single function call
    ``combine``   - Binary operator to combine two intermediate results.
                    If ``binop`` is of type (total, item) -> total
                    then ``combine`` is of type (total, total) -> total
                    Defaults to ``binop`` for common case of operators like add

    Fold chunks up the collection into blocks of size ``chunksize`` and then
    feeds each of these to calls to ``reduce``. This work is distributed
    with a call to ``map``, gathered back and then refolded to finish the
    computation. In this way ``fold`` specifies only how to chunk up data but
    leaves the distribution of this work to an externally provided ``map``
    function. This function can be sequential or rely on multithreading,
    multiprocessing, or even distributed solutions.

    If ``map`` intends to serialize functions it should be prepared to accept
    and serialize lambdas. Note that the standard ``pickle`` module fails
    here.

    Example
    -------

    >>> # Provide a parallel map to accomplish a parallel sum
    >>> from operator import add
    >>> fold(add, [1, 2, 3, 4], chunksize=2, map=map)
    10
    é   N)r	   r   )ÚmapÚ	chunksize)r   r   r   Úpartialr   ÚlistÚlenÚfold)Úbinopr   Údefaultr   r   ÚcombineÚchunksÚresultsr
   r
   r   r      s"   0

þþr   r   )r   Útoolz.itertoolzr   Útoolz.utilsr   r   r   r   r
   r
   r
   r   Ú<module>   s
    
