o
    h                      @  s~  d dl mZ d dlmZ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)OptionalUnionN   )_binary_ufuncs_impl_dtypes_impl_unary_ufuncs_impl_util)	ArrayLikeCastingModes	DTypeLike
normalizerNotImplementedTypeOutArrayScalarc                 C  s,   |d urt | |jj|} t| |j} | S N)r	   typecast_tensordtypetorch_dtypetorchbroadcast_toshape)resultoutcasting r   J/var/www/html/ai/venv/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multiplyfloor_dividetrue_dividedivide	remainderbitwise_and
bitwise_orbitwise_xorbitwise_left_shiftbitwise_right_shifthypotarctan2	logaddexp
logaddexp2	heavisidecopysignfmaxminimum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]x1Union[ArrayLike, Scalar]x2rF   r   r   Optional[CastingModes]rG   r   Optional[DTypeLike]rH   rI   rJ   c                 s   |d ur fdd}
|
| |} |
||}n*t | tjr3t |tjr3t| |}t| |f| \} }nt| |jt	v \} }| |}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   castY   s   z0deco_binary_ufunc.<locals>.wrapped.<locals>.cast)rR   r   rS   r   result_type_implr	   typecast_tensorsnep50_to_tensors__name__NEP50_FUNCSr   )rL   rN   r   rF   r   rG   r   rH   rI   rJ   rW   r   
torch_funcrV   r   wrappedH   s   

z"deco_binary_ufunc.<locals>.wrappedr   r   rK   rL   rM   rN   rM   rF   r   r   rO   rG   r   r   rP   rH   r   rI   r   rJ   r   r   r[   __qualname__r^   r_   r   r]   r   deco_binary_ufuncA   s   $rd   rC   rD   F)r   rG   r   rH   rI   rJ   axesaxisr   rK   rL   r
   rN   r   rO   rG   r   r   rP   rH   rI   rJ   re   rf   c               C  sF   |d u r
t | |}t| |f||\} }t| |}t|||}|S r   )r   rX   r	   rY   r   r   r   )rL   rN   r   r   rG   r   rH   rI   rJ   re   rf   r   r   r   r   r   w   s   r   TrE   rM   rF   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 )NrQ   r   zldexp 2nd arg must be integer)rR   r   rS   r	   r   rT   cast_int_to_floatr   	_categoryr   
ValueErrorr   r!   float16tor   )rL   rN   r   rF   r   rG   r   rH   rI   rJ   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%   rU   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)
sumri   	TypeErrorr   rX   r	   rY   r   r    r   )rL   rN   rn   ro   r   rF   r   rG   r   rH   rI   rJ   num_outso1o2quotremr   r   r   r       s$   r    c                O  s$   t | dg|R i |\}}||fS )Nr   )r    )rU   argskwdsrw   rx   r   r   r   modf   s   r{   )r    r{   r   r!   c                 C  s"   g | ]}| d s|dkr|qS )r   r   r"   r$   r   r   r   r'      r(   )arccosarccosharcsinarcsinharctanarctanhcbrtcoscoshdeg2raddegreesexpexp2expm1loglog10log1plog2rad2degradians
reciprocalsinsinhsqrt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.
    NTrC   rD   FrE   r   rK   rU   r
   r   rO   r   rP   rH   r   c         
        sB   |d urt | ||}  jtv rt | }  | }	t|	||}	|	S r   )r	   r   r[   	_fp_unaryrg   r   )
rU   r   rF   r   rG   r   rH   rI   rJ   r   r]   r   r   r_   &  s   

z!deco_unary_ufunc.<locals>.wrappedr   )
r   rK   rU   r
   r   rO   r   rP   rH   r   ra   rc   r   r]   r   deco_unary_ufunc  s   r   r   )r   rK   rL   r
   rN   r
   r   rO   rG   r   r   rP   rH   r   rI   r   rJ   r   re   r   rf   r   r`   )NNrl   )r   rm   rL   r
   rN   r
   rn   rK   ro   rK   rF   r   r   rO   rG   r   r   rP   rH   r   rI   r   rJ   r   )$
__future__r   typingr   r   r    r   r   r   r	   _normalizationsr
   r   r   r   r   r   r   r   dir_binaryr\   rd   r   r!   r    r&   getattrufuncvarsr{   _unaryr   r   __all__r   r   r   r   <module>   sz    $	6',
 (
