a
    –§»aÀ  ã                   @   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d d!„ Zd"d#„ Zd$d%„ Zd&d'„ ZdS )(Ú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   úO/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/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   Z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   s   | j jS r*   )r
   Úninr(   r   r   r   r-   Q   s    z
GUFunc.ninc                 C   s   | j jS r*   )r
   Únoutr(   r   r   r   r.   U   s    zGUFunc.noutc                 C   s   | j jS r*   )r
   Únargsr(   r   r   r   r/   Y   s    zGUFunc.nargsc                 C   s   | j jS r*   )r
   Úntypesr(   r   r   r   r0   ]   s    zGUFunc.ntypesc                 C   s   | j jS r*   )r
   r   r(   r   r   r   r   a   s    zGUFunc.typesc                 C   s   | j jS r*   )r
   r   r(   r   r   r   r   e   s    zGUFunc.identityc                 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>j   ó    z*GUFunc._get_ewise_dtypes.<locals>.<lambda>)ÚmapÚ
isinstancer   ÚArrayÚappendZdtype)r   ÚargsZargtysZtysZargtyr   r   r   Ú_get_ewise_dtypesi   s    zGUFunc._get_ewise_dtypesc                 G   s$   t | jjƒ}t|ƒt|d ƒd kS )Nr   é   )r   r   r   r+   )r   r8   Ú
parsed_sigr   r   r   Ú_num_args_matchs   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 ƒp‚d}	| t ||	d¡¡ tj	|Ž S )Nr   ÚAéÿÿÿÿr:   )
r   r   r   r9   Ú	enumerater+   r7   r   r6   Únone)
r   r8   r;   Zewise_typesÚlÚidxZsig_dimÚndimZrettyZret_ndimr   r   r   Ú_get_signaturex   s    
zGUFunc._get_signaturec                 O   s    | j s| js| j|i |¤ŽS d|v r4|| d¡f7 }| j|Ž du rXd| j› d�}t|ƒ‚|  |¡}| jrtt| j|ƒs�| 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
   Úpopr<   r   Ú	TypeErrorr9   r   rD   r#   r$   )r   r8   ÚkwargsÚmsgZewiser&   r   r   r   Ú__call__Ž   s    ÿ


zGUFunc.__call__)r   Ú
__module__Ú__qualname__Ú__doc__r   r"   Úclassmethodr'   r)   r#   r$   r,   Úpropertyr   r-   r.   r/   r0   r   r   r9   r<   rD   rJ   r   r   r   r   r	   
   s:   ÿ









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   