U
    yh                      @  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dFdddddddddddddddddddddddZedGddddddddddddddddddd
ddZedHd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d$d&ddg Zd'd
 eeD Zd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCgZ dDdE Z!eD ]ZeeeZe!ee e< qee Z"dS )I    )annotations)OptionalN   )_binary_ufuncs_impl_dtypes_impl_unary_ufuncs_impl_util)	ArrayLikeArrayLikeOrScalarCastingModes	DTypeLike
normalizerNotImplementedTypeOutArrayc                 C  s,   |d k	r(t | |jj|} t| |j} | S N)r   typecast_tensordtypeZtorch_dtypetorchZbroadcast_toshape)resultoutcasting r   F/var/www/html/venv/lib/python3.8/site-packages/torch/_numpy/_ufuncs.py_ufunc_postprocess   s    r   c                 C  s"   g | ]}| d s|dk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gcdZ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x2r4   r   r5   r   r6   r7   r8   c                 s   |d k	r* fdd}
|
| |} |
||}nXt | tjrft |tjrft| |}t| |f| \} }nt| |jt	k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)r@   r   rA   r   result_type_implr   typecast_tensorsZnep50_to_tensors__name__NEP50_FUNCSr   )r=   r>   r   r4   r   r5   r   r6   r7   r8   rE   r   
torch_funcrD   r   wrappedJ   s    
   
z"deco_binary_ufunc.<locals>.wrapped)Nr   rH   __qualname__rK   rL   r   rJ   r   deco_binary_ufuncC   s     *$rP   r1   r2   F)r   r5   r   r6   r7   r8   axesaxisr9   r	   r:   r   r;   )r   r=   r>   r   r5   r   r6   r7   r8   rQ   rR   c               C  sF   |d krt | |}t| |f||\} }t| |}t|||}|S r   )r   rF   r   rG   r   r   r   )r=   r>   r   r   r5   r   r6   r7   r8   rQ   rR   r   r   r   r   r   y   s    r   Tr3   r
   r<   c               C  s   |d k	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)r@   r   rA   r   r   rB   cast_int_to_floatr   Z	_categoryr   
ValueErrorr   r   Zfloat16tor   )r=   r>   r   r4   r   r5   r   r6   r7   r8   r   r   r   r   r      s    


r   NNz-tuple[Optional[OutArray], Optional[OutArray]])r   r=   r>   out1out2r4   r   r5   r   r6   r7   r8   c               C  s   t dd ||fD }|dkr(tdn2|dkrR|\}}|d k	sH|d k	rZtdn|\}}|d krnt| |}t| |f||\} }t| |\}}t	|||}t	|||}||fS )Nc                 s  s   | ]}|d k	V  qd S r   r   )r"   rC   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)
sumrT   	TypeErrorr   rF   r   rG   r   r   r   )r=   r>   rW   rX   r   r4   r   r5   r   r6   r7   r8   Znum_outsZo1o2quotremr   r   r   r      s"    
r   c                O  s   t | df||\}}||fS )Nr   )r   )rC   argskwdsr^   r_   r   r   r   modf   s    rb   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.
    NTr1   r2   Fr3   r9   r	   r:   r;   r   )r   rC   r   r   r6   c         
        sB   |d k	rt | ||}  jtkr*t | }  | }	t|	||}	|	S r   )r   r   rH   	_fp_unaryrS   r   )
rC   r   r4   r   r5   r   r6   r7   r8   r   rJ   r   r   rL   (  s    

z!deco_unary_ufunc.<locals>.wrapped)NrM   rO   r   rJ   r   deco_unary_ufunc!  s      rt   )N)N)NNrV   )#
__future__r   typingr   r    r   r   r   r   Z_normalizationsr	   r
   r   r   r   r   r   r   dir_binaryrI   rP   r   r   r   r#   getattrZufuncvarsrb   Z_unaryrs   rt   __all__r   r   r   r   <module>   s   $	6 ( &'   *,
	 (
