
    biD                       d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 d dlmZmZ d dlmZmZ d dlmZ d dlZd dlmZ d d	lmZmZmZ d dlmZ d d
lmZ d dlmZm Z m!Z!m"Z"m#Z# d dl$m%Z%m&Z& d dl'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z<m=Z= 	 d dl>Z> ej                         r	d dlAmBZBmCZC nd dlDmBZBmCZC d\dZEd ZFd ZG e=e      d]d       ZH e=e      d]d       ZI e"ej                  ej                         e=e      d^d              ZJd_dZL e"ej                  ej                         e=e      d^d              ZMd_dZO e=e      d^d       ZP e=e      d^d        ZQ e=e      d]d!       ZR e=e      d]d"       ZS e=e      d_d#d$d%       ZT e=e      d_d#d$d&       ZU e=e      d^d'       ZVd( ZW e=e      d^d)       ZXd* ZYej                  eFd+dfd,ZZej                  eFd+ddfd-Z[d`d.Z\ e=e      d]d/       Z] e=e      d]d0       Z^d1ej                  eFd+ddfd2Z_d3 Z`d1d d+ej                  ddfd4Zad1d d+ej                  ddfd5Zb	 dad6Zc e=e      dad7       Zd e=e      	 dad8       Zed9 Zfd: Zg e=e      dad;       Zh e=e      	 dad<       Zidbd=Zjd> Zkd\d?Zldcd@ZmdcdAZn	 d^dBZodC ZpdD Zq e=e      d^dE       Zr e=e      d^dF       Zs e=e      d^dG       Zt e=e      d^dH       ZudI ZvdJ ZwdddKZx	 	 	 	 	 dedLZydM ZzdN Z{ e=e      dfdO       Z| e=e      dfdP       Z}dgdQZ~dgdRZ e=e      dhdS       Z e=e      didT       Z e=e      didU       Z e=e      	 	 	 	 	 djdddVdW       ZdX Z	 	 	 	 dkdYZ e=e      	 	 	 	 	 djdddVdZ       Zd[ Zy# e?$ r dZ>Y w xY w)l    )annotationsN)Iterable)partialreduce)productrepeat)IntegralNumber)mul)Version)
accumulatedroppluck)chunk)Array_concatenate2
handle_out
implementsunknown_chunk_message)arangediagonal)divide_lookupnannumel_lookupnumel_lookup)NUMPY_GE_200)
array_safeasarray_safeis_arraylikemeta_from_arrayvalidate_axis)oneszeros)tokenize)HighLevelGraph)applydeepmapderived_from)_tree_reduce	reductionc           	         d }t        j                  t        t        j                  | ||                  } || ||      S )Nc                .    t        | dt        d            S )N__array_priority__z-inf)getattrfloat)xs    P/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/dask/array/reductions.py<lambda>zdivide.<locals>.<lambda>5   s    GA3U6]C     )keydtype)r   dispatchtypebuiltinsmax)abr5   r3   fs        r0   divider=   4   s8    
CCtHLLA3$?@AAQr2   c                    t        | fi |S N)r   r/   kwargss     r0   numelrB   :   s    $V$$r2   c                    t        | fi |S r?   )r   r@   s     r0   nannumelrD   >   s    1'''r2   Fc           
         |>t        t        j                  d| j                        j	                         dt
              }t        | t        j                  t        j                  |||||      }|S )N   r4   r5   axiskeepdimsr5   split_everyout)r-   npr"   r5   sumobjectr)   r   )r:   rH   r5   rI   rJ   rK   results          r0   rM   rM   B   s^    }!''2668'6J						F Mr2   c           
         ||}n>t        t        j                  d| j                        j	                         dt
              }t        | t        j                  t        j                  |||||      S NrF   r4   r5   rG   )r-   rL   r!   r5   prodrN   r)   r   r:   rH   r5   rI   rJ   rK   dts          r0   rS   rS   S   s`    RWWT1668'6J	



	 	r2   c                j    t        | t        t        j                  t        ||| j                  ||	      S N)combinerH   rI   r5   rJ   rK   )r)   	chunk_minr   minr5   r:   rH   rI   rJ   rK   s        r0   rZ   rZ   e   4     			gg
 
r2   c                    | j                   dk(  r#t        g | | j                  | j                        S t	        j
                  | ||      S )z-Version of np.min which ignores size 0 arraysr   ndminr5   rH   rI   )sizer   ndimr5   rL   rZ   r/   rH   rI   s      r0   rY   rY   u   9    vv{"aqvvQWW==vvadX66r2   c                j    t        | t        t        j                  t        ||| j                  ||	      S rW   )r)   	chunk_maxr   r9   r5   r[   s        r0   r9   r9   }   r\   r2   c                    | j                   dk(  r#t        g | | j                  | j                        S t	        j
                  | ||      S )z-Version of np.max which ignores size 0 arraysr   r^   r`   )ra   r   rb   r5   rL   r9   rc   s      r0   rf   rf      rd   r2   c           
     `    t        | t        j                  t        j                  ||d||      S NboolrG   )r)   r   anyr[   s        r0   rk   rk      /    						 	r2   c           
     `    t        | t        j                  t        j                  ||d||      S ri   )r)   r   allr[   s        r0   rn   rn      rl   r2   c           
         ||}nCt        t        j                  t        j                  d| j
                              dt              }t        | t        j                  t        j                  |||||      S rQ   )	r-   r   nansumrL   r!   r5   rN   r)   rM   rT   s          r0   rp   rp      s`    U\\"''$agg">?&Q				 	r2   c           
         ||}nCt        t        j                  t        j                  d| j
                              dt              }t        | t        j                  t        j                  |||||      S rQ   )
r-   r   rp   rL   r!   r5   rN   r)   nanprodrS   rT   s          r0   rr   rr      s`    U\\"''$agg">?&Q	

	 	r2   
sequential)methodc               ~    t        t        j                  t        j                  d| ||||t
        j                  	      S )ai  Dask added an additional keyword-only argument ``method``.

    method : {'sequential', 'blelloch'}, optional
        Choose which method to use to perform the cumsum.  Default is 'sequential'.

        * 'sequential' performs the cumsum of each prior block before the current block.
        * 'blelloch' is a work-efficient parallel cumsum.  It exposes parallelism by
            first taking the sum of each block and combines the sums via a binary tree.
            This method may be faster or more memory efficient depending on workload,
            scheduler, and hardware.  More benchmarking is necessary.
    r   rK   rt   preop)cumreductionr   	nancumsumoperatoraddrL   rp   r/   rH   r5   rK   rt   s        r0   ry   ry      s8     		ii
 
r2   c               ~    t        t        j                  t        j                  d| ||||t
        j                  	      S )at  Dask added an additional keyword-only argument ``method``.

    method : {'sequential', 'blelloch'}, optional
        Choose which method to use to perform the cumprod.  Default is 'sequential'.

        * 'sequential' performs the cumprod of each prior block before the current block.
        * 'blelloch' is a work-efficient parallel cumprod.  It exposes parallelism by first
            taking the product of each block and combines the products via a binary tree.
            This method may be faster or more memory efficient depending on workload,
            scheduler, and hardware.  More benchmarking is necessary.
    rF   rv   )rx   r   
nancumprodrz   r   rL   rr   r|   s        r0   r~   r~      s:     		jj
 
r2   c           
         t        j                  | j                        rt        dt               | j                  dk(  rt        d      t        | t        t        ||| j                  ||      S )N Arrays chunk sizes are unknown. r   zAzero-size array to reduction operation fmin which has no identityrG   )rL   isnanra   
ValueErrorr   r)   _nanmin_skipr5   r[   s        r0   nanminr   	  m    	xx;<Q;RSTTvv{O
 	
 	gg	 	r2   c                D   | j                   dkD  rQt        j                         5  t        j                  ddt               t        j                  | ||      cd d d        S t        t        j                  g | j                        t        |             S # 1 sw Y   y xY wNr   ignorezAll-NaN slice encounteredr`   r4   like)ra   warningscatch_warningsfilterwarningsRuntimeWarningrL   r   r   arrayr5   r   x_chunkrH   rI   s      r0   r   r         ||a$$& 	D##5~ 99W4(C		D 	D HHRw}}-OG4L
 	
	D 	D   3BBc           
         t        j                  | j                        rt        dt               | j                  dk(  rt        d      t        | t        t        ||| j                  ||      S )Nr   r   zAzero-size array to reduction operation fmax which has no identityrG   )rL   r   ra   r   r   r)   _nanmax_skipr5   r[   s        r0   nanmaxr   *  r   r2   c                D   | j                   dkD  rQt        j                         5  t        j                  ddt               t        j                  | ||      cd d d        S t        t        j                  g | j                        t        |             S # 1 sw Y   y xY wr   )ra   r   r   r   r   rL   r   r   r   r5   r   r   s      r0   r   r   >  r   r   f8c                @    |r| S  || fd|i|} || fd|i|}||dS )Nr5   ntotal )r/   rM   rB   r5   computing_metarA   r   r   s           r0   
mean_chunkr   K  s?     a'u''A))&)EU##r2   c                    t        | t              s| g} |st        d |       n| } t        ||      j                  dd|i|}|r|S t        d |       }	 t        |	|      j                  dd|i|}
||
dS )Nc                    | d   S Nr   r   pairs    r0   r1   zmean_combine.<locals>.<lambda>c  
    d3i r2   axesrH   c                    | d   S Nr   r   r   s    r0   r1   zmean_combine.<locals>.<lambda>i  
    $w- r2   r   r   )
isinstancelistr&   r   rM   )pairsrM   rB   r5   rH   r   rA   nsr   totalsr   s              r0   mean_combiner   W  s     eT"7E'	/5B(bt$((=d=f=A/7F0M&t,00EdEfEEU##r2   c                H   |st        d |       n| }t        ||      }t        j                  |f||d|}|r|S t        d |       } t        ||      j                  d||d|}t        j                  dd      5  t        |||      cd d d        S # 1 sw Y   y xY w)	Nc                    | d   S r   r   r   s    r0   r1   zmean_agg.<locals>.<lambda>p  r   r2   r   rH   r5   c                    | d   S r   r   r   s    r0   r1   zmean_agg.<locals>.<lambda>w  r   r2   r   r=   invalidr4   r   )r&   r   rL   rM   errstater=   )	r   r5   rH   r   rA   r   r   r   r   s	            r0   mean_aggr   o  s    7E'	/5Bbt$A
q3t53F3A/7F0M&t,00Rd%R6RE	Hh	7 -eQe,- - -s    BB!c                   ||}n]| j                   t        k(  rt        }nCt        t        j                  t        j
                  d| j                               dt              }t        | t        t        ||||t        |d
      S )NrR   shaper5   r5   FrH   rI   r5   rJ   rX   rK   concatenate)
r5   rN   r-   rL   meanr"   r)   r   r   r   rT   s          r0   r   r   ~  so    	
F	RWWRXXD@A7FS	 r2   c                L   ||}nCt        t        j                  t        j                  d| j                              dt
              }t        | t        t        t        j                  t              t        |||||dt        t        t        j                  t              
      S )NrR   r   r5   )rM   rB   FrH   rI   r5   rJ   rK   r   rX   )r-   rL   r   r!   r5   rN   r)   r   r   r   rp   rD   r   r   rT   s          r0   nanmeanr     sx    RWWRWW4qww?@'6R	
H=%,,hG r2      c                   |r| S  || fi |}|j                  t        j                        }|r
 || fi |}	n || fd|i|}	t        j                  dd      5  |	|z  }
d d d        | 
z
  }t        j                  | j
                  t        j                        rt        j                  |      }t        d|dz         D cg c]  } |||z  fd|i| }}t        j                  |d      }|	||dS # 1 sw Y   xY wc c}w )	Nr5   r   r   r   rF   rH   r   r   M)
astyperL   int64r   
issubdtyper5   complexfloatingabsrangestack)AorderrM   rB   r5   r   implicit_complex_dtyperA   r   r   udixsr   s                  r0   moment_chunkr     s     a6A	AA  A-U-f-	Hh	7 AI	AA	}}QWWb001FF1I49!UQY4G	Hq#ad
*%
*6
*	HB	H
"A++ 
 
Is   C6D6C?c           	     V    | d|dz
  f   j                   dd|i| ||||z  z  fd|i|z   }t        d|dz
        D ]h  }t        j                  |      t        j                  |      t        j                  ||z
        z  z  }	||	 || d||z
  dz
  f   ||z  z  fd|i|z  z  }j |S )N.r   rH   rF   r   )rM   r   math	factorial)
Msr   
inner_termr   rM   rH   rA   r   kcoeffs
             r0   _moment_helperr     s    3	>3D3F3c
Z7%)7-37 	A 1eai  Vu%):T^^ETUI=V)VW	USCQ./*a-?UdUfUUUV Hr2   c                   t        | t              s| g} d |d<   d|d<   |st        d |       n| }t        ||      } |j                  dd|i|}	|r|	S t        t        d |       |      }
t        t        d |       |      } |
j                  dd|i|}t        j                  d	d	
      5  t        j                  |j                  t
        j                        r/t        ||	      }t        j                  t        |
|      |z
        }nt        ||	|      }t        |
||      |z
  }d d d        t        d|dz         D cg c]  }t        ||||||       }}t        j                  |d      }||	|dS # 1 sw Y   QxY wc c}w )Nr5   TrI   c                    | d   S r   r   r   s    r0   r1   z moment_combine.<locals>.<lambda>  r   r2   r   rH   c                    | d   S r   r   r   s    r0   r1   z moment_combine.<locals>.<lambda>  
    W r2   c                    | d   S Nr   r   r   s    r0   r1   z moment_combine.<locals>.<lambda>  
    DI r2   r   r   r4   r   rF   r   r   r   r   )r   r   r&   r   rM   rL   r   r   r5   r   r=   r   r   r   r   )r   r   ddofr5   rM   rH   r   rA   r   r   r   r   r   mur   or   r   s                     r0   moment_combiner     s    eT"F7OF:7E'	/5B	r	%B#D#F#A7#=uEDQF	w5u=D	IBFJJ+D+F+E	Hh	7 >==b&8&89q!Bvr 2R 78Jq.B%82=J> q%!)$
 	r2z1c4@
B 
 	"A++> >
s   /A=E<F<Fc           	        t        | t              s| g} ||d<   |j                         }d|d<   d |d<   |st        d |       n| }	t	        |	|      }	 |	j
                  dd|i|}
|r|
S t	        t        d |       |      }t	        t        d |       |      }t         |j
                  dd|i||
      }t        j                  d	d	
      5  t        j                  |j                  t        j                        r#t        j                  t        ||	      |z
        }nt        ||	|      |z
  }d d d        t        ||	||||      } |
j
                  dd|i||z
  }t        |t              r|dk  rCt        j                  }n2|t        j                   j"                  urt        j                  ||dk  <   t        |||      S # 1 sw Y   xY w)Nr5   TrI   c                    | d   S r   r   r   s    r0   r1   zmoment_agg.<locals>.<lambda>  r   r2   r   rH   c                    | d   S r   r   r   s    r0   r1   zmoment_agg.<locals>.<lambda>  r   r2   c                    | d   S r   r   r   s    r0   r1   zmoment_agg.<locals>.<lambda>  r   r2   r   r   r4   r   r   )r   r   copyr&   r   rM   r=   rL   r   r   r5   r   r   r   r
   nanmamasked)r   r   r   r5   rM   rH   r   rA   
keepdim_kwr   r   r   r   r   r   r   denominators                    r0   
moment_aggr     s    eT"F7O J!JzJw7E'	/5B	r	%B'D'J'A7#=uEDQF	w5u=D	IB	


33
3Q	7B	Hh	7 >==r'9'9:vr 2R 78J%82=J	> 	r2z5#tVDA!%%,T,V,t3K +v&?&&K	BEELL	(')vvK!O$![..#> >s   A#GGc                |   t        |t              r|dk  rt        d      |dk  rq| j                  |      }|dk(  r-t	        |j
                  |j                  d|j                        S t        |j
                  |j                  d|j                        S ||}	nCt        t        j                  t        j                  d| j                  	            d
t              }	|du xr t        j                  |       }
t        | t!        t"        ||
      t!        t$        ||      |||	||dt!        t&        |      
      S )a  Calculate the nth centralized moment.

    Parameters
    ----------
    a : Array
        Data over which to compute moment
    order : int
        Order of the moment that is returned, must be >= 2.
    axis : int, optional
        Axis along which the central moment is computed. The default is to
        compute the moment of the flattened array.
    dtype : data-type, optional
        Type to use in computing the moment. For arrays of integer type the
        default is float64; for arrays of float types it is the same as the
        array type.
    keepdims : bool, optional
        If this is set to True, the axes which are reduced are left in the
        result as dimensions with size one. With this option, the result
        will broadcast correctly against the original array.
    ddof : int, optional
        "Delta Degrees of Freedom": the divisor used in the calculation is
        N - ddof, where N represents the number of elements. By default
        ddof is zero.

    Returns
    -------
    moment : Array

    References
    ----------
    .. [1] Pebay, Philippe (2008), "Formulas for Robust, One-Pass Parallel
        Computation of Covariances and Arbitrary-Order Statistical Moments",
        Technical Report SAND2008-6212, Sandia National Laboratories.

    r   zOrder must be an integer >= 0r   r   r   )chunksr5   metaNrR   r   r5   )r   r   )r   r   F)r   r   )r   r	   r   rM   r!   r   r   _metar"   r-   rL   varr5   rN   iscomplexobjr)   r   r   r   r   )r:   r   rH   r5   rI   r   rJ   rK   reducedrU   r   s              r0   momentr   0  s   L eX&%!)899qy%%T%"A:gnnDw}}  MM'..7==
 	
 RVVBGG$agg>?&Q"d]Arq/A	>T	
 	
%d3e4 r2   c                8   ||}nCt        t        j                  t        j                  d| j                              dt
              }|d u xr t        j                  |       }t        | t        t        |      t        t        |      ||||t        d|d      S )	NrR   r   r5   )r   )r   r   F)rH   rI   r5   rJ   rX   namerK   r   )r-   rL   r   r!   r5   rN   r   r)   r   r   r   r   	r:   rH   r5   rI   r   rJ   rK   rU   r   s	            r0   r   r   |  s    RVVBGG$agg>?&Q"d]Arq/A	5KL
& r2   c                   ||}nCt        t        j                  t        j                  d| j                              dt
              }|d u xr t        j                  |       }t        | t        t        t        j                  t        |      t        t        t        j                  |      ||||t        t        t        j                        |d
      S )	NrR   r   r5   )rM   rB   r   )rM   r   )rM   Fr   )r-   rL   r   r!   r5   rN   r   r)   r   r   r   rp   rD   r   r   r   s	            r0   nanvarr    s     RVVBGG$agg>?&Q"d]Arq/A	#9		
 	
		5BII6 r2   c                    t        | t        j                  j                        r@| j                  s4| j
                  j                         rt        j                  j                  S t        j                  |       S r?   )	r   rL   r   masked_arrayr   maskrn   r   sqrtr:   s    r0   _sqrtr    sD    !RUU''(QVVZZ\uu||771:r2   c                \    t        | d      r| j                  t        |       S t        |       S )a  A version of sqrt that properly handles scalar masked arrays.

    To mimic ``np.ma`` reductions, we need to convert scalar masked arrays that
    have an active mask to the ``np.ma.masked`` singleton. This is properly
    handled automatically for reduction code, but not for ufuncs. We implement
    a simple version here, since calling `np.ma.sqrt` everywhere is
    significantly more expensive.
    	_elemwise)hasattrr	  r  r  s    r0   	safe_sqrtr    s(     q+{{5!$$8Or2   c                    t        t        | ||||||            }|r ||j                  k7  r|j                  |      }|S N)rH   r5   rI   r   rJ   rK   )r  r   r5   r   r:   rH   r5   rI   r   rJ   rK   rO   s           r0   stdr    sL    #	

F &,,&u%Mr2   c                    t        t        | ||||||            }|r ||j                  k7  r|j                  |      }|S r  )r  r  r5   r   r  s           r0   nanstdr    sN     #	

F &,,&u%Mr2   c           	        t        | t              rV| d   j                  | d   j                  k(  sJ t        |      | d   j                  k(  s| d   j                  dk(  rdn|d   }n.t        |      | j                  k(  s| j                  dk(  rdn|d   }| d   }| d   }|5 ||||      }|j	                         |   }|j	                         |   }||fS  |||      }t        t        j                  t        t        t        |j                                       }|j                  ||       t        |      }||   }||   }|r,t        j                  ||      }t        j                  ||      }||fS )z3Merge intermediate results from ``arg_*`` functionsvalsargrF   Nr   r`   r   )r   dictrb   lenravelr   rL   ogridtuplemapslicer   insertexpand_dims)datarH   argfuncrI   r  r  
local_argsindss           r0   _arg_combiner"    sj   $ F|  DK$4$4444 4yDL---f1B1Ba1G a 	 4yDII-atT!W<D
u+C|Tx@
zz|J'iik*% 9 T-
BHHU3uj.>.>#?@ABD*%T{Dz$i>>$-D..d+C9r2   c                t   t        |      |j                  k(  s|j                  dk(  rd n|d   } | ||d      } |||d      }|j                  dkD  rs|l|\  }}	t        j                  |j	                         d   |j
                        }
t        d t        ||
      D              }t        j                  ||	      |d d  n||z  }t        |t        j                  j                        rmd|j                  v r t        j                  j                  |      }nt        j                  j                  |      }t        j                  j                  ||      }	 t        j                   ||j
                  d|j"                  fd|j"                  fg	      }||d<   ||d<   |S # t$        $ r t'               }Y !w xY w)
NrF   r   Tr`   c              3  ,   K   | ]  \  }}||z     y wr?   r   ).0r   r   s      r0   	<genexpr>zarg_chunk.<locals>.<genexpr>  s     CAa!eCs   rZ   r  r  r   )r  rb   rL   unravel_indexr  r   r  zipravel_multi_indexr   r   r  __name__minimum_fill_valuemaximum_fill_valuefilled
empty_liker5   	TypeErrorr  )funcr  r/   rH   offset_infoarg_axisr  r  offsettotal_shapeind	total_ind
fill_valuerO   s                 r0   	arg_chunkr8    sx   4yAFF*affkttAwH40D
!(T
2Cvvz"-FK""399;q>177;CC#fc2BCCI)))[ACF;C$**+G$$$11$7J11$7Juu||D*-

FDJJ+?%AS*T
 F6NF5MM  s   <F! !F76F7c                    t        ||| d      \  }}	 t        j                  ||j                  d|j                  fd|j                  fg      }||d<   ||d<   |S # t
        $ r t               }Y !w xY w)NTrI   r  r  r   )r"  rL   r.  r   r5   r/  r  )r  r  rH   rA   r  r  rO   s          r0   arg_combiner;  .  s|    T44@IC

FDJJ+?%AS*T
 F6NF5MM  s   <A A21A2c                &    t        ||| |      d   S )Nr:  r   )r"  )r  r  rH   rI   rA   s        r0   arg_aggr=  >  s    dGh?BBr2   c                    t        ||| |      \  }}t        j                  t        j                  |            rt	        d      |S )Nr:  zAll NaN slice encountered)r"  rL   rk   r   r   )r  r  rH   rI   rA   r  r  s          r0   
nanarg_aggr?  B  s;    T48DIC	vvbhhtn455Jr2   c           	     |   !t        t        | j                              d}nHt        t              r)t        | j                        f| j                  dk(  }nt        d d      D ]N  }	| j                  |	   }
t        |
      dkD  s!t        j                  |
      j                         sEt        d       dt        | |||       }| j                  }t        t!        t#        t        | j$                               }t        t!        d | j                  D               }|r t'        |t)        | j*                              }nt-        d	   |      }t        fd
t/        | j                        D              }
t'        ||      D ci c]  \  }}|f|z   ||f|z   |f }}}t        j0                  t3        dgt5        |                   }d}t7        |      r|}|j8                  }t;        j<                  ||| g      }t?        |||
||      }tA        ||||||      }tC        ||      S c c}}w )a7  Generic function for argreduction.

    Parameters
    ----------
    x : Array
    chunk : callable
        Partialed ``arg_chunk``.
    combine : callable
        Partialed ``arg_combine``.
    agg : callable
        Partialed ``arg_agg``.
    axis : int, optional
    split_every : int or dict, optional
    NTrF   z(axis must be either `None` or int, got ''zArg-reductions do not work with arrays that have unknown chunksizes. At some point in your computation this array lost chunking information.

A possible solution is with 
  x.compute_chunk_sizes()zarg-reduce-c              3  X   K   | ]"  }t        t        j                  |d d d       $ y w)Nr   r   )r   rz   r{   )r%  bds     r0   r&  z arg_reduction.<locals>.<genexpr>s  s#     UbZb"gqAUs   (*r   c              3  L   K   | ]  \  }}|v rd t        |      z  n|  yw)rR   N)r  )r%  r   crH   s      r0   r&  z arg_reduction.<locals>.<genexpr>y  s(     W!QAI4#a&=14Ws   !$r   dependencies)r5   r   )rI   r5   rJ   rX   )"r  r   rb   r   r	   r    r/  r   r  rL   r   rk   r   r#   r   r   r   r  	numblocksr(  r   r   r   	enumerateargminr   r   r   r5   r$   from_collectionsr   r(   r   )r/   r   rX   aggrH   rI   rJ   rK   r  axr   r   oldkeysoffsetsr1  r   offdskr5   r   graphtmprO   s       `                   r0   arg_reductionrU  I  s#   " |U166]#	D(	#T166*w!B4&JKK 	"v;?rxx/335, 	 $5';GHID
&&CUAKK012D7UAHHUVWG'6!''?3DGW-W9QXXCVWWF D+.Q 
!ecVaZs33C 
 IIlA3_Q-?@AEDE 

++D#QCHE
tV5t
<CF c6""3s   H8c                    	 t        j                  | |fi |S # t        $ rP t        j                  t        j                  t        j
                  |       t        j                  |       |fi |cY S w xY wr?   )r   	nanargminr   rL   wherer   infr/   rH   rA   s      r0   
_nanargminr[    s^    Qq$1&11 QrxxRVVQ?PPPQs    AA21A2c                    	 t        j                  | |fi |S # t        $ rQ t        j                  t        j                  t        j
                  |       t        j                   |       |fi |cY S w xY wr?   )r   	nanargmaxr   rL   rX  r   rY  rZ  s      r0   
_nanargmaxr^    s`    Rq$1&11 RrxxbffWa@$Q&QQRs    AA32A3c           
         t        | t        t        t        j                  t        j
                        t        t        t        j
                        t        t        t        j
                        ||||      S N)rH   rI   rJ   rK   )rU  r   r8  r   r9   argmaxr;  r=  r[   s        r0   ra  ra    N    		599ell3U\\*&	 	r2   c           
         t        | t        t        t        j                  t        j
                        t        t        t        j
                        t        t        t        j
                        ||||      S r`  )rU  r   r8  r   rZ   rJ  r;  r=  r[   s        r0   rJ  rJ    rb  r2   c           
         t        | t        t        t        j                  t
              t        t        t
              t        t        t
              ||||      S r`  )rU  r   r8  r   r   r^  r;  r?  r[   s        r0   r]  r]    B    		5<<4Z(
J'	 	r2   c           
         t        | t        t        t        j                  t
              t        t        t
              t        t        t
              ||||      S r`  )rU  r   r8  r   r   r[  r;  r?  r[   s        r0   rW  rW    re  r2   c                &     || | |||            S )a  Combine results of a parallel prefix scan such as cumsum

    Parameters
    ----------
    func : callable
        Cumulative function (e.g. ``np.cumsum``)
    binop : callable
        Associative function (e.g. ``add``)
    pre : np.array
        The value calculated in parallel from ``preop``.
        For example, the sum of all the previous blocks.
    x : np.array
        Current block
    axis : int
    dtype : dtype

    Returns
    -------
    np.array
    r   r   )r0  binopprer/   rH   r5   s         r0   _prefixscan_combinerj    s    0 d14u566r2   c                     | |||      S )a  Compute the prefix scan (e.g., cumsum) on the first block

    Parameters
    ----------
    func : callable
        Cumulative function (e.g. ``np.cumsum``)
    x : np.array
        Current block
    axis : int
    dtype : dtype

    Returns
    -------
    np.array
    r   r   )r0  r/   rH   r5   s       r0   _prefixscan_firstrl    s      E**r2   c                Z   |,|j                         j                  |j                        }d}|6t         | t	        j
                  d|j                              dt              }t        |t              sJ t        ||j                        }| j                   dt        | |||||       }|f}|j                  ||d|      }	t        |j                   |         D 
cg c]J  }
t#        t%        t'        |j                         D cg c]  \  }}||k7  rt        |      n|
g c}}       L c}}}
x^ }}}|D cg c]   }|D cg c]  }|	j(                  f|z    c}" }}}i }t+        |      }d}|d	k\  r>d
}d	}||k  rst        |d
z
  ||      D ]N  }
g }t-        ||
   ||
|z
     ||
         D ])  \  }}}||z   ||
fz   }|||f||<   |j/                  |       + |||
<   P |}|d	z  }|d
z  }||k  rst1        j2                  d	d	t5        j6                  t5        j8                  |d	z              z        }|d	z  }|dkD  rvt        ||z   d
z
  ||      D ]N  }
g }t-        ||
   ||
|z
     ||
         D ])  \  }}}||z   ||
fz   }|||f||<   |j/                  |       + |||
<   P |}|d	z  }|d
z  }|dkD  rv|r||d   D ]!  }t:        | |j(                  f|z   ||f|||z   <   # t-        t=        d
|      |      D ]:  \  }}t-        ||      D ]&  \  }}t>        | |||j(                  f|z   ||f|||z   <   ( < t+        |      d	k  r|g}n||	g}tA        jB                  |||      }tE        |||jF                  |	j                        } tI        ||       S c c}}w c c}}}
w c c}w c c}}w )a  Generic function to perform parallel cumulative scan (a.k.a prefix scan)

    The Blelloch prefix scan is work-efficient and exposes parallelism.
    A parallel cumsum works by first taking the sum of each block, then do a binary tree
    merge followed by a fan-out (i.e., the Brent-Kung pattern).  We then take the cumsum
    of each block and add the sum of the previous blocks.

    When performing a cumsum across N chunks, this method has 2 * lg(N) levels of dependencies.
    In contrast, the sequential method has N levels of dependencies.

    Floating point operations should be more accurate with this method compared to sequential.

    Parameters
    ----------
    func : callable
        Cumulative function (e.g. ``np.cumsum``)
    preop : callable
        Function to get the final value of a cumulative function (e.g., ``np.sum``)
    binop : callable
        Associative function (e.g. ``add``)
    x : dask array
    axis : int
    dtype : dtype

    Returns
    -------
    dask array
    r   r   r   r4   r5   -T)rH   rI   r5   r   rF   rF  )%flattenrechunknpartitionsr-   rL   r!   r5   rN   r   r	   r    rb   r*  r#   
map_blocksr   rH  r   r   rI  r   r  r(  appendr8   r9   r   ceillog2rl  r   rj  r$   rK  r   r   r   )!r0  rw   rh  r/   rH   r5   rK   r   base_keybatchesr   jnbindices
last_indexfull_indicesr  indexprefix_valsrR  n_valslevelstridestride2new_valsleft_val	right_valr3   indexesvaldepsrS  rO   s!                                    r0   prefixscan_blellochr  
  sH   : |IIKq}}5}RWWT9:GVLdH%%%qvv&Dmm_AhtT5%EJKLDwH ll5td%lHG q{{4()+ +  	?H?UVeaqDy%)qc1V	
+ Wj< LSS4>W\\Oe+>SKS
CFE{7Q;8 *25AJAJ 7Q3 ).E8Y #U*eQZ7C %x;CHOOC() "*A* FqLGQJE " ,,q!tyy6Q;1G'H"HIAqj7V+a/A *25AJAJ 7Q3 ).E8Y #U*eQZ7C %x;CHOOC() "*A* GqLFQJE qj !!_ 	E!	E!%C5 !	 !a!6D 
	MGT!'40 	
s'VVI%)Hu$%	
	 <1s7|++D#DIE5$'--8Fc6""Q W+ ?Ss0   "'N	N&N 	N'	N" N'N"N'c	                f   |dk(  r|t        d      t        | ||||      S |dk7  rt        d|      ;j                  dkD  r*j	                         j                  j                        d	|6t         | t        j                  d
j                              dt              }t        t              sJ t        j                        j                  | |      }	| j                    dt#        | |||       }
j$                     }t'        ddd      }|fz  t'        dd      fz   |fj                  z
  dz
  z  z   }t)        t+        t-        j$                        D cg c]  \  }}|k7  rt/        |      nd	g c}}       }t1               }|D ]p  }t3        fdt-        |      D              }t4        t        j6                  j8                  ||	j                  fd|if||
df|z   <   |	j:                  f|z   ||
f|z   <   r t/        d|      D ]  }|}t)        t+        t-        j$                        D cg c]  \  }}|k7  rt/        |      n|g c}}       }t=        ||      D ]R  \  }}|
df|z   }||
df|z   t>        j@                  |	j:                  f|z   |ff||<   |||	j:                  f|z   f||
f|z   <   T  tC        jD                  |
||	g      }tG        ||
jH                  |	j                  j8                        }tK        ||      S c c}}w c c}}w )a  Generic function for cumulative reduction

    Parameters
    ----------
    func: callable
        Cumulative function like np.cumsum or np.cumprod
    binop: callable
        Associated binary operator like ``np.cumsum->add`` or ``np.cumprod->mul``
    ident: Number
        Associated identity like ``np.cumsum->0`` or ``np.cumprod->1``
    x: dask Array
    axis: int
    dtype: dtype
    method : {'sequential', 'blelloch'}, optional
        Choose which method to use to perform the cumsum.  Default is 'sequential'.

        * 'sequential' performs the scan of each prior block before the current block.
        * 'blelloch' is a work-efficient parallel scan.  It exposes parallelism by first
          calling ``preop`` on each block and combines the values via a binary tree.
          This method may be faster or more memory efficient depending on workload,
          scheduler, and hardware.  More benchmarking is necessary.
    preop: callable, optional
        Function used by 'blelloch' method,
        like ``np.cumsum->np.sum`` or ``np.cumprod->np.prod``

    Returns
    -------
    dask array

    See also
    --------
    cumsum
    cumprod
    blellochNz>cumreduction with "blelloch" method required `preop=` argument)rK   rs   zMInvalid method for cumreduction.  Expected "sequential" or "blelloch".  Got: rF   rn  r   ro  r4   r5   r   rp  r   c              3  V   K   | ]   \  }}|k7  rj                   |   |   nd  " ywrF   Nrn  )r%  r   iirH   r/   s      r0   r&  zcumreduction.<locals>.<genexpr>  s,     Veadahhqk"o9Vs   &)r   extrarF  )r   )&r/  r  r   rb   rq  rr  rs  r-   rL   r!   r5   rN   r   r	   r    rt  r*  r#   rH  r  r   r   rI  r   r  r  r%   	full_liker   r   r(  rz   getitemr$   rK  r   r   r   )r0  rh  identr/   rH   r5   rK   rt   rw   mr   r   fullslcr   r{  r|  rR  r5  r   last_indicesr  rN  
this_slicerS  rO   s      ``                     r0   rx   rx     sI   Z =P  #4q$3OO	<	[\b[ef
 	
 |66A:		##1==#9A}RWWT9:GVLdH%%%qvv&D	TE2Amm_AhtT5%EJKLD	DAtT"D'D.E"dO-
-166D=1;L0M
MCy?UVeaqDy%)qc1VWG &C -VyQT~VVLLWWeQWW%e	&
T7Oc!"  ffY_TGcM- 1a[ FAJ1;;AWXvr2rTz%)s2X

 L'2 	FHC3.Jw#%!!AFF9s?C8C
O
 #(affY_!EC#	FF  ++D#QCHE5$!''@Fc6""? W" Ys   3L'L-c                   t        | t        j                  j                        s$t        |t        j                  j                        r}t        j                  j	                  |       t        j                  j	                  |      z   }t        j                  j                  |t        j                  j                  |            S | |z   S N)r  r   rL   r   r  getdatagetmaskarrayr:   r;   valuess      r0   _cumsum_merger        !RUU''(Jq"%%:L:L,Mq!BEEMM!$44uu!!&ruu/A/A!/D!EEq5Lr2   c                   t        | t        j                  j                        s$t        |t        j                  j                        r}t        j                  j	                  |       t        j                  j	                  |      z  }t        j                  j                  |t        j                  j                  |            S | |z  S r  r  r  s      r0   _cumprod_merger    r  r2   c                j    t        t        j                  t        d| ||||t        j                  	      S )ac  Dask added an additional keyword-only argument ``method``.

    method : {'sequential', 'blelloch'}, optional
        Choose which method to use to perform the cumsum.  Default is 'sequential'.

        * 'sequential' performs the cumsum of each prior block before the current block.
        * 'blelloch' is a work-efficient parallel cumsum.  It exposes parallelism by
          first taking the sum of each block and combines the sums via a binary tree.
          This method may be faster or more memory efficient depending on workload,
          scheduler, and hardware.  More benchmarking is necessary.
    r   rv   )rx   rL   cumsumr  rM   r|   s        r0   r  r    s4     
				ff
 
r2   c                j    t        t        j                  t        d| ||||t        j                  	      S )an  Dask added an additional keyword-only argument ``method``.

    method : {'sequential', 'blelloch'}, optional
        Choose which method to use to perform the cumprod.  Default is 'sequential'.

        * 'sequential' performs the cumprod of each prior block before the current block.
        * 'blelloch' is a work-efficient parallel cumprod.  It exposes parallelism by first
          taking the product of each block and combines the products via a binary tree.
          This method may be faster or more memory efficient depending on workload,
          scheduler, and hardware.  More benchmarking is necessary.
    rF   rv   )rx   rL   cumprodr  rS   r|   s        r0   r  r    s4     


		gg
 
r2   c                    t        || j                        }t        t        j                  |      }t        t        j
                  |      }t        | ||||d| j                  |t        |      	      S )a  Extract the k largest elements from a on the given axis,
    and return them sorted from largest to smallest.
    If k is negative, extract the -k smallest elements instead,
    and return them sorted from smallest to largest.

    This performs best when ``k`` is much smaller than the chunk size. All
    results will be returned in a single chunk along the given axis.

    Parameters
    ----------
    x: Array
        Data being sorted
    k: int
    axis: int, optional
    split_every: int >=2, optional
        See :func:`reduce`. This parameter becomes very important when k is
        on the same order of magnitude of the chunk size or more, as it
        prevents getting the whole or a significant portion of the input array
        in memory all at once, with a negative impact on network transfer
        too when running on distributed.

    Returns
    -------
    Selection of x with size abs(k) along the given axis.

    Examples
    --------
    >>> import dask.array as da
    >>> x = np.array([5, 1, 3, 6])
    >>> d = da.from_array(x, chunks=2)
    >>> d.topk(2).compute()
    array([6, 5])
    >>> d.topk(-2).compute()
    array([1, 3])
    r   T)r   rX   	aggregaterH   rI   r5   rJ   output_size)	r    rb   r   r   topktopk_aggregater)   r5   r   )r:   r   rH   rJ   chunk_combiner  s         r0   r  r  /  sk    H qvv&D
 EJJ!,M ,,2I	ggF
 
r2   c                   t        | j                        t        | j                     | j                     ft
        j                        }|t        fdt        | j                        D                 }| j                  t        j                  |t              }t        t        j                  |      }t        t        j                  |      }t!        t"              rd}nt%              }| j&                  j)                  t
        j                        j+                  d| j                  |z
  dz   z        }	t-        ||||dt
        j                  |dt/        |      |		      S )
a  Extract the indices of the k largest elements from a on the given axis,
    and return them sorted from largest to smallest. If k is negative, extract
    the indices of the -k smallest elements instead, and return them sorted
    from smallest to largest.

    This performs best when ``k`` is much smaller than the chunk size. All
    results will be returned in a single chunk along the given axis.

    Parameters
    ----------
    x: Array
        Data being sorted
    k: int
    axis: int, optional
    split_every: int >=2, optional
        See :func:`topk`. The performance considerations for topk also apply
        here.

    Returns
    -------
    Selection of np.intp indices of x with size abs(k) along the given axis.

    Examples
    --------
    >>> import dask.array as da
    >>> x = np.array([5, 1, 3, 6])
    >>> d = da.from_array(x, chunks=2)
    >>> d.argtopk(2).compute()
    array([3, 0])
    >>> d.argtopk(-2).compute()
    array([1, 2])
    )r   r5   c              3  ^   K   | ]$  }|k(  rt        d       nt        j                   & y wr?   )r  rL   newaxis)r%  r   rH   s     r0   r&  zargtopk.<locals>.<genexpr>  s$     T19E$K"**<Ts   *-r4   r  rF   ro  TF)
r   rX   r  rH   rI   r5   rJ   r   r  r   )r    rb   r   r   r   rL   intpr  r   rt  r   argtopk_preprocessrN   r   argtopkargtopk_aggregater   r
   r  r   r   reshaper)   r   )
r:   r   rH   rJ   idx
a_plus_idxr  r  naxisr   s
     `       r0   r  r  j  s   B qvv&D '8
HC
eTeAFFmTT
UCe666JJ EMMQ/M //15I$D	77>>"''"**4166E>A3E+FGDggF r2   c                B    t        | |||      j                  d|      S )N)r3  axis1axis2r   r4   )r   rM   )r:   r3  r  r  r5   s        r0   tracer    s#    AfE?CCBeCTTr2   c                $    |t        d      t        |t              s|f}|D cg c]  }|dk  r| j                  z   n| }}t	        j
                   fd|D              r9 j                  t         j                        D ci c]  }|||v rdnd c}        j                  t        j                  |||s|nd|r.t         j                        D cg c]  \  }}||v rdn| c}}nd      }t        ||      }|S c c}w c c}w c c}}w )	z
    This works by automatically chunking the reduced axes to a single chunk if necessary
    and then calling ``numpy.median`` function across the remaining dimensions
    NzcThe da.median function only works along an axis.  The full algorithm is difficult to do in parallelr   c              3  B   K   | ]  }j                   |   d kD    ywr  rH  r%  rM  r:   s     r0   r&  zmedian.<locals>.<genexpr>       7BAKKOa'7   r   autorF   )rH   rI   	drop_axisr   )NotImplementedErrorr   r   rb   r8   rk   rr  r   rt  rL   medianrI  r   r   )r:   rH   rI   rK   rM  rE  rO   s   `      r0   r  r    s    |!@
 	

 dH%w489b26BKr)9D9 ||7$77II%-PBrt27PQ\\
		&$D  2;1881DEA"*Q!#E  
F V$FM' : Q Fs   DDDc                    |t        d      t        |t              s|f}|D cg c]  }|dk  r| j                  z   n| }}t	        j
                   fd|D              r9 j                  t         j                        D ci c]  }|||v rdnd c}       t        St        t        j                        j                  dk\  r- j                  j                  dv r|st        j                  }i }nt        j                  }d	|i}  j                   |f||s|nd|r.t#         j$                        D cg c]  \  }}||v rd
n| c}}ndd|}t'        ||      }|S c c}w c c}w c c}}w )z
    This works by automatically chunking the reduced axes to a single chunk
    and then calling ``numpy.nanmedian`` function across the remaining dimensions
    NzzThe da.nanmedian function only works along an axis or a subset of axes.  The full algorithm is difficult to do in parallelr   c              3  B   K   | ]  }j                   |   d kD    ywr  r  r  s     r0   r&  znanmedian.<locals>.<genexpr>  r  r  r   r  )r      r   uifrI   rF   )rH   r  r   )r  r   r   rb   r8   rk   rr  r   numbaggr   __version__releaser5   kind	nanmedianrL   rt  rI  r   r   )	r:   rH   rI   rK   rM  r0  rA   rE  rO   s	   `        r0   r  r    so    |!@
 	

 dH%w489b26BKr)9D9 ||7$77II%-PBrt27PQ 	G''(00I=GGLLE!  ||h'Q\\
&$D  2;1881DEA"*Q!#E
 
F V$FM? : Q& Fs   E"E'7E,)weightsinterpolationc                   |Xt        j                  d  j                  D              rt        d      t	        t        t         j                                    }t        |t              s|f}|D 	cg c]  }	|	dk  r|	 j                  z   n|	 }}	t        j                   fd|D              r9 j                  t         j                        D 	ci c]  }	|	|	|v rdnd c}	       t        rd|i}
ni }
  j                  t        j                  f||||||s|ndt        |t              rdndt!         |||      d	|
}t#        ||      }|S c c}	w c c}	w )
z
    This works by automatically chunking the reduced axes to a single chunk if necessary
    and then calling ``numpy.quantile`` function across the remaining dimensions
    Nc              3  &   K   | ]	  }|d kD    ywr  r   r%  n_blockss     r0   r&  zquantile.<locals>.<genexpr>       A1A   zeThe da.quantile function only works along an axis.  The full algorithm is difficult to do in parallelr   c              3  B   K   | ]  }j                   |   d kD    ywr  r  r  s     r0   r&  zquantile.<locals>.<genexpr>-  r  r  r   r  r  )qrt   r  rH   rI   r  new_axisr   )r8   rk   rH  r  r  r   r  r   r   r   rb   rr  r   rt  rL   quantile_get_quantile_chunksr   )r:   r  rH   rK   overwrite_inputrt   rI   r  r  rM  rA   rO   s   `           r0   r  r    sM   " |<<AQ[[AA%D 
 s177|,-DdH%w489b26BKr)9D9 ||7$77II%-PBrt27PQW%Q\\

#&$D H-4#Aq$9 F V$FM3 : Qs   3EEc           
        t        | j                        dk  rdn%t        t        t	        | j                        dd       }|| j                  d   z  }t        t        j                  t        j                  | j                  d         |            g}t        dt        | j                        dz
        D ]  }t        j                  t        j                  | j                  |         || j                  |   z        }|j                  t        t        j                  |||z                     || j                  |   z  } |S )Nr   rF   r   r   )r  r   r   r   r   r  rL   r   r   r   ru  tile)r:   shapesoriginal_shapesindexersr   indexers         r0   _span_indexersr  F  s     agg,!#QT!'']1R5H)IFqwwqz)Obii		!''!* 5v>?@H1c!''lQ&' ))BIIaggaj16QWWQZ3GHbggg&/HIJK1771: Or2   c                   ||hj                  dd h      rVt        |      dk7  sH|d   t        | j                        dz
  k7  s*t        | j                        dk(  s| j                  d   dkD  rt        j                  | |f||||d|S t        j
                  | d      }t        |       }t        |d         }	d}
t        |t              sd	}
|g}g }d
t        |j                  d d       z   |rd
ndz   }t        |      D ]4  }t        j                  |	      | j                  d   dz
  z  t        j                  |      j                  d      j                  d      z
  |z  }t        j                  |      j!                  t"              t        j$                  |      j!                  t"              }}|t        |      t        |      fz      }|t        |      t        |      fz      }||z
  }t        j&                  |dk(  d|      }||z
  }|j)                   ||z  ||z  z   j                  |        7 |
r|d   j+                  d      S t        j,                  |d      S )NlinearrF   r   r   i  )rH   rt   r  rI   r   FTrR   r   g        g      ?)issubsetr  r   rL   nanquantilesortr  r   r   r  r   r!   r   rM   r  floorr   intrv  rX  ru  squeezer   )r:   r  rH   rt   r  rI   rA   
sorted_arrr  nr_quantiles	is_scalar	quantilesreshape_shapessingle_qr   lower_valuehigher_valuelowerhigherfactor_higherfactor_lowers                        r0   _custom_quantiler  W  sZ    ]#,,h-=>t9>7c!''lQ&&qww<1772; ~~
 '
 
 	
, $Ja Hx{#LIa"	CIE*"2"23B"788HDRTUNG 
GGL!QWWR[1_5hhz"&&B&/77;< %'HHQK$6$6s$;RWWQZ=N=Ns=S\ 5?eK.@-BBCE(Ou\/B.DDE K#!5sMJ#a'CVm#el&::CC^T	
!
( |###++~~ia00r2   c                   |Xt        j                  d  j                  D              rt        d      t	        t        t         j                                    }t        |t              s|f}|D 	cg c]  }	|	dk  r|	 j                  z   n|	 }}	t        j                   fd|D              r9 j                  t         j                        D 	ci c]  }	|	|	|v rdnd c}	       t        \t        t        j                        j                  dk\  r6 j                   j"                  d	v r||d
k(  r|st        j$                  }
d|i}n&t&        }
||||d}t(        r|j+                  d|i         j,                  |
f||s|ndt        |t              rdndt/         |||      d|}t1        ||      }|S c c}	w c c}	w )z
    This works by automatically chunking the reduced axes to a single chunk
    and then calling ``numpy.nanquantile`` function across the remaining dimensions
    Nc              3  &   K   | ]	  }|d kD    ywr  r   r  s     r0   r&  znanquantile.<locals>.<genexpr>  r  r  zhThe da.nanquantile function only works along an axis.  The full algorithm is difficult to do in parallelr   c              3  B   K   | ]  }j                   |   d kD    ywr  r  r  s     r0   r&  znanquantile.<locals>.<genexpr>  r  r  r   r  )r      r   r  r  r  )r  rt   r  rI   r  )rH   r  r  r   )r8   rk   rH  r  r  r   r  r   r   r   rb   rr  r  r   r  r  r5   r  r  r  r   updatert  r  r   )r:   r  rH   rK   r  rt   rI   r  r  rM  r0  rA   rO   s   `            r0   r  r    s   " |<<AQ[[AA%D 
 s177|,-DdH%w489b26BKr)9D9 ||7$77II%-PBrt27PQ 	G''(00I=GGLLE!Oh""q!* 	
 MM9g./Q\\&$D H-4#Aq$9 F V$FMK : Qs   3F9F>c                   t        |t              rt        |      gng }|r1|t        | j                        D cg c]  \  }}||v rdn| c}}z   S |t        | j                        D cg c]  \  }}||vs| c}}z   S c c}}w c c}}w )NrF   )r   r   r  rI  r   )r:   r  rH   rI   quantile_chunkrM  rE  s          r0   r  r    s    !+Ax!8c!fXbN09!((0C!
',r1tA"!
 
 	
 	!((0C Vur1rQU~ VVV	!
 !Ws   B+B8Br?   )NNFNN)NFNN)NN)r   NF)NNFr   NN)F)NF)NNN)NNNrs   N)NNNrs   )r   N)r   r   rF   N)NFN)NNFr  F)Nr  NF)
__future__r   r8   r   rz   r   collections.abcr   	functoolsr   r   	itertoolsr   r   numbersr	   r
   r   numpyrL   packaging.versionr   tlzr   r   r   
dask.arrayr   dar   dask.array.corer   r   r   r   r   dask.array.creationr   r   dask.array.dispatchr   r   r   dask.array.numpy_compatr   dask.array.utilsr   r   r   r   r    dask.array.wrapr!   r"   	dask.baser#   dask.highlevelgraphr$   
dask.utilsr%   r&   r'   r  ImportError_array_expr_enableddask.array._array_exprr(   r)   dask.array._reductions_genericr=   rB   rD   rM   rS   rZ   aminrY   r9   amaxrf   rk   rn   rp   rr   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r"  r8  r;  r=  r?  rU  r[  r^  ra  rJ  r]  rW  rj  rl  r  rx   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r2   r0   <module>r     s^   "     $ % % $   % ' '    1 L L 0  (  . 3 3 2>>F %( b   b " BFFBGGb  7 BFFBGGb  7 b
 
 b
 
 b " b " b|  2 b  2 b &

 b &

 99Ee	$ 			

	$0- b * b * 		

 ,< 	


	),\ 	


	1/j TXIX b . bLP : b " bLP &BB C NRJ#ZQR b
 
 b
 
 b
 
 b
 
76+&u#z 


h#V b 2 b 28vEP bU U b! !H b- -` b 
5 5 5p( 
J1Z b 
A A AHW}5  Gs   .N: :OO