U
    9%e                     @   sf   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlZG dd	 d	e
jZdS )
    typeof)types)GUFuncBuilder)parse_signature)ufunc_find_matching_loop)	serializeNc                   @   s  e Zd ZdZdddi dfddZdd Zed	d
 Zdd Zdd Z	dd Z
dd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* Zed+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 ZdS )5GUFuncz
    Dynamic generalized universal function (GUFunc)
    intended to act like a normal Numpy gufunc, but capable
    of call-time (just-in-time) compilation of fast loops
    specialized to inputs.
    NF c                 C   sH   d | _ d| _|| _|| _t||||||| _| jjj| _t	| | d S )NF)
ufunc_frozen_is_dynamic	_identityr   gufunc_builderpy_func__name__	functoolsupdate_wrapper)selfr   	signatureidentitycache
is_dynamictargetoptionswritable_argsr
   r
   T/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/np/ufunc/gufunc.py__init__   s         zGUFunc.__init__c                 C   s6   | j }t|j|j| j|j| j|j|j|j	| j
d	}|S )N)	r   r   r   r   r   r   r   typesigsfrozen)r   dictr   r   r   r   r   r   r   _sigsr   )r   gbdctr
   r
   r   _reduce_states!   s    zGUFunc._reduce_statesc
              	   C   s<   | |||||||d}
|D ]}|
 | q|
  |	|
_|
S )N)r   r   r   r   r   r   r   )addbuild_ufuncr   )clsr   r   r   r   r   r   r   r   r   r   sigr
   r
   r   _rebuild0   s      zGUFunc._rebuildc                 C   s   d| j  dS )Nz<numba._GUFunc 'z'>)r   r   r
   r
   r   __repr__<   s    zGUFunc.__repr__c                 C   s   | j | d S N)r   r$   )r   Zftyr
   r
   r   r$   ?   s    z
GUFunc.addc                 C   s   | j  | _| S r+   )r   r%   r   r)   r
   r
   r   r%   B   s    zGUFunc.build_ufuncc                 C   s   t | jjdkstd| _dS )zI
        Disable the compilation of new signatures at call time.
        r   TN)lenr   r    AssertionErrorr   r)   r
   r
   r   disable_compileF   s    zGUFunc.disable_compilec                 C   s   | j S r+   )r   r)   r
   r
   r   r   N   s    zGUFunc.is_dynamicc                 C   s   | j jS r+   )r   ninr)   r
   r
   r   r/   R   s    z
GUFunc.ninc                 C   s   | j jS r+   )r   noutr)   r
   r
   r   r0   V   s    zGUFunc.noutc                 C   s   | j jS r+   )r   nargsr)   r
   r
   r   r1   Z   s    zGUFunc.nargsc                 C   s   | j jS r+   )r   ntypesr)   r
   r
   r   r2   ^   s    zGUFunc.ntypesc                 C   s   | j jS r+   )r   r   r)   r
   r
   r   r   b   s    zGUFunc.typesc                 C   s   | j jS r+   )r   r   r)   r
   r
   r   r   f   s    zGUFunc.identityc                 C   s   | j jS r+   )r   r   r)   r
   r
   r   r   j   s    zGUFunc.signaturec                 C   s   | j jS r+   )r   
accumulater)   r
   r
   r   r3   n   s    zGUFunc.accumulatec                 C   s   | j jS r+   )r   atr)   r
   r
   r   r4   r   s    z	GUFunc.atc                 C   s   | j jS r+   )r   outerr)   r
   r
   r   r5   v   s    zGUFunc.outerc                 C   s   | j jS r+   )r   reducer)   r
   r
   r   r6   z   s    zGUFunc.reducec                 C   s   | j jS r+   )r   reduceatr)   r
   r
   r   r7   ~   s    zGUFunc.reduceatc                 C   sD   t dd |}g }|D ](}t|tjr4||j q|| q|S )Nc                 S   s   t | S r+   r   )xr
   r
   r   <lambda>       z*GUFunc._get_ewise_dtypes.<locals>.<lambda>)map
isinstancer   ArrayappendZdtype)r   argsZargtysZtysZargtyr
   r
   r   _get_ewise_dtypes   s    zGUFunc._get_ewise_dtypesc                 G   s$   t | jj}t|t|d d kS )Nr      )r   r   r   r,   )r   r?   
parsed_sigr
   r
   r   _num_args_match   s    zGUFunc._num_args_matchc           
      G   s   t | jj}| |}g }t|d D ]@\}}t|}|dkrN|||  q&|t|| |d q&|d }t|d d pd}	|t||	d tj	| S )Nr   ArA   )
r   r   r   r@   	enumerater,   r>   r   r=   none)
r   r?   rB   Zewise_typeslidxZsig_dimndimZrettyZret_ndimr
   r
   r   _get_signature   s    
zGUFunc._get_signaturec                 O   s   | j s| js| j||S d|kr0||df7 }| j| dkrTd| j d}t|| |}| jrpt| j|s| j	| }| 
| |   | j||S )NoutFz Too few arguments for function 'z'. Note that the pattern `out = gufunc(Arg1, Arg2, ..., ArgN)` is not allowed. Use `gufunc(Arg1, Arg2, ..., ArgN, out) instead.)r   r   r   poprC   r   	TypeErrorr@   r   rK   r$   r%   )r   r?   kwargsmsgZewiser'   r
   r
   r   __call__   s    


zGUFunc.__call__)r   
__module____qualname____doc__r   r#   classmethodr(   r*   r$   r%   r.   propertyr   r/   r0   r1   r2   r   r   r   r3   r4   r5   r6   r7   r@   rC   rK   rQ   r
   r
   r
   r   r	   
   sV     















r	   )Znumbar   Z
numba.corer   Znumba.np.ufunc.ufuncbuilderr   Znumba.np.ufunc.sigparser   Znumba.np.numpy_supportr   r   r   ZReduceMixinr	   r
   r
   r
   r   <module>   s   