o
    Nrf                  
   @  s  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rKd 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 zJe < eejddddejdddedreejdddddreedddsedejZejjZW d   n1 sw   Y  W n ey   d#ddZejj eejj! d dZY nw G dd dZ"eedd Z#d$ddZ$d%d!d"Z%dS )&    )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                 C  s$   t | ||}|dur||}|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.N)npdivideZastype)x1Zx2outr   x r   `/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/dask/array/numpy_compat.pyr   0   s   
r   c                   @  s>   e Zd ZdZdd Zdd dd dd fdd	ZdddZdS )	_Recurserz;
    Utility class for recursing over nested iterables
    c                 C  s
   || _ d S N
recurse_if)selfr   r   r   r   __init__H   s   
z_Recurser.__init__c                 K     | S r   r   r   kwargsr   r   r   <lambda>N       z_Recurser.<lambda>c                 K  r    r   r   r!   r   r   r   r#   O   r$   c                  K  r    r   r   )r"   r   r   r   r#   P   r$   c                   s$    fd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                   sH    | s| fi |S di |  fdd| D fi |S )Nc                 3  s     | ]} |fi V  qd S r   r   ).0xi)fnext_kwargsr   r   	<genexpr>y   s    z2_Recurser.map_reduce.<locals>.f.<locals>.<genexpr>r   r   r!   r'   f_kwargsf_mapf_reducer   )r(   r   r'   t   s   
 z_Recurser.map_reduce.<locals>.fr   )r   r   r,   r-   r+   r"   r   r*   r   
map_reduceK   s   )z_Recurser.map_reducer   c                 c  sN    |  |}|||fV  |sdS t|D ]\}}| |||f E dH  q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   indexZ
do_recurseir&   r   r   r   r0   }   s   
	z_Recurser.walkN)r   )__name__
__module____qualname____doc__r   r.   r0   r   r   r   r   r   ?   s    
2r   c                   s~   t  | jd t || jd}t t|krtd fddt| jD }tt| D ]
\}}||| q-| |}|S )NsourcedestinationzJ`source` and `destination` arguments must have the same number of elementsc                   s   g | ]}| vr|qS r   r   )r%   nr7   r   r   
<listcomp>   s    zmoveaxis.<locals>.<listcomp>)	r   ndimlen
ValueErrorrangesortedzipinsert	transpose)ar7   r8   orderdestsrcresultr   r:   r   moveaxis   s   
rI   c                 C  s   | j }t||}|dk r||7 }d}d|  kr|d k s-n t|d| d|d |f ||k r5|d8 }||kr=| d S ttd|}|| ||| | |S )Nr   z5'%s' arg requires %d <= %s < %d, but %d was passed inr   start.)r<   r   r>   listr?   removerB   rC   )rD   ZaxisrJ   r9   msgZaxesr   r   r   rollaxis   s   


rN   linearc                 C  s$   t r
tj| ||dS tj| ||dS )N)method)interpolation)NUMPY_GE_122r   
percentile)rD   qrP   r   r   r   rS      s   rS   )NN)r   )rO   )&
__future__r   warningsnumpyr   Zpackaging.versionr   Z
dask.utilsr   __version__Z_np_versionreleaserR   ZNUMPY_GE_123ZNUMPY_GE_124ZNUMPY_GE_125ZNUMPY_GE_200Znumpy.exceptionsr   r   Znumpy.lib.array_utilsr   r   Znumpy.core.numericcatch_warningsZallcloser   float	TypeErrormaZ	ma_dividecoreZ_DomainedBinaryOperationZ_DomainSafeDivider   rI   rN   rS   r   r   r   r   <module>   s\    









S

