o
    0 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%   a/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/numba/np/ufunc/dufunc.py__init__   s   
zUfuncAtIterator.__init__c                 C   s6   |  || | j \}}| ||| | j  d S r   )_prepareindexerZbegin_loops_call_ufuncZ	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   Z	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.arrayobjr3   r4   r   r    r   r!   get_value_typer   intpr"   r   Zalloca_once_valueb_indicer2   unpack_tuplelenr)   prepare_compile_ufunccres)r$   r+   r,   r3   r4   r   r    r   r!   zeroZ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)	r6   r@   r   r:   shapestridesdataZget_item_pointer2layout)r$   r+   r,   r-   arrayarray_tyr@   ZshapesrB   rC   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   r8   Zget_functionoperatorgetitemr7   addstore)r$   r+   r,   r    rE   rF   idxsigimplrH   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)r6   rV   r>   r   return_typerL   cast)
r$   r+   r,   rE   rF   rG   rH   rV   ZfromtyZ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   rL   r#   rO   Zadd_linking_libslibrary)r$   r+   r,   r   rR   r>   r%   r%   r&   r=   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   )r>   r   r   rI   r"   r#   r9   rU   Zcall_internalZfndescr   rY   )r$   r+   r,   r-   r>   r   r   rG   rH   argsr"   r#   Zb_idxr.   Zval_bresr%   r%   r&   r*   t   s   
zUfuncAtIterator._call_ufuncNN)__name__
__module____qualname__r'   r/   r2   r(   rI   rU   rY   r=   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_functionr]   Z	inner_sigr>   )r$   r+   r,   Z	outer_sig	__class__r%   r&   r'      s   z1make_dufunc_kernel.<locals>.DUFuncKernel.__init__)r`   ra   rb   __doc__rf   r'   __classcell__r%   _dufuncrh   r&   DUFuncKernel   s    rn   )numba.nprd   Z_Kernelr`   r   )rm   rd   rn   r%   rl   r&   make_dufunc_kernel   s   rp   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   rc   )ro   rd   re   r'   rp   Znumpy_ufunc_kernel)r$   rf   rd   rh   r%   r&   r'      s
   zDUFuncLowerer.__init__)r`   ra   rb   rj   r'   rk   r%   r%   rh   r&   rq      s    rq   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 )NZnpyufunc)_targetcacher%   )r	   py_funcr   Z3_suppress_deprecation_warning_nopython_not_suppliedr   _initialize	functoolsupdate_wrapper)r$   ry   rs   rx   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)rs   )r   Zparse_identityre   rr   r'   r   ZPyUFunc_Nonereorderablery   r`   rj   rq   	_lower_meZ_install_cg_install_type)r$   r~   rs   rh   r%   r&   rz      s   



zDUFunc._initializec                 C   s&   t | jj }t| j| j| j|dS )4
        NOTE: part of ReduceMixin protocol
        )r~   rs   frozensiglist)list_dispatcher	overloadskeysdictrs   _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__rz   rO   disable_compile)clsr~   rs   r   r   r$   rR   r%   r%   r&   _rebuild   s   zDUFunc._rebuildc                 C   s   | S )zK
        For compatibility with the various *UFuncBuilder classes.
        r%   r1   r%   r%   r&   build_ufunc   s   zDUFunc.build_ufuncc                 C      | j jS r   )r   r}   r1   r%   r%   r&   r}         zDUFunc.targetoptionsc                 C   r   r   )r   ru   r1   r%   r%   r&   ru      r   z
DUFunc.ninc                 C   r   r   )r   rv   r1   r%   r%   r&   rv      r   zDUFunc.noutc                 C   r   r   )r   nargsr1   r%   r%   r&   r      r   zDUFunc.nargsc                 C   r   r   )r   ntypesr1   r%   r%   r&   r      r   zDUFunc.ntypesc                 C   r   r   )r   r   r1   r%   r%   r&   r      r   zDUFunc.typesc                 C   r   r   )r   rs   r1   r%   r%   r&   rs      r   zDUFunc.identityc                 C   r   r   )r   r   r1   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   r1   r%   r%   r&   r     s   
zDUFunc.disable_compilec                 C   s   t |\}}| ||S )z=
        Compile the DUFunc for the given signature.
        )r   Znormalize_signature_compile_for_argtys)r$   rR   r]   rW   r%   r%   r&   rO     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   npZndarrayr   tuplevaluesgetattrtypeNotImplementedre   r   )r$   r]   kwsdefaultargoutputrh   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   ru   pop	TypeErrorjoinsortedr;   rv   r   r0   r   ArrayrL   r   Zmap_arrayscalar_typeappendr   r   )	r$   r]   r   ru   r   Zargs_lenargtysr   Z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   RuntimeErrorr0   r   r   r   itemsr]   warningswarnr   ZNumbaWarningr   Z_compile_element_wise_functionr}   Z_finalize_ufunc_signatureZ!_build_element_wise_ufunc_wrapperZ	_add_loopintrt   r   r\   r   Zlibs)r$   r   rW   rR   r   r>   msgZ
actual_sigZ	dtypenumsrG   envr%   r%   r&   r   A  s6   	



zDUFunc._compile_for_argtysc                 C   s
   |j |kS r   )r]   )r$   ewise_typesrR   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   rH   r%   r&   <lambda>o  s    zUDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.impl.<locals>.<lambda>)r   r[   r   r   r   r&   rS   m  s   zCDUFunc._install_ufunc_attributes.<locals>.get_attr_fn.<locals>.implr%   )r   rS   r%   r   r&   get_attr_fnk  s   z5DUFunc._install_ufunc_attributes.<locals>.get_attr_fn)ru   rv   r   rs   r   )strr   r   Functionr
   )r$   templater   at
attributesr   Z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 ufuncrJ   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   )r6   r   r;   r]   r   r/   )r+   r,   rR   r]   r   r.   ZatyZidxtyZbtyr   r    r"   Z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"   rR   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    rR   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   Zbroadcast_torA   Zflat)r   r   r    r"   Zb_Z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   NumbaExperimentalFeatureWarningr0   r   r   NumbaTypeErrorListTupleZ	SliceTyper;   Sequencer   is_nonelikeanyr   ru   ZTypingErrorrO   rL   r   )r   r   r    r"   r   Zindices_arrZindices_listZindices_tupleZindices_sliceZindices_scalarZindices_empty_tupleZb_arrayZb_scalarZ	need_castru   r   r   r   r   r1   )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%   r1   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   rJ   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   rJ   )	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   rH   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   rJ   )	append_basic_block
goto_blockr   ZIntTyperangeZextract_valuemulrO   branch)r,   Z	block_posZ
block_nameZbb_endr]   rB   r.   rQ   bbr?   flat_idxr   ZstrideZ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 )NZaxis_endr   axis_r   rJ   )Zbasic_blockr   r   r   r   switchZadd_caseZposition_at_endphir   Zadd_incomingZsdiv)r+   r,   rR   r]   rB   itemsizerQ   axisr   Z
switch_endlr   blockr   r  r  valuer  r  r%   r&   codegenR  s(   
zZDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.compute_flat_idx.<locals>.codegen)r   r8   r;   )r   rB   r  rQ   r	  rR   r  r%   r  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 rZ   )r   r;   r   )r	  ndimaxr   rH   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 rZ   )r   r;   )r   rQ   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 identityrJ   )r;   
ValueErrorrA   r   )
r   rE   r	  rL   initialr   startrr   r   )id_noners   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  )rL   )Z
fill_valuerL   )
r  r  rA   r   emptyZndenumeratefullZravelrB   r  )r   rE   r	  rL   r  r   rA   r  rQ   r.   Z
result_idxviewrH   Zflat_poslhsrhs)r  rs   r  nb_dtyper   r   r  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   r  rJ   zduplicate value in 'axis')r	  rL   r  r   )r	  )r  r   r;   r  r   r   )r   rE   r	  rL   r  r  r   r   min_idxZmin_elemr  r  )axis_tupr  r  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   rE   r	  rL   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   r*  )r(  r%   r&   impl_axis_none  s   zGDUFunc._install_ufunc_reduce.<locals>.ol_reduce.<locals>.impl_axis_noner   NN)r   r   r   r   r0   r   r   r   ZUniTuplerL   Integerr   r;   r   r   r   rs   r`   r   r  r   r   r   r   ZOmittedZIntegerLiteral)r   rE   r	  rL   r  r   Zaxis_int_tupleZaxis_empty_tupleZ	axis_noner  r&  r)  r+  r,  r1   )r(  r  r  r  r  rs   r  r  r%  r   r   r   r   r  r&   	ol_reduce  s   






A

@ 
	z/DUFunc._install_ufunc_reduce.<locals>.ol_reducer-  r   )r$   r   r   r/  r%   r1   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   )r0   r   r   rL   r0  r%   r%   r&   r     s    r_   z#compilation disabled for %s.at(...))	r   r   r   rg   r   r   r   re   r   )r$   r   r    r"   r]   r   r   r   rh   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()).
        NZDUFuncTyping_)r[   Zgeneric)r   ZtargetdescrZtyping_contextr   r   r`   r   r   _type_meZinsert_user_functionr   r   )r$   r   Z_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.
        Nr_   )r   r   Zufunc_find_matching_loopr   ZinputsZoutputsr;   r   r   r   r]   )r$   r   looprR   r>   r%   r%   r&   rg   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 %srJ   ztyping gufuncs (nout > 1))r   r   ZNumpy_rules_ufuncZ_handle_inputsr;   r   rg   r   r   r   r   r   rv   r   r   rW   ZNumbaNotImplementedErrorextendr   )r$   r   Zkwtysr   Z_handle_inputs_resultZ
base_typesZexplicit_outputsZndimsrD   Zexplicit_output_countr   rR   r>   Zouttysr%   r%   r&   r1  F  s8   





zDUFunc._type_mer   )r   N)%r`   ra   rb   rj   setZ_DUFunc__base_kwargsr'   rz   r   classmethodr   r   propertyr}   ru   rv   r   r   r   rs   r   r   rO   r   r   r   r   r   r   r   r   r   r   r   rg   r1  rk   r%   r%   rh   r&   rr      sT    









$



e  (
rr   )3r{   rM   r   numpyr   Znumbar   r   Z
numba.corer   r   r   r   r   Znumba.core.extendingr	   r
   r   r   r   Znumba.core.typingr   Znumba.core.typing.templatesr   r   Znumba.cpython.unsafe.tupler   Znumba.np.ufuncr   Znumba.np.ufunc.ufunc_baser   r   Znumba.parforsr   r   ro   r   typingr   Zllvmliter   Znumba.core.compiler_lockr   r   rp   rq   ZReduceMixinr   rr   Z	MAP_TYPESr   r%   r%   r%   r&   <module>   s8    m
     P