o
    8ήcl                     @   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 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.d/ Zd0d1 Zd2d3 ZdS )4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.
    NFc                 C   sF   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 r   </tmp/pip-target-vg8gfxp4/lib/python/numba/np/ufunc/gufunc.py__init__   s   
zGUFunc.__init__c              
   C   s2   | j }t|j|j| j|j| j|j|j| j	d}|S )N)r   r   r   r   r   r   typesigsfrozen)
r   dictr   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   )addbuild_ufuncr   )clsr   r   r   r   r   r   r   r   r   sigr   r   r   _rebuild/   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   ftyr   r   r   r#   >   s   z
GUFunc.addc                 C   s   | j  | _| S r*   )r   r$   r
   r(   r   r   r   r$   A   s   zGUFunc.build_ufuncc                 C   s   t | jjdks
J d| _dS )zI
        Disable the compilation of new signatures at call time.
        r   TN)lenr   r   r   r(   r   r   r   disable_compileE   s   
zGUFunc.disable_compilec                 C   s   | j S r*   )r   r(   r   r   r   r   M   s   zGUFunc.is_dynamicc                 C      | j jS r*   )r
   ninr(   r   r   r   r/   Q      z
GUFunc.ninc                 C   r.   r*   )r
   noutr(   r   r   r   r1   U   r0   zGUFunc.noutc                 C   r.   r*   )r
   nargsr(   r   r   r   r2   Y   r0   zGUFunc.nargsc                 C   r.   r*   )r
   ntypesr(   r   r   r   r3   ]   r0   zGUFunc.ntypesc                 C   r.   r*   )r
   r   r(   r   r   r   r   a   r0   zGUFunc.typesc                 C   r.   r*   )r
   r   r(   r   r   r   r   e   r0   zGUFunc.identityc                 C   r.   r*   )r
   r   r(   r   r   r   r   i   r0   zGUFunc.signaturec                 C   r.   r*   )r
   
accumulater(   r   r   r   r4   m   r0   zGUFunc.accumulatec                 C   r.   r*   )r
   atr(   r   r   r   r5   q   r0   z	GUFunc.atc                 C   r.   r*   )r
   outerr(   r   r   r   r6   u   r0   zGUFunc.outerc                 C   r.   r*   )r
   reducer(   r   r   r   r7   y   r0   zGUFunc.reducec                 C   r.   r*   )r
   reduceatr(   r   r   r   r8   }   r0   zGUFunc.reduceatc                 C   sD   t dd |}g }|D ]}t|tjr||j q|| q|S )Nc                 S   s   t | S r*   r   )xr   r   r   <lambda>   s    z*GUFunc._get_ewise_dtypes.<locals>.<lambda>)map
isinstancer   Arrayappenddtype)r   argsargtystys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r'|||  q|t|| |d q|d }t|d d pAd}	|t||	d tj	| S )Nr   ArE   )
r   r   r   rD   	enumerater,   r>   r   r=   none)
r   r@   rF   ewise_typeslidxsig_dimndimrettyret_ndimr   r   r   _get_signature   s   

zGUFunc._get_signaturec                 O   s   | j s| js| j|i |S d|v r||df7 }| j| du r,d| j d}t|| |}| jr:t| j|sH| j	| }| 
| |   | j|i |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
   poprG   r   	TypeErrorrD   r   rS   r#   r$   )r   r@   kwargsmsgewiser&   r   r   r   __call__   s   


zGUFunc.__call__)r   
__module____qualname____doc__r   r"   classmethodr'   r)   r#   r$   r-   propertyr   r/   r1   r2   r3   r   r   r   r4   r5   r6   r7   r8   rD   rG   rS   rZ   r   r   r   r   r	   
   sT    















r	   )numbar   
numba.corer   numba.np.ufunc.ufuncbuilderr   numba.np.ufunc.sigparser   numba.np.numpy_supportr   r   r   ReduceMixinr	   r   r   r   r   <module>   s    