
    bi              
         d dl mZ d dlZd dlmZ  ed       d dlZd dlmZ d dl	m
Z
  eej                        Zej                  dk\  Zej                  dk\  Zej                  d	k\  Zerd d
lmZmZ d dlmZmZ nd d
lmZmZ d dlmZ d dlmZ 	  ej0                         5   ej2                   ej4                  ddd       ej4                  ddde            rJ ej2                   ej4                  ddd      d      r$ ej2                   ej4                  dd      d      s ed      ej4                  Zej:                  j4                  Zddd        G d d      Z" e
e      d        Z#ddZ$y# 1 sw Y   &xY w# e$ rQ ddZej:                  j>                  jA                  eej:                  j>                  jC                         d d      ZY ~w xY w)    )annotationsN)import_optional_dependencynumpy)Version)derived_from)      )   r   )r
   r   )	AxisErrorComplexWarning)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                Z    t        j                  | ||      }||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        R/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/dask/array/numpy_compat.pyr   r   4   s.    
 IIb"c"A    c                  2    e Zd ZdZd Zd d d fdZd	dZy)
	_Recurserz;
    Utility class for recursing over nested iterables
    c                    || _         y N
recurse_if)selfr"   s     r   __init__z_Recurser.__init__L   s	    $r   c                    | S r     r   kwargss     r   <lambda>z_Recurser.<lambda>R   s    ! r   c                    | S r    r&   r'   s     r   r)   z_Recurser.<lambda>S   s    Q r   c                     | S r    r&   )r(   s    r   r)   z_Recurser.<lambda>T   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                p    j                  |       s	 | fi |S  di | fd| D        fi |S )Nc              3  0   K   | ]  } |fi   y wr    r&   ).0xifnext_kwargss     r   	<genexpr>z2_Recurser.map_reduce.<locals>.f.<locals>.<genexpr>}   s      B"2!5!5 Bs   r&   r!   )r   r(   r2   r1   f_kwargsf_mapf_reducer#   s     @r   r1   z_Recurser.map_reduce.<locals>.fx   sB    ??1%Q)&))&00 B BMfMMr   r&   )r#   r   r5   r6   r4   r(   r1   s   ` ``` @r   
map_reducez_Recurser.map_reduceO   s     R	N 	N ~f~r   c              #     K   | j                  |      }|||f |syt        |      D ]#  \  }}| j                  |||fz         E d{    % y7 w)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ir0   s         r   r:   z_Recurser.walk   s]      __Q'
Q
""q\ 	3EAryyUaT\222	32s   AAA	AN)r&   )__name__
__module____qualname____doc__r$   r7   r:   r&   r   r   r   r   C   s"    % $&(0d3r   r   c                ~   t        || j                  d      }t        || j                  d      }t        |      t        |      k7  rt        d      t	        | j                        D cg c]	  }||vs| }}t        t        ||            D ]  \  }}|j                  ||        | j                  |      }|S c c}w )NsourcedestinationzJ`source` and `destination` arguments must have the same number of elements)	r   ndimlen
ValueErrorrangesortedzipinsert	transpose)arC   rD   norderdestsrcresults           r   moveaxisrS      s    !&!&&(;F&{AFFMJK
6{c+&&*
 	

 aff91&Q9E9CV45  	cT3  [[FM :s   (	B:2B:c                R   | 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|            }|j                  |       |j                  ||       | j                  |      S )Nr   z5'%s' arg requires %d <= %s < %d, but %d was passed inr   start.)rE   r   rG   listrH   removerK   rL   )rM   axisrU   rN   msgaxess         r   rollaxisr[      s    	Aa(Dqy

ACQ!Wa!eUCCDDe|
u}vaDKKKKt;;tr   )NN)r   )%
__future__r   warningsdask._compatibilityr   r   r   packaging.versionr   
dask.utilsr   __version___np_versionreleaseNUMPY_GE_125NUMPY_GE_200NUMPY_GE_210numpy.exceptionsr   r   numpy.lib.array_utilsr   r   numpy.core.numericcatch_warningsallcloser   float	TypeErrorma	ma_dividecore_DomainedBinaryOperation_DomainSafeDivider   rS   r[   r&   r   r   <module>rs      s   "  : 7 #  % #bnn%""g-""f,""f, :PP 87
	 	 	 	" !		#q(3		#q(%@ 2;;yryyCt<a@2;;yryya0#6=  EELL	!BN3 N3f b (S! !    

33

,,.1Is,   F !B/E5F 5E>:F AGG