a
    h                      @  s  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d,dddddddddddddddddddddddZed-ddddddddddddddddddd
ddZed.ddddddddd!dddddddddddd"d#d$ZeD ]ZeeeZeee e< q6d%d& Zeg d' Zd(d
 eeD Zg d)Z d*d+ 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   P/var/www/html/assistant/venv/lib/python3.9/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>   s   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                   sP   t dddddddddd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extobjOptional[OutArray]r
   r   Optional[CastingModes]Optional[DTypeLike]
r   x1x2r5   r   r6   r   r7   r8   r9   c                 s   |d ur* fdd}
|
| |} |
||}nXt | tjrft |tjrft| |}t| |f| \} }nt| |jt	v j\} }| |}t
|| S )Nc                   s,   t | tjrt| | S tj| |dS 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   r5   r   r6   r   r7   r8   r9   rF   r   
torch_funcrE   r   wrappedJ   s    

z"deco_binary_ufunc.<locals>.wrapped)Nr   rI   __qualname__rL   rM   r   rK   r   deco_binary_ufuncC   s     *$rQ   r2   r3   F)r   r6   r   r7   r8   r9   axesaxisr:   r	   r;   r   r<   )r   r>   r?   r   r6   r   r7   r8   r9   rR   rS   c               C  sF   |d u rt | |}t| |f||\} }t| |}t|||}|S r   )r   rG   r   rH   r   r   r   )r>   r?   r   r   r6   r   r7   r8   r9   rR   rS   r   r   r   r   r   y   s    r   Tr4   r
   r=   c               C  s   |d ur4t | tjr$t| ||} qTtj| |d} n t | tjsTt| } t| } t|}t|j	dkrvt
dt| |}
| j	tjkr|
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   r5   r   r6   r   r7   r8   r9   r   r   r   r   r      s    


r   NNz-tuple[Optional[OutArray], Optional[OutArray]])r   r>   r?   out1out2r5   r   r6   r   r7   r8   r9   c               C  s   t dd ||fD }|dkr(tdn2|dkrR|\}}|d usH|d urZtdn|\}}|d u rnt| |}t| |f||\} }t| |\}}t	|||}t	|||}||fS )Nc                 s  s   | ]}|d uV  qd S r   r   )r"   rD   r   r   r   	<genexpr>       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)
sumrU   	TypeErrorr   rG   r   rH   r   r   r   )r>   r?   rX   rY   r   r5   r   r6   r   r7   r8   r9   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kwdsr`   ra   r   r   r   modf   s    rd   )r   rd   r   r   c                 C  s"   g | ]}| d s|dkr|qS )r   r   r   r!   r   r   r   r$      s   )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              
     sF   t ddddd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.
    NTr2   r3   Fr4   r:   r	   r;   r<   r   )r   rD   r   r   r7   c         
        sB   |d urt | ||}  jtv r*t | }  | }	t|	||}	|	S r   )r   r   rI   	_fp_unaryrT   r   )
rD   r   r5   r   r6   r   r7   r8   r9   r   rK   r   r   rM   (  s    

z!deco_unary_ufunc.<locals>.wrapped)NrN   rP   r   rK   r   deco_unary_ufunc!  s      rv   )N)N)NNrW   )#
__future__r   typingr   r    r   r   r   r   Z_normalizationsr	   r
   r   r   r   r   r   r   dir_binaryrJ   rQ   r   r   r   r#   getattrZufuncvarsrd   Z_unaryru   rv   __all__r   r   r   r   <module>   sx   $	6 ( &'   *,
 (
