U
    9%e                      @  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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< q:d%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)OptionalUnionN   )_binary_ufuncs_impl_dtypes_impl_unary_ufuncs_impl_util)	ArrayLikeCastingModes	DTypeLike
normalizerNotImplementedTypeOutArrayScalarc                 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   S/var/www/html/Darija-Ai-API/env/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]Union[ArrayLike, Scalar]r   Optional[CastingModes]Optional[DTypeLike]
r   x1x2r5   r   r6   r   r7   r8   r9   c                 s   |d k	r* fdd}
|
| |} |
||}nTt | tjrft |tjrft| |}t| |f| \} }nt| |jt	k\} }| |}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   castY   s    z0deco_binary_ufunc.<locals>.wrapped.<locals>.cast)rB   r   rC   r   result_type_implr	   typecast_tensorsZnep50_to_tensors__name__NEP50_FUNCSr   )r?   r@   r   r5   r   r6   r   r7   r8   r9   rG   r   
torch_funcrF   r   wrappedH   s    
  
z"deco_binary_ufunc.<locals>.wrapped)Nr   rJ   __qualname__rM   rN   r   rL   r   deco_binary_ufuncA   s     *$rR   r2   r3   F)r   r6   r   r7   r8   r9   axesaxisr:   r
   r<   r   r=   )r   r?   r@   r   r6   r   r7   r8   r9   rS   rT   c               C  sF   |d krt | |}t| |f||\} }t| |}t|||}|S r   )r   rH   r	   rI   r   r   r   )r?   r@   r   r   r6   r   r7   r8   r9   rS   rT   r   r   r   r   r   w   s    r   Tr4   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 )NrA   r   zldexp 2nd arg must be integer)rB   r   rC   r	   r   rD   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 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#   rE   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   rH   r	   rI   r   r   r   )r?   r@   rY   rZ   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f||\}}||fS )Nr   )r   )rE   argskwdsr`   ra   r   r   r   modf   s    rd   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   rE   r   r   r7   c         
        sB   |d k	rt | ||}  jtkr*t | }  | }	t|	||}	|	S r   )r	   r   rJ   	_fp_unaryrU   r   )
rE   r   r5   r   r6   r   r7   r8   r9   r   rL   r   r   rN   &  s    

z!deco_unary_ufunc.<locals>.wrapped)NrO   rQ   r   rL   r   deco_unary_ufunc  s      rv   )N)N)NNrX   )$
__future__r   typingr   r   r    r   r   r   r	   Z_normalizationsr
   r   r   r   r   r   r   r   dir_binaryrK   rR   r   r   r   r$   getattrZufuncvarsrd   Z_unaryru   rv   __all__r   r   r   r   <module>   s   $	6 ( &'   *,
	 (
