
    >ie              
         d dl mZ d dlZd dlZd dlmZ d dlm	Z	  eej
                  Ze ed          k    Ze ed          k    Ze ed          k    Zej        dk    Zej        d	k    Zer	d d
lmZmZ nd dlmZ d dlmZ 	  ej                    5   ej         ej        ddd           ej        ddde                    rB ej         ej        ddd          d          r  ej         ej        dd          d          s ed          ej        Zej        j        Zddd           n# 1 swxY w Y   nM# e$ rE ddZej        j                            eej        j                                        d d          ZY nw xY w G d d          Z  e	e          d             Z!ddZ"d dZ#erej$        j%        nej%        Z%erej$        j&        nej&        Z&dS )!    )annotationsN)parse)derived_fromz1.22.0z1.23.0z1.24.0)      r   )   r   r   )normalize_axis_indexnormalize_axis_tuple)r	   )r
   g?r   unsafe)casting)r   dtypeg      ?i8)r   r   zIDivide not working with dtype: https://github.com/numpy/numpy/issues/3484c                `    t          j        | ||          }||                    |          }|S )zImplementation of numpy.divide that works with dtype kwarg.

        Temporary compatibility fix for a bug in numpy's version. See
        https://github.com/numpy/numpy/issues/3484 for the relevant issue.)npdivideastype)x1x2outr   xs        7lib/python3.11/site-packages/dask/array/numpy_compat.pyr   r   .   s1    
 Ib"c""A    c                  4    e Zd ZdZd Zd d d fdZd
dZd	S )	_Recurserz;
    Utility class for recursing over nested iterables
    c                    || _         d S N
recurse_if)selfr   s     r   __init__z_Recurser.__init__F   s    $r   c                    | S r    r   kwargss     r   <lambda>z_Recurser.<lambda>L   s    ! r   c                    | S r   r"   r#   s     r   r%   z_Recurser.<lambda>M   s    Q r   c                     | S r   r"   )r$   s    r   r%   z_Recurser.<lambda>N   s    & r   c                0      fd |fi |S )a{  
        Iterate over the nested list, applying:
        * ``f_map`` (T -> U) to items
        * ``f_reduce`` (Iterable[U] -> U) to mapped items

        For instance, ``map_reduce([[1, 2], 3, 4])`` is::

            f_reduce([
              f_reduce([
                f_map(1),
                f_map(2)
              ]),
              f_map(3),
              f_map(4)
            ]])


        State can be passed down through the calls with `f_kwargs`,
        to iterables of mapped items. When kwargs are passed, as in
        ``map_reduce([[1, 2], 3, 4], **kw)``, this becomes::

            kw1 = f_kwargs(**kw)
            kw2 = f_kwargs(**kw1)
            f_reduce([
              f_reduce([
                f_map(1), **kw2)
                f_map(2,  **kw2)
              ],      **kw1),
              f_map(3, **kw1),
              f_map(4, **kw1)
            ]],     **kw)
        c                ~                         |           s	 | fi |S  di | fd| D             fi |S )Nc              3  *   K   | ]} |fi V  d S r   r"   ).0xifnext_kwargss     r   	<genexpr>z2_Recurser.map_reduce.<locals>.f.<locals>.<genexpr>w   s5       B B"2!5!5!5!5 B B B B B Br   r"   r   )r   r$   r.   r-   f_kwargsf_mapf_reducer   s     @r   r-   z_Recurser.map_reduce.<locals>.fr   sv    ??1%% NuQ))&)))&h0000x B B B B B B B BMMfMMMr   r"   )r   r   r1   r2   r0   r$   r-   s   ` ``` @r   
map_reducez_Recurser.map_reduceI   sT    R	N 	N 	N 	N 	N 	N 	N 	N 	N q~~f~~r   r"   c              #     K   |                      |          }|||fV  |sdS t          |          D ]%\  }}|                     |||fz             E d{V  &dS )aB  
        Iterate over x, yielding (index, value, entering), where

        * ``index``: a tuple of indices up to this point
        * ``value``: equal to ``x[index[0]][...][index[-1]]``. On the first iteration, is
                     ``x`` itself
        * ``entering``: bool. The result of ``recurse_if(value)``
        N)r   	enumeratewalk)r   r   index
do_recurseir,   s         r   r6   z_Recurser.walk{   s       __Q''
Q
"""" 	Fq\\ 	3 	3EAryyUaT\2222222222	3 	3r   N)r"   )__name__
__module____qualname____doc__r    r3   r6   r"   r   r   r   r   =   sj         % % % $#&&((0 0 0 0d3 3 3 3 3 3r   r   c                   t          | j        d          t          || j        d          }t                    t          |          k    rt          d          fdt	          | j                  D             }t          t          |                    D ]\  }}|                    ||           |                     |          }|S )NsourcedestinationzJ`source` and `destination` arguments must have the same number of elementsc                    g | ]}|v|	S r"   r"   )r+   nr?   s     r   
<listcomp>zmoveaxis.<locals>.<listcomp>   s    9991&Qr   )	r
   ndimlen
ValueErrorrangesortedzipinsert	transpose)ar?   r@   orderdestsrcresults    `     r   moveaxisrQ      s    !&!&(;;F&{AFMJJK
6{{c+&&&&*
 
 	

 :999af999ECV4455    	cT3[[FMr   c                   | j         }t          ||          }|dk     r||z  }d}d|cxk    r	|dz   k     sn t          |d| d|dz   |fz            ||k     r|dz  }||k    r| d         S t          t	          d|                    }|                    |           |                    ||           |                     |          S )Nr   z5'%s' arg requires %d <= %s < %d, but %d was passed inr   start.)rD   r	   rF   listrG   removerJ   rK   )rL   axisrS   rB   msgaxess         r   rollaxisrY      s    	Aa((Dqyy

ACQ!Wa!eUCCDDDe||
u}}vaDKKKKt;;tr   linearc                l    t           rt          j        | ||          S t          j        | ||          S )N)method)interpolation)
_numpy_122r   
percentile)rL   qr\   s      r   r_   r_      s8     9}Q&1111}Q8888r   )NN)r   )rZ   )'
__future__r   warningsnumpyr   packaging.versionr   parse_version
dask.utilsr   __version___np_versionr^   
_numpy_123
_numpy_124release
_numpy_125
_numpy_200numpy.lib.array_utilsr	   r
   numpy.core.numericcatch_warningsallcloser   float	TypeErrorma	ma_dividecore_DomainedBinaryOperation_DomainSafeDivider   rQ   rY   r_   
exceptionsComplexWarning	AxisErrorr"   r   r   <module>r|      sI   " " " " " "      4 4 4 4 4 4 # # # # # #mBN++MM(333
MM(333
MM(333
 J.
 I-
  8PPPPPPPPP777777777777
	 	 	"	" ! !	#q(333	#q(%@@@ 	
 2;yryCt<<<a@@	 2;yrya00#66	 )=   EL	! ! ! ! ! ! ! ! ! ! ! ! ! ! !         
33
,,..1 III"N3 N3 N3 N3 N3 N3 N3 N3f b  (   (9 9 9 9 2<R--AR'1CBM##r|			s8   E BD6*E 6D::E =D:>E AFF