o
    i                     @   sB  d dl Z d dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
mZmZmZ d dlmZmZmZmZmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d d	lmZ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)m*Z* G dd dZ+dd Z,G dd deZ-G dd dej.ej/eZ0e!j12e0 dS )    N)jittypeof)cgutilstypes	serializesigutilserrors)	is_jittedoverload_attributeoverload_methodregister_jitable	intrinsic)npydecl)AbstractTemplate	signature)tuple_setitem)	_internal)	UfuncBaseUfuncLowererBase)array_analysis)ufuncbuilder)numpy_support)Callable)ir)global_compiler_lockc                   @   sV   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd ZdS )UfuncAtIteratorNc                 C   s.   || _ || _|| _|| _|| _|| _|| _d S N)ufuncaa_tyindices
indices_tybb_ty)selfr   r   r   r    r!   r"   r#    r%   R/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/numba/np/ufunc/dufunc.py__init__   s   
zUfuncAtIterator.__init__c                 C   s6   |  || | j \}}| ||| | j  d S r   )_prepareindexerbegin_loops_call_ufunc	end_loops)r$   contextbuilderloop_indices_r%   r%   r&   run$   s   zUfuncAtIterator.runc                 C   s   t | jtjS r   )
isinstancer!   r   	BaseTupler$   r%   r%   r&   need_advanced_indexing*   s   z&UfuncAtIterator.need_advanced_indexingc                 C   s   ddl m}m} | j| j}}| j| j}}|tj	d}	| j
d ur*t||	| _|  rEtj||t|d}|j}
||||
|\}
}n|f}|f}
||||
|\}
}||||||
|| _| j  | ||| _d S )Nr   )normalize_indicesFancyIndexer)count)numba.np.arrayobjr6   r7   r   r    r   r!   get_value_typer   intpr"   r   alloca_once_valueb_indicer5   unpack_tuplelenr)   prepare_compile_ufunccres)r$   r-   r.   r6   r7   r   r    r   r!   zeroindex_typesr%   r%   r&   r(   -   s0   



zUfuncAtIterator._preparec              	   C   s\   ddl m} t||j}t||j}|j}	t|||	|||j|}
|||||
}|
|fS )Nr   )	load_item)	r9   rE   r   r>   shapestridesdataget_item_pointer2layout)r$   r-   r.   r/   arrayarray_tyrE   shapesrG   rH   ptrvalr%   r%   r&   	_load_valI   s   zUfuncAtIterator._load_valc                 C   sd   | |}||tj}|tj|}||||f}	|tjd}
|||
}|	|| d |	fS )N   )
loaddtyper   r;   get_functionoperatorgetitemr:   addstore)r$   r-   r.   r    rK   rL   idxsigimplrO   oner%   r%   r&   
_load_flatT   s   
zUfuncAtIterator._load_flatc           
      C   s@   ddl m} | jjj}|j}	|||||	}|||||| d S )Nr   )
store_item)r9   r^   rB   r   return_typerS   cast)
r$   r-   r.   rK   rL   rN   rO   r^   fromtytotyr%   r%   r&   
_store_vala   s
   
zUfuncAtIterator._store_valc                 C   sN   | j jd }| jd u r| jjf}n| jj| jjf}||}||jf |S Nr   )	r   keyr"   r   rS   r#   rW   add_linking_libslibrary)r$   r-   r.   r   rZ   rB   r%   r%   r&   rA   h   s   

zUfuncAtIterator._compile_ufuncc                 C   s   | j }| j| j}}| |||||\}}| jd u r|f}	n| j| j| j}
}}| ||||
|\}}||f}	|||j	|j
|	}| |||||| d S r   )rB   r   r   rP   r"   r#   r=   r]   call_internalfndescr   rc   )r$   r-   r.   r/   rB   r   r   rN   rO   argsr"   r#   b_idxr0   val_bresr%   r%   r&   r+   t   s   
zUfuncAtIterator._call_ufuncNN)__name__
__module____qualname__r'   r1   r5   r(   rP   r]   rc   rA   r+   r%   r%   r%   r&   r      s    
	r   c                    s8   ddl m} G  fddd|j}| j jj7  _|S )Nr   npyimplc                       s$   e Zd ZdZZ fddZ  ZS )z(make_dufunc_kernel.<locals>.DUFuncKernelz
        npyimpl._Kernel subclass responsible for lowering a DUFunc kernel
        (element-wise function) inside a broadcast loop (which is
        generated by npyimpl.numpy_ufunc_kernel()).
        c                    s*   t  ||| | j|j\| _| _d S r   )superr'   dufuncfind_ewise_functionrj   	inner_sigrB   )r$   r-   r.   	outer_sig	__class__r%   r&   r'      s   z1make_dufunc_kernel.<locals>.DUFuncKernel.__init__)ro   rp   rq   __doc__ru   r'   __classcell__r%   _dufuncry   r&   DUFuncKernel   s    r   )numba.nprs   _Kernelro   r   )r~   rs   r   r%   r}   r&   make_dufunc_kernel   s   r   c                       s    e Zd ZdZ fddZ  ZS )DUFuncLowererzHCallable class responsible for lowering calls to a specific DUFunc.
    c                    s"   ddl m} t |t|j d S )Nr   rr   )r   rs   rt   r'   r   numpy_ufunc_kernel)r$   ru   rs   ry   r%   r&   r'      s
   zDUFuncLowerer.__init__)ro   rp   rq   r{   r'   r|   r%   r%   ry   r&   r      s    r   c                       s>  e Zd ZdZedZddi fddZ fddZd	d
 Ze	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dd  Zd!d" Z fd#d$Zd%d& Zed<d'd(Zd)d* Zd=d,d-Zd=d.d/Zd=d0d1Zd=d2d3Zd< fd4d5	Z d<d6d7Z!d8d9 Z"d:d; Z#  Z$S )>DUFuncz
    Dynamic universal function (DUFunc) intended to act like a normal
    Numpy ufunc, but capable of call-time (just-in-time) compilation
    of fast loops specialized to inputs.
    )identity
_keepaliveninnoutNFc                 C   sj   t |r|j}t  tdd|d||}W d    n1 s"w   Y  | || t| | d S )Nnpyufunc)_targetcacher%   )r	   py_funcr   3_suppress_deprecation_warning_nopython_not_suppliedr   _initialize	functoolsupdate_wrapper)r$   r   r   r   targetoptions
dispatcherr%   r%   r&   r'      s   
zDUFunc.__init__c                    s\   t |}tt| j||d |tjk| _|jj	| _	|jj
| _
t| | _|   |   d S )N)r   )r   parse_identityrt   r   r'   r   PyUFunc_Nonereorderabler   ro   r{   r   	_lower_me_install_cg_install_type)r$   r   r   ry   r%   r&   r      s   



zDUFunc._initializec                 C   s&   t | jj }t| j| j| j|dS )4
        NOTE: part of ReduceMixin protocol
        )r   r   frozensiglist)list_dispatcher	overloadskeysdictr   _frozen)r$   r   r%   r%   r&   _reduce_states   s   zDUFunc._reduce_statesc                 C   s<   t j| }||| |D ]}|| q|r|  |S )r   )r   _DUFunc__new__r   rW   disable_compile)clsr   r   r   r   r$   rZ   r%   r%   r&   _rebuild   s   zDUFunc._rebuildc                 C   s   | S )zK
        For compatibility with the various *UFuncBuilder classes.
        r%   r4   r%   r%   r&   build_ufunc   s   zDUFunc.build_ufuncc                 C      | j jS r   )r   r   r4   r%   r%   r&   r         zDUFunc.targetoptionsc                 C   r   r   )r   r   r4   r%   r%   r&   r      r   z
DUFunc.ninc                 C   r   r   )r   r   r4   r%   r%   r&   r      r   zDUFunc.noutc                 C   r   r   )r   nargsr4   r%   r%   r&   r      r   zDUFunc.nargsc                 C   r   r   )r   ntypesr4   r%   r%   r&   r      r   zDUFunc.ntypesc                 C   r   r   )r   r   r4   r%   r%   r&   r      r   zDUFunc.typesc                 C   r   r   )r   r   r4   r%   r%   r&   r      r   zDUFunc.identityc                 C   r   r   )r   r   r4   r%   r%   r&   r      r   zDUFunc.signaturec                 C   s   t | jjdks
J d| _dS )zI
        Disable the compilation of new signatures at call time.
        r   TN)r?   r   r   r   r4   r%   r%   r&   r     s   
zDUFunc.disable_compilec                 C   s   t |\}}| ||S )z=
        Compile the DUFunc for the given signature.
        )r   normalize_signature_compile_for_argtys)r$   rZ   rj   r_   r%   r%   r&   rW     s   z
DUFunc.addc                    sp   t jjj}|t|  D ]!}tt|d||ur.|j| dg|R i |}|tur.|  S qt	 j
|i |S )z}
        Allow any argument that has overridden __array_ufunc__ (NEP-18)
        to take control of DUFunc.__call__.
        __array_ufunc____call__)r   npndarrayr   tuplevaluesgetattrtypeNotImplementedrt   r   )r$   rj   kwsdefaultargoutputry   r%   r&   r     s   
zDUFunc.__call__c           	      O   s   | j j}|r&d|v r|d}||f7 }|r&tdddd t|D  t|}||ks8||| j j ks8J |r<J g }|d | D ]}t|}t	|t
jrT|j}nt|}|| qD| t|S )Noutz)unexpected keyword arguments to ufunc: %sz, c                 s       | ]}t |V  qd S r   )repr).0kr%   r%   r&   	<genexpr>*      z+DUFunc._compile_for_args.<locals>.<genexpr>)r   r   pop	TypeErrorjoinsortedr?   r   r   r2   r   ArrayrS   r   map_arrayscalar_typeappendr   r   )	r$   rj   r   r   r   args_lenargtysr   argtyr%   r%   r&   _compile_for_args"  s(   



zDUFunc._compile_for_argsc                 C   s   | j r
td| f t|tsJ |du r|}n|| }| jj D ]\}}||jkr<d| d}t	|t
j |  S q"t| j| j|\}}}t|||}t||\}}	}
| t|	| | j|	|j|
f | jj|j |S )a/  
        Given a tuple of argument types (these should be the array
        dtypes, and not the array types themselves), compile the
        element-wise function for those inputs, generate a UFunc loop
        wrapper, and register the loop with the Numpy ufunc object for
        this DUFunc.
        zcompilation disabled for %sNz>Compilation requested for previously compiled argument types (z~). This has no effect and perhaps indicates a bug in the calling code (compiling a ufunc more than once for the same signature)r   RuntimeErrorr2   r   r   r   itemsrj   warningswarnr   NumbaWarningr   _compile_element_wise_functionr   _finalize_ufunc_signature!_build_element_wise_ufunc_wrapper	_add_loopintr   r   rg   r   libs)r$   r   r_   rZ   r   rB   msg
actual_sig	dtypenumsrN   envr%   r%   r&   r   A  s6   	



zDUFunc._compile_for_argtysc                 C   s
   |j |kS r   )rj   )r$   ewise_typesrZ   r%   r%   r&   match_signaturef  s   
zDUFunc.match_signaturereturnc                 C   sD   dt dtfdd}t|}d}|D ]}||}t||| qd S )Nattrr   c                    s    fdd}|S )Nc                    s   t | jd   fddS )Nr   c                    s    S r   r%   r   rO   r%   r&   <lambda>o  s    zUDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.impl.<locals>.<lambda>)r   re   r   r   r   r&   r[   m  s   zCDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.implr%   )r   r[   r%   r   r&   get_attr_fnk  s   z5DUFunc._install_ufunc_attributes.<locals>.get_attr_fn)r   r   r   r   r   )strr   r   Functionr
   )r$   templater   at
attributesr   attr_fnr%   r%   r&   _install_ufunc_attributesi  s   
z DUFunc._install_ufunc_attributesc                 C   s   |  | | | d S r   )_install_ufunc_reduce_install_ufunc_at)r$   r   r%   r%   r&   _install_ufunc_methods~  s   
zDUFunc._install_ufunc_methodsc                    s&   t |}t|dd fdd	}d S )Nr   c                    s  t jdtjd t|tjsd}t|t|tj}t|tj}t|tj	}t|tj
}|p2|p2| }	|o;t|dk}
t|tjtjtjtj	f}t||pQ }t|g}jj}|dkrjt|rjtd|dkrzt|szd}t|t|r|jf n|r|j|f n	|j|jf fd	d
tfdd tfdddfdd	}d fdd	}ddd}dfdd	}|r|S |
r|r|S |	r|r|S |S )Nz ufunc.at feature is experimentalcategoryz)The first argument "a" must be array-liker      zsecond operand needed for ufuncrQ   z+second operand provided when ufunc is unaryc                    s   ddl m} t|dkr|j\}}}}|\}}	}
}n|jd \}}}}|d \}}	}
}||| ||	}	t |	||
|||}|| | d S )Nr   )
make_array   r   )r9   r   r?   rj   r   r1   )r-   r.   rZ   rj   r   r0   atyidxtybtyr   r    r"   at_iterr   r%   r&   apply_ufunc_codegen  s   zDDUFunc._install_ufunc_at.<locals>.ol_at.<locals>.apply_ufunc_codegenc                    s   t ||||}| fS r   r   none)	typingctxr   r   r    r"   rZ   r   r%   r&   apply_a_b_ufunc  s   z@DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.apply_a_b_ufuncc                    s   t |||}| fS r   r   )r   r   r   r    rZ   r   r%   r&   apply_a_ufunc  s   z>DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.apply_a_ufuncc                    s0    r|  |t|S |  |t|t|S r   )r   r   asarrayr   r   r    r"   b_noner%   r&   	impl_cast  s   z:DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_castc                    sH   r
| || d S t |}|| }t ||j} | |||j d S r   )r   r  broadcast_torF   flat)r   r   r    r"   b_a_)r   r   r  r%   r&   impl_generic  s   
z=DUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_genericc                 S   s   | |d ||d< d S )Nr%   r%   r  r%   r%   r&   impl_indices_empty_b_scalar  s   zLDUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_indices_empty_b_scalarc                    s.    r| || ||< d S | || |||< d S r   r%   r  r  r%   r&   impl_scalar_scalar  s   zCDUFunc._install_ufunc_at.<locals>.ol_at.<locals>.impl_scalar_scalarr   )r   r   r   NumbaExperimentalFeatureWarningr2   r   r   NumbaTypeErrorListTuple	SliceTyper?   Sequencer   is_nonelikeanyr   r   TypingErrorrW   rS   r   )r   r   r    r"   r   indices_arrindices_listindices_tupleindices_sliceindices_scalarindices_empty_tupleb_arrayb_scalar	need_castr   r  r
  r  r  r4   )r   r   r   r  r   r&   ol_at  sZ   







	z'DUFunc._install_ufunc_at.<locals>.ol_atr   r   r   r   )r$   r   r   r  r%   r4   r&   r        
zDUFunc._install_ufunc_atc                    s&   t |}t|dd fdd	}d S )Nreducer   c                    s  t jdtjd t|tjsd}t|t|tjo!t|j	tj
}t|tjo-t|dk}t|}jjd u jjjsS|rSt|dkrSd d}t|d|j 	d|jd  
t|rg|j	n|jtt|t
fd	d
t	fddtdd tdd tdd dfdd	}			 	 dfdd	}
		 	 d fdd	}		 	 ddd}		 	 d fdd	}|jdkr|s|	S |r|S |rtt|j |S |rdt|d   |S |dkst|tj
tjtjfr|
S d S )Nz$ufunc.reduce feature is experimentalr   z-The first argument "array" must be array-liker   rQ   zreduction operation 'z:' is not reorderable, so at most one axis may be specified)r   c                    s<    }d}t | D ]\}}||krqt|||}|d7 }q|S Nr   rQ   )	enumerater   )tuppossije)tup_init_m1r%   r&   tuple_slice  s   
zDDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.tuple_slicec                    sf    }ddt |}}}||k r1||krt|||}n| | }t|||}|d7 }|d7 }||k s|S r#  )r?   r   )r%  r&  rO   r'  r(  r)  szr*  )tup_initr%   r&   tuple_slice_append  s   zKDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.tuple_slice_appendc                    s:   t ||||}t|fdd  fdd}||fS )Nc                    s  |\}}}}| j |d}| | tdd}	|	}
|dkrBtd D ]}| ||d }| ||}| ||}| |
|}
q$nud|  k rN d k rn nEtd|D ]}| ||}| ||}| ||}| |
|}
qUt|d  D ]}| ||d }| ||}| ||}| |
|}
qwn"td d D ]}| ||}| ||}| ||}| |
|}
q| | W d    ||
fS 1 sw   Y  ||
fS )Nname@   r   rQ   )	append_basic_block
goto_blockr   IntTyperangeextract_valuemulrW   branch)r.   	block_pos
block_namebb_endrj   rG   r0   rY   bbrC   flat_idxr(  strideidx_im)len_idxr%   r&   	gen_block-  sD   
z\DUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx.<locals>.gen_blockc                    s   |\}}}}|j }|jdd}	g }
tD ]} ||d| |	|\}}|
||f q||# |||
d d }tD ]}|||
| d  q@W d    n1 sWw   Y  ||	 ||
d d j	}|
D ]
\}}|
|| qm|||S )Naxis_endr0  axis_r   rQ   )basic_blockr3  r6  r   r4  switchadd_caseposition_at_endphir   add_incomingsdiv)r-   r.   rZ   rj   rG   itemsizerY   axisr=  
switch_endlr(  blockr>  rH  rK  valuerC  rB  r%   r&   codegenR  s(   
zZDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx.<locals>.codegen)r   r;   r?   )r   rG   rN  rY   rO  rZ   rU  r%   rT  r&   compute_flat_idx(  s
   %zIDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idxc                 S   sF   | }t t| D ]}| | dk r| | | n| | }t|||}q|S rd   )r6  r?   r   )rO  ndimaxr(  rO   r%   r%   r&   
fixup_axisj  s
    zCDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.fixup_axisc                 S   sB   d| d }}t t| D ]}| | |k r|| | }}q||fS rd   )r6  r?   )r%  rY   r*  r(  r%   r%   r&   find_minr  s   zADUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.find_minc           
         s   r|d u rt |dkrd d}t|d}r# r#d}|d }nr(}n|}|jd }t||D ]	}	| |||	 }q4|S )Nr   'zero-size array to reduction operation  which has no identityrQ   )r?   
ValueErrorrF   r6  )
r   rK   rO  rS   initialr   startrr-  r(  )id_noner   identity_none	init_none
ufunc_namer%   r&   impl_1dz  s    

z@DUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_1dc                    s  |d u rt d|dk r||j7 }|dk s||jkrt dr5|d u r5|j| dkr5d d}t ||j|}|d u rad u ratj|d}t|D ]\}}	||d}
||
 ||< qOn|d u rrd urrtj|d}ntj||d}| }|d u rd u rt|D ]"\}}|| dkrq |j|j	||}|| |}}| ||||< q|S t|D ]*\}}|d u rȈd u r|| dkrq |j|j	||}|| |}}| ||||< q|S )Nz'axis' must be specifiedr   Invalid axisr[  r\  )rS   )
fill_valuerS   )
r]  rW  rF   r   emptyndenumeratefullravelrG   rN  )r   rK   rO  rS   r^  r   rF   r`  rY   r0   
result_idxviewrO   flat_poslhsrhs)rV  r   rb  nb_dtyper,  r/  rd  r%   r&   impl_nd_axis_int  sT   



zIDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_nd_axis_intc                    s  ||j }tdt|D ]+}|| dk s|| |j kr tdt|d t|D ]}|| || kr7tdq)q|\}}	| j||	||d}
t|dkrP|
S t|dkre| j|
||d d  d dS  }tt|D ]}||kr{t|||| }qm| j|
|dS )Nr   rf  rQ   zduplicate value in 'axis')rO  rS   r^  r   )rO  )rW  r6  r?   r]  r"  r   )r   rK   rO  rS   r^  rE  r(  r)  min_idxmin_elemr`  rX  )axis_tuprZ  rY  r%   r&   impl_nd_axis_tuple  s2   zKDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_nd_axis_tuplec                 S   s   |S r   r%   r   rK   rO  rS   r^  r%   r%   r&   impl_axis_empty_tuple  s   zNDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_axis_empty_tuplec                    s   |  | ||S r   )r"  rw  )ru  r%   r&   impl_axis_none  s   zGDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_axis_noner   NN)r   r   r   r  r2   r   r   r  UniTuplerS   Integerr  r?   r   r  r   r   ro   r   rW  r   r   r   r6  OmittedIntegerLiteral)r   rK   rO  rS   r^  r   axis_int_tupleaxis_empty_tuple	axis_nonere  rr  rv  rx  ry  r4   )ru  rV  rZ  rY  ra  r   rb  rc  rq  r.  r+  r,  r/  rd  r&   	ol_reduce  s   






A

@ 
	z/DUFunc._install_ufunc_reduce.<locals>.ol_reducerz  r   )r$   r   r   r  r%   r4   r&   r     r!  zDUFunc._install_ufunc_reducec                    s   t |r|fn||f}dd |D }tdd |D }| |dkr4| jr/d| f }t|| j|  t |r@t ||S t j|||f S )Nc                 s   r   r   )r   r   r   r%   r%   r&   r     r   zDUFunc.at.<locals>.<genexpr>c                 s   s&    | ]}t |tjr|jn|V  qd S r   )r2   r   r   rS   r  r%   r%   r&   r     s    rn   z#compilation disabled for %s.at(...))	r   r  r   rv   r   r   r   rt   r   )r$   r   r    r"   rj   r   r   r   ry   r%   r&   r     s   


z	DUFunc.atc                 C   sV   |du r	| j jj}td| jj tft| | jd}|	| | | 
| | | dS )a*  Constructs and installs a typing class for a DUFunc object in the
        input typing context.  If no typing context is given, then
        _install_type() installs into the typing context of the
        dispatcher object (should be same default context used by
        jit() and njit()).
        NDUFuncTyping_)re   generic)r   targetdescrtyping_contextr   r   ro   r   r   _type_meinsert_user_functionr   r   )r$   r   _ty_clsr%   r%   r&   r   "  s   

zDUFunc._install_typec                 C   sj   | j rt| |}|du rdS t|j|j dt| }| jj	 D ]\}}|j
|kr2||f  S q#dS )a  
        Given a tuple of element-wise argument types, find a matching
        signature in the dispatcher.

        Return a 2-tuple containing the matching signature, and
        compilation result.  Will return two None's if no matching
        signature was found.
        Nrn   )r   r   ufunc_find_matching_loopr   inputsoutputsr?   r   r   r   rj   )r$   r   looprZ   rB   r%   r%   r&   rv   2  s   	
zDUFunc.find_ewise_functionc                 C   s
  |rJ | j }tj|||}|\}}}}t|}	|	dkr)t|dt|  }
nt|}
| |
\}}|du rV| jrDt	d| |f | 
|
 | |
\}}|dusVJ |	dkr_t|}n|jdkrw|dkrrt|j||g}n
|jg}ntd|| t| S )z
        Implement AbstractTemplate.generic() for the typing class
        built by DUFunc._install_type().

        Return the call-site signature after either validating the
        element-wise signature or compiling for it.
        r   Nzcannot call %s with types %srQ   ztyping gufuncs (nout > 1))r   r   Numpy_rules_ufunc_handle_inputsr?   r   rv   r   r   r  r   r   r   r   r   r_   NumbaNotImplementedErrorextendr   )r$   r   kwtysr   _handle_inputs_result
base_typesexplicit_outputsndimsrJ   explicit_output_countr   rZ   rB   outtysr%   r%   r&   r  F  s8   





zDUFunc._type_mer   )r   N)%ro   rp   rq   r{   set_DUFunc__base_kwargsr'   r   r   classmethodr   r   propertyr   r   r   r   r   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   rv   r  r|   r%   r%   ry   r&   r      sT    









$



e  (
r   )3r   rU   r   numpyr   numbar   r   
numba.corer   r   r   r   r   numba.core.extendingr	   r
   r   r   r   numba.core.typingr   numba.core.typing.templatesr   r   numba.cpython.unsafe.tupler   numba.np.ufuncr   numba.np.ufunc.ufunc_baser   r   numba.parforsr   r   r   r   typingr   llvmliter   numba.core.compiler_lockr   r   r   r   ReduceMixinr   r   	MAP_TYPESr   r%   r%   r%   r&   <module>   s8    m
     P