o
    Zh                      @  sz  d dl mZ d dlmZ d dlZddlmZmZmZm	Z	 ddl
mZmZmZmZmZmZmZ dd Zd	d
 eeD ZdZdd Ze	d7dddddddddd8d"d#Ze	d7d$ddddddd%d9d(d)Ze			*d:d$ddddddd%d;d.d/ZeD ]ZeeeZeee e< q|d0d1 Zeg d2 Zd3d
 eeD Zg d4Z d5d6 Z!eD ]ZeeeZe!ee e< qee Z"dS )<    )annotations)OptionalN   )_binary_ufuncs_impl_dtypes_impl_unary_ufuncs_impl_util)	ArrayLikeArrayLikeOrScalarCastingModes	DTypeLike
normalizerNotImplementedTypeOutArrayc                 C  s,   |d urt | |jj|} t| |j} | S N)r   typecast_tensordtypeZtorch_dtypetorchZbroadcast_toshape)resultoutcasting r   C/var/www/auris/lib/python3.10/site-packages/torch/_numpy/_ufuncs.py_ufunc_postprocess   s   r   c                 C  s"   g | ]}| d s|dvr|qS )_)r   matmuldivmodldexp
startswith.0namer   r   r   
<listcomp>       r$   )addsubtractmultiplyZfloor_divideZtrue_dividedivide	remainderZbitwise_andZ
bitwise_orZbitwise_xorZbitwise_left_shiftZbitwise_right_shifthypotZarctan2Z	logaddexpZ
logaddexp2Z	heavisidecopysignZfmaxminimumZfminmaximumfmodgcdlcmpowc              
     s<   t 	dddddddddd fdd} j|_ j|_|S )zCommon infra for binary ufuncs.

    Normalize arguments, sort out type casting, broadcasting and delegate to
    the pytorch functions for the actual work.
    NT	same_kindKFwherer   orderr   subok	signatureextobjr   Optional[OutArray]x1r
   x2r6   r   r   Optional[CastingModes]r7   r   Optional[DTypeLike]r8   r9   r:   c                 s   |d ur fdd}
|
| |} |
||}n,t | tjr3t |tjr3t| |}t| |f| \} }nt| |jt	v j\} }| |}t
|| S )Nc                   s(   t | tjrt| | S tj| |dS )Nr   )
isinstancer   Tensorr   r   	as_tensor)xr   r   r   r   cast[   s   z0deco_binary_ufunc.<locals>.wrapped.<locals>.cast)rA   r   rB   r   result_type_implr   typecast_tensorsZnep50_to_tensors__name__NEP50_FUNCSr   )r<   r=   r   r6   r   r7   r   r8   r9   r:   rF   r   
torch_funcrE   r   wrappedJ   s   

z"deco_binary_ufunc.<locals>.wrappedr   r   r;   r<   r
   r=   r
   r6   r   r   r>   r7   r   r   r?   r8   r   r9   r   r:   r   r   rI   __qualname__rL   rM   r   rK   r   deco_binary_ufuncC   s   $rR   r3   r4   F)r   r7   r   r8   r9   r:   axesaxisr   r;   r<   r	   r=   r   r>   r7   r   r   r?   r8   r9   r:   rS   rT   c               C  sF   |d u r
t | |}t| |f||\} }t| |}t|||}|S r   )r   rG   r   rH   r   r   r   )r<   r=   r   r   r7   r   r8   r9   r:   rS   rT   r   r   r   r   r   y   s   r   Tr5   r
   r6   c               C  s   |d urt | tjrt| ||} ntj| |d} nt | tjs*t| } t| } t|}t|j	dkr;t
dt| |}
| j	tjkrM|
tj}
t|
||S )Nr@   r   zldexp 2nd arg must be integer)rA   r   rB   r   r   rC   cast_int_to_floatr   Z	_categoryr   
ValueErrorr   r   Zfloat16tor   )r<   r=   r   r6   r   r7   r   r8   r9   r:   r   r   r   r   r      s   


r   NN-tuple[Optional[OutArray], Optional[OutArray]]out1out2c               C  s   t dd ||fD }|dkrtd|dkr(|\}}|d us#|d ur'tdn|\}}|d u r6t| |}t| |f||\} }t| |\}}t	|||}t	|||}||fS )Nc                 s  s    | ]}|d uV  qd S r   r   )r"   rD   r   r   r   	<genexpr>   s    zdivmod.<locals>.<genexpr>r   z&both out1 and out2 need to be provided   z>cannot specify 'out' as both a positional and keyword argument)
sumrV   	TypeErrorr   rG   r   rH   r   r   r   )r<   r=   rZ   r[   r   r6   r   r7   r   r8   r9   r:   Znum_outsZo1o2quotremr   r   r   r      s$   r   c                O  s$   t | dg|R i |\}}||fS )Nr   )r   )rD   argskwdsra   rb   r   r   r   modf   s   re   )r   re   r   r   c                 C  s"   g | ]}| d s|dkr|qS )r   r   r   r!   r   r   r   r$      r%   )ZarccosZarccoshZarcsinZarcsinhZarctanZarctanhZcbrtcoscoshZdeg2raddegreesexpZexp2expm1loglog10log1plog2Zrad2degradiansZ
reciprocalsinsinhsqrtZsquaretantanhtruncc              
     s<   t 	dddddddddd fdd} j|_ j|_|S )zCommon infra for unary ufuncs.

    Normalize arguments, sort out type casting, broadcasting and delegate to
    the pytorch functions for the actual work.
    NTr3   r4   Fr5   r   r;   rD   r	   r   r>   r   r?   r8   r   c         
        sB   |d urt | ||}  jtv rt | }  | }	t|	||}	|	S r   )r   r   rI   	_fp_unaryrU   r   )
rD   r   r6   r   r7   r   r8   r9   r:   r   rK   r   r   rM   (  s   

z!deco_unary_ufunc.<locals>.wrappedr   )
r   r;   rD   r	   r   r>   r   r?   r8   r   rO   rQ   r   rK   r   deco_unary_ufunc!  s   rw   r   )r   r;   r<   r	   r=   r	   r   r>   r7   r   r   r?   r8   r   r9   r   r:   r   rS   r   rT   r   rN   )NNrX   )r   rY   r<   r	   r=   r	   rZ   r;   r[   r;   r6   r   r   r>   r7   r   r   r?   r8   r   r9   r   r:   r   )#
__future__r   typingr   r    r   r   r   r   Z_normalizationsr	   r
   r   r   r   r   r   r   dir_binaryrJ   rR   r   r   r   r#   getattrZufuncvarsre   Z_unaryrv   rw   __all__r   r   r   r   <module>   sz   $	6',
 (
