
    tf              
         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
j                  dk\  Ze
j                  dk\  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$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)Version)derived_from)      )r      )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        a/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/dask/array/numpy_compat.pyr   r   0   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__H   s	    $r   c                    | S r!    r   kwargss     r   <lambda>z_Recurser.<lambda>N   s    ! r   c                    | S r!   r'   r(   s     r   r*   z_Recurser.<lambda>O   s    Q r   c                     | S r!   r'   )r)   s    r   r*   z_Recurser.<lambda>P   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>y   s      B"2!5!5 Bs   r'   r"   )r   r)   r3   r2   f_kwargsf_mapf_reducer$   s     @r   r2   z_Recurser.map_reduce.<locals>.ft   sB    ??1%Q)&))&00 B BMfMMr   r'   )r$   r   r6   r7   r5   r)   r2   s   ` ``` @r   
map_reducez_Recurser.map_reduceK   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ir1   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%   r8   r;   r'   r   r   r   r   ?   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)arD   rE   norderdestsrcresults           r   moveaxisrT      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.)rF   r   rH   listrI   removerL   rM   )rN   axisrV   rO   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   c                n    t         rt        j                  | ||      S t        j                  | ||      S )N)method)interpolation)NUMPY_GE_122r   
percentile)rN   qr^   s      r   ra   ra      s+    }}Q&11}}Q88r   )NN)r   )linear)&
__future__r   warningsnumpyr   packaging.versionr   
dask.utilsr   __version___np_versionreleaser`   NUMPY_GE_123NUMPY_GE_124NUMPY_GE_125NUMPY_GE_200numpy.exceptionsr   r   numpy.lib.array_utilsr   r   numpy.core.numericcatch_warningsallcloser   float	TypeErrorma	ma_dividecore_DomainedBinaryOperation_DomainSafeDivider   rT   r\   ra   r'   r   r   <module>r|      s   "   % #bnn%""g-""g-""g-""g-""f, :PP/77
	 	 	 	" !		#q(3		#q(%@ 2;;yryyCt<a@2;;yryya0#6=  EELL	!BN3 N3f b ((9{! !    

33

,,.1Is,    F 1B/F	 F 	FF AG+*G+