
    
f1                     |    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	e
j                  ZdS )
    typeof)types)GUFuncBuilder)parse_signature)ufunc_find_matching_loop)	serializeNc                      e Zd ZdZdddi dfdZd Zed             Zd Zd	 Z	d
 Z
d Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zd Zd Zd Z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.
    NF c                     d | _         d| _        || _        || _        t	          ||||||          | _        | j        j        j        | _        t          j	        | |           d S )NF)
ufunc_frozen_is_dynamic	_identityr   gufunc_builderpy_func__name__	functoolsupdate_wrapper)selfr   	signatureidentitycache
is_dynamictargetoptionswritable_argss           5lib/python3.11/site-packages/numba/np/ufunc/gufunc.py__init__zGUFunc.__init__   sk    
%!
 ,Y%O O+3< w/////    c                     | j         }t          |j        |j        | j        |j        | j        |j        |j        |j	        | j
        	  	        }|S )N)	r   r   r   r   r   r   r   typesigsfrozen)r   dictr   r   r   r   r   r   r   _sigsr   )r   gbdcts      r   _reduce_stateszGUFunc._reduce_states!   sU     Jl^('**X<

 

 

 
r    c
           	           | |||||||          }
|D ]}|
                     |           |
                                 |	|
_        |
S )N)r   r   r   r   r   r   r   )addbuild_ufuncr   )clsr   r   r   r   r   r   r   r"   r#   r   sigs               r   _rebuildzGUFunc._rebuild0   sm     s7i(:!.mM M M  	 	CHHSMMMMr    c                     d| j          dS )Nz<numba._GUFunc 'z'>)r   r   s    r   __repr__zGUFunc.__repr__<   s    3$-3333r    c                 :    | j                             |           d S N)r   r*   )r   ftys     r   r*   z
GUFunc.add?   s    $$$$$r    c                 B    | j                                         | _        | S r3   )r   r+   r   r0   s    r   r+   zGUFunc.build_ufuncB   s    (4466
r    c                 R    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   r0   s    r   disable_compilezGUFunc.disable_compileF   s.    
 4&,--1111r    c                     | j         S r3   )r   r0   s    r   r   zGUFunc.is_dynamicN   s    r    c                     | j         j        S r3   )r   ninr0   s    r   r;   z
GUFunc.ninR   s    z~r    c                     | j         j        S r3   )r   noutr0   s    r   r=   zGUFunc.noutV   s    zr    c                     | j         j        S r3   )r   nargsr0   s    r   r?   zGUFunc.nargsZ       zr    c                     | j         j        S r3   )r   ntypesr0   s    r   rB   zGUFunc.ntypes^       z  r    c                     | j         j        S r3   )r   r   r0   s    r   r   zGUFunc.typesb   r@   r    c                     | j         j        S r3   )r   r   r0   s    r   r   zGUFunc.identityf       z""r    c                     | j         j        S r3   )r   r   r0   s    r   r   zGUFunc.signaturej   s    z##r    c                     | j         j        S r3   )r   
accumulater0   s    r   rI   zGUFunc.accumulaten   s    z$$r    c                     | j         j        S r3   )r   atr0   s    r   rK   z	GUFunc.atr   s    z}r    c                     | j         j        S r3   )r   outerr0   s    r   rM   zGUFunc.outerv   r@   r    c                     | j         j        S r3   )r   reducer0   s    r   rO   zGUFunc.reducez   rC   r    c                     | j         j        S r3   )r   reduceatr0   s    r   rQ   zGUFunc.reduceat~   rF   r    c                     t          d |          }g }|D ]L}t          |t          j                  r|                    |j                   7|                    |           M|S )Nc                      t          |           S r3   r   )xs    r   <lambda>z*GUFunc._get_ewise_dtypes.<locals>.<lambda>   s    vayy r    )map
isinstancer   Arrayappenddtype)r   argsargtystysargtys        r   _get_ewise_dtypeszGUFunc._get_ewise_dtypes   sn    (($// 	" 	"E%-- "

5;''''

5!!!!
r    c                     t          | j        j                  }t          |          t          |d                   t          |d                   z   k    S )Nr      )r   r   r   r7   )r   r[   
parsed_sigs      r   _num_args_matchzGUFunc._num_args_match   sC    $T%8%BCC
4yyC
1..Z]1C1CCCCr    c                 ^   t          | j        j                  }|                     |          }g }t	          |d                   D ]e\  }}t          |          }|dk    r|                    ||                    6|                    t          j        ||         |d                     ft          |d                   }t	          |d                   D ]J\  }}|||z            }	t          |          pd}
|                    t          j        |	|
d                     Kt          j	        | S )Nr   Ara   )
r   r   r   r_   	enumerater7   rY   r   rX   none)r   r[   rb   ewise_typeslidxsig_dimndimoffsetrettyret_ndims              r   _get_signaturezGUFunc._get_signature   s#   $T%8%BCC
,,T22 %jm44 	C 	CLCw<<DqyyS)****[%5tSAABBBBZ]##%jm44 	8 	8LCf-E7||(qHHHU[#667777z1~r    c                    | j         s| j        s | j        |i |S d|v r||                    d          fz  } | j        | du rd| j         d}t          |          |                     |          }| j        rt          | j        |          s3 | 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   poprc   r   	TypeErrorr_   r   rp   r*   r+   )r   r[   kwargsmsgewiser-   s         r   __call__zGUFunc.__call__   s
    < 	)t 	)4:t.v...f__VZZ&&((D4&%//
4=    
 C..  &&t,,
 	7
EJJ 	%$%t,CHHSMMMtz4*6***r    )r   
__module____qualname____doc__r   r(   classmethodr.   r1   r*   r+   r8   propertyr   r;   r=   r?   rB   r   r   r   rI   rK   rM   rO   rQ   r_   rc   rp   rx   r   r    r   r   r   
   sD         59!20 0 0 0   	 	 [	4 4 4% % %         X    X   X     X  ! ! X!     X  # # X# $ $ X$ % % X%   X     X  ! ! X! # # X#  D D D  0+ + + + +r    r   )numbar   
numba.corer   numba.np.ufunc.ufuncbuilderr   numba.np.ufunc.sigparser   numba.np.numpy_supportr   r	   r   ReduceMixinr   r   r    r   <module>r      s                5 5 5 5 5 5 3 3 3 3 3 3 ; ; ; ; ; ;                x+ x+ x+ x+ x+Y" x+ x+ x+ x+ x+r    