U
    /e&                     @   s  d dl 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mZmZ d dlmZmZ d dlmZ d dlmZmZ efd	d
ZG dd dZeedd ZG dd dZeejZeejZeejZeejZeejZeejZeej Z eej!Z!eej"Z"eej#Z#eej$Z$eej%Z%eej&Z&eej'Z'eej( Z)Z(eej*Z*eej+Z+eej,Z,eej-Z-eej.Z.eej/Z/eej0Z0eej1Z1eej2Z2eej3Z3eej4Z4eej5Z5eej6Z6eej7Z7eej8Z8eej9Z9eej:Z:eej;Z;eej<Z<eej=Z=eej>Z>eej?Z?eej@Z@eejAZAeejBZBeejCZCeejDZDeejEZEeejFZFeejGZGeejHZHeejIZIeejJZJeeJejK ZLeeJejKZMeejNZNeejOZOeejPZPeejQZQeejRZReejSZSeejTZTeejUZUeejVZVeejWZWeejXZXeejYZYeYZZeej[Z[eej\Z\eej]Z]eej^Z^eej_Z_eej`Z`eejaZaeejbZbeejcZceejdZdeejeZeeejfZfeejgZgeejhZheejiZieejjZjeejkZkeejlZleejmZmeejnZnenZoeejpZpeejqZqeejrZreejsZseejtZteejuZueejvZveejwZweejxZxeedddZyeedd Zzeedd Z{eedd Z|dS )    )partialgetitemN)core)Arrayapply_infer_dtypeasarray	blockwiseelemwise)is_dask_collectionnormalize_function)HighLevelGraph)derived_fromfuncnamec                    s     fdd} j |_ t||S )z&Wrap up numpy function into dask.arrayc                     s>   dd | D }t |dkr0|d j f| |S  | |S d S )Nc                 S   s   g | ]}t |d r|qS 	_elemwisehasattr.0arg r   4/tmp/pip-unpacked-wheel-dbjnr7gq/dask/array/ufunc.py
<listcomp>   s     
 z2wrap_elemwise.<locals>.wrapped.<locals>.<listcomp>r   )lenr   )argskwargsdsknumpy_ufuncr   r   wrapped   s    zwrap_elemwise.<locals>.wrapped)__name__r   )r   sourcer    r   r   r   wrap_elemwise   s    r#   c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )da_frompyfuncz"A serializable `frompyfunc` objectc                 C   s<   t |||| _|| _|| _|| _t|| _d| j | _d S )Nzfrompyfunc-%s)	np
frompyfunc_ufunc_funcninnoutr   _namer!   )selffuncr)   r*   r   r   r   __init__   s    
zda_frompyfunc.__init__c                 C   s   d| j | j| jf S )Nzda.frompyfunc<%s, %d, %d>)r+   r)   r*   r,   r   r   r   __repr__'   s    zda_frompyfunc.__repr__c                 C   s   t | j| j| jfS N)r   r(   r)   r*   r/   r   r   r   __dask_tokenize__*   s    zda_frompyfunc.__dask_tokenize__c                 C   s   t | j| j| jffS r1   )r$   r(   r)   r*   r/   r   r   r   
__reduce__-   s    zda_frompyfunc.__reduce__c                 O   s   | j ||S r1   )r'   )r,   r   r   r   r   r   __call__0   s    zda_frompyfunc.__call__c                 C   s2   | dst| j|S tt| jd|d S )N_ object has no attribute )
startswithgetattrr'   AttributeErrortyper!   )r,   ar   r   r   __getattr__3   s    
zda_frompyfunc.__getattr__c                 C   s4   t tt| }|| j |t| j t|S r1   )setdirr:   update__dict__r'   list)r,   or   r   r   __dir__8   s    zda_frompyfunc.__dir__N)r!   
__module____qualname____doc__r.   r0   r2   r3   r4   r<   rC   r   r   r   r   r$      s   r$   c                 C   s    |dkrt dtt| ||S )N   z$frompyfunc with more than one output)NotImplementedErrorufuncr$   )r-   r)   r*   r   r   r   r&   ?   s    r&   c                   @   sX   e Zd ZdddddddhZdd	 Zd
d Zdd Zdd Zdd Ze	e
jdd ZdS )rI   r)   nargsr*   Zntypesidentity	signaturetypesc                 C   sL   t |tjtfs"tdt|j || _|j| _t |tjrHtt|  d S )Nz:must be an instance of `ufunc` or `da_frompyfunc`, got `%s)	
isinstancer%   rI   r$   	TypeErrorr:   r!   r'   r   )r,   rI   r   r   r   r.   Q   s    zufunc.__init__c                 C   s2   || j krt| j|S tt| jd|d S )Nr6   )_forward_attrsr8   r'   r9   r:   r!   )r,   keyr   r   r   r<   \   s    
zufunc.__getattr__c                 C   s   t | jtt| | jS r1   )rA   rP   unionr>   r:   r@   r/   r   r   r   rC   a   s    zufunc.__dir__c                 C   s
   t | jS r1   )reprr'   r/   r   r   r   r0   d   s    zufunc.__repr__c                 O   sp   dd |D }t |dkr`|D ]0}|j| jf||}t|ttkr|  S qtd| j n| j||S d S )Nc                 S   s   g | ]}t |d r|qS r   r   r   r   r   r   r   h   s     
 z"ufunc.__call__.<locals>.<listcomp>r   z.Parameters of such types are not supported by )r   r   r'   r:   NotImplementedrO   r!   )r,   r   r   Zdsksr   resultr   r   r   r4   g   s    
zufunc.__call__c                 K   s  | j dkrtdd|kr"tdt|}t|}|sL|sL| jj||f|S |rZt|trh|rpt|tsptdt|}t|}|j	|j	 }t
t|}|d |j	 }||j	d  }	t| jj||g|ddd}
d	|krt| jj|d	d
}n| jj}t||||||	f|
| jd d|S )N   z1outer product only supported for binary functionsoutz`out` kwarg not supportedzGDask objects besides `dask.array.Array` are not supported at this time.ufunc.outerF)Zsuggest_dtypedtyperY   z.outer)rY   token)r)   
ValueErrorr   r'   outerrN   r   rH   r   ndimtupleranger   r   popr	   r!   )r,   ABr   Z	A_is_daskZ	B_is_daskr^   Zout_indsZA_indsZB_indsrY   r-   r   r   r   r]   t   s`    
    	rX   N)r!   rD   rE   rP   r.   r<   rC   r0   r4   r   r%   rI   r]   r   r   r   r   rI   F   s   
rI   c                 C   s0   t |}t| dr"| tj| |S tj| |dS )Nr   )deg)boolr   r   r%   angle)xrd   r   r   r   rf     s    
rf   c           
         s   t tj| td}d|j  d|j  fddt| D }fddt| D }tjt	| d| d| j
 | jd	}t|\}}tj ||gd
}t| |j|d}tj||gd
}t||j|d}	||	fS )NrZ   z	mantissa-z	exponent-c                    s&   i | ]} f|d d  t |dfqS rG   Nr   r   r   rQ   leftr   r   
<dictcomp>(  s    zfrexp.<locals>.<dictcomp>c                    s&   i | ]} f|d d  t |d fqS rG   Nr   ri   rightr   r   rl   ,  s    _metarG   shaperY   Zdependencieschunksmeta)r
   r%   frexpobjectnamer   flatten__dask_keys__
empty_liker8   r^   rY   r   from_collectionsr   rv   
rg   tmpZldskZrdskr;   lrgraphLRr   rk   ro   r   rx   "  s     



 rx   c           
         s   t tj| td}d|j  d|j  fddt| D }fddt| D }tjt	| d| d| j
 | jd	}t|\}}tj ||gd
}t| |j|d}tj||gd
}t||j|d}	||	fS )NrZ   zmodf1-zmodf2-c                    s&   i | ]} f|d d  t |dfqS rh   r   ri   rj   r   r   rl   A  s    zmodf.<locals>.<dictcomp>c                    s&   i | ]} f|d d  t |d fqS rm   r   ri   rn   r   r   rl   E  s    rp   rq   rr   rt   ru   )r
   r%   modfry   rz   r   r{   r|   r}   r8   r^   rY   r   r~   r   rv   r   r   r   r   r   ;  s     



 r   c                 C   s   | | }| | }||fS r1   r   )rg   yZres1Zres2r   r   r   divmodT  s    r   )r   )}	functoolsr   operatorr   Znumpyr%   Zdaskr   Zdask.array.corer   r   r   r	   r
   Z	dask.baser   r   Zdask.highlevelgraphr   Z
dask.utilsr   r   r#   r$   r&   rI   addsubtractmultiplydivideZ	logaddexpZ
logaddexp2Ztrue_divideZfloor_dividenegativeZpositivepowerZfloat_power	remaindermod	conjugateZconjexpZexp2loglog2log10log1pexpm1sqrtZsquareZcbrtZ
reciprocalsincostanZarcsinZarccosZarctanZarctan2hypotsinhcoshtanhZarcsinhZarccoshZarctanhZdeg2radZrad2degZgreaterZgreater_equalZlessZ
less_equal	not_equalequalinfZisneginfZisposinflogical_and
logical_orlogical_xorZlogical_notmaximumZminimumZfmaxZfminZbitwise_andZ
bitwise_orZbitwise_xorZbitwise_notinvertZ
left_shiftZright_shiftisfiniteisinfisnanZsignbitcopysignZ	nextafterspacingldexpfmodfloorceiltruncdegreesradiansZrintfabssignabsoluteabsZclipZisrealZ	iscomplexrealimagZfixZi0ZsincZ
nan_to_numrf   rx   r   r   r   r   r   r   <module>   s   #
e

























































































