o
    0 i|                     @   s  d Z ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ d
ZdZdZdddZejrYejZ nej!Z e fddZ"dd Z#dd Z$dd Z%dd Z&dd Z'dd Z(dd Z)e(Z*dd  Z+d!d" Z,d#d$ Z-d%d& Z.d'd( Z/d)d* Z0d+d, Z1d-d* Z0e1e0eej2ej3 d.d/ Z4d0d1 Z5d2d3 Z6ee6d4d5d6d7 Z7e1e5d8e6ej8 d9d: Z9d;d< Z:d=d> Z;d?d@ Z<dAdB Z=dCdD Z>dEdF Z?dGdH Z@dIdJ ZAdKdL ZBdMdN ZCdOdP ZDdQdR ZEdSdT ZFdUdV ZGdWdX ZHdYdZ ZId[d\ ZJd]d^ ZKd_d` ZLdadb ZMdcdd ZNdedf ZOdgdh ZPdidj ZQdkdl ZRdmdn ZSdodp ZTdqdr ZUdsdt ZVdudv ZWdwdx ZXdydz ZYd{d| ZZd}d~ Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd Zgdd Zhdd Zidd Zjdd Zkdd Zldd Zmdd Zndd Zodd Zpdd Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}ddĄ Z~ddƄ ZddȄ Zddʄ Zdd̄ Zdd΄ ZddЄ Zdd҄ ZddԄ Zddք Zdd؄ Zddڄ Zdd܄ Zddބ Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zdd Zdd Zdd ZdS (  zCodegen for functions used as kernels in NumPy functions

Typically, the kernels of several ufuncs that can't map directly to
Python builtins
    Noverload)impl_ret_untracked)typingtypeserrorsloweringcgutilsconfig)register_jitable)
npdatetime)	cmathimplmathimplnumbers)numpy_versiong+eG?g&{?g9B.?c                    s   t ||ksJ t | j|ksJ | jd  |du r }t fdd| jD r-| j|ksBddl}| jjj}d	|| }J |dS )zchecks that the following are true:
    - args and sig.args have arg_count elements
    - all input types are homogeneous
    - return type is 'return_type' if provided, otherwise it must be
      homogeneous with the input types.
    r   Nc                 3   s    | ]}| kV  qd S N .0argtyr   ]/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/numba/np/npyfuncs.py	<genexpr>*   s    z/_check_arity_and_homogeneity.<locals>.<genexpr>z"{0} called with invalid types: {1})
lenargsallreturn_typeinspectcurrentframef_backf_codeco_nameformat)sigr   arityr   r   fnamemsgr   r   r   _check_arity_and_homogeneity   s   
"r(   c                    sx    j }}tj||gt|j }tj|||d}	 fddt	||jD }
 
|	|
} |tj|jS )Nnamec                    s    g | ]\}}  ||qS r   )cast)r   r   Zargtybuildercontextr   r   r   
<listcomp>>   s    z0_call_func_by_name_with_cast.<locals>.<listcomp>)moduleget_argument_typellvmliteirFunctionTyper   r   r	   insert_pure_functionzipcallr+   r   float64r   )r.   r-   r$   r   	func_namer   modZltyfntyfnZ	cast_argsresultr   r,   r   _call_func_by_name_with_cast5   s   

r>   c              
      s<  |j d }z|| }W n ty$ } zd|t|}	t|	d }~ww  j}
|tjv rt	 |} fdd|D }|
 g| }|gt|j  }fdd|D }tjtj |}t|
||} ||  |d }|S fdd|j D }|j}tj||}tj|
||d} ||j |}|S )Nr   z!No {0} function for real type {1}c                    s   g | ]}t  |qS r   )r	   Zalloca_once_valuer   )r-   r   r   r/   ^   s    z/_dispatch_func_by_name_type.<locals>.<listcomp>c                    s   g | ]	}  | qS r   )get_value_typeZ
as_pointer)r   r   r.   r   r   r/   f   s    c                    s   g | ]}  |qS r   )r1   )r   Zatyr@   r   r   r/   n       r)   )r   KeyErrorr#   strr   ZLoweringErrorr0   r   Zcomplex_domainmake_complexZ_getpointerlistr2   r3   r4   ZVoidTyper	   Zget_or_insert_functionr7   loadr1   r   r5   Zcall_external_function)r.   r-   r$   r   tableZ	user_namer   r9   er'   r:   outZptrargsZ	call_argsZcall_argtysZcall_argltysr;   r<   retvalargtypesrestyper   )r-   r.   r   _dispatch_func_by_name_typeE   s<   
	



rM   c              	   C   s  t ||d |\}}|jd }| |d}| |d}| |d|jjd > }	|d||}
|d||}|d|	|}|||}||
|}|j|ddn\}}| |j	}W d    n1 sbw   Y  |E |j	}|
||}|||}|d||}|d||}|||}|d	||}|||}||||}|||}W d    n1 sw   Y  W d    n1 sw   Y  ||j}||| ||| |S )
N   r      ==FZlikely>!=)r(   r   get_constanttypewidthicmp_unsignedand_or_if_elsebasic_blockZsdivsremicmp_signedxorselectaddphiadd_incoming)r.   r-   r$   r   numdenr   ZERO	MINUS_ONEZMIN_INTZden_is_zeroZden_is_minus_oneZnum_is_min_intZcould_cause_sigfpeZ
force_zerothen	otherwisebb_thenbb_otherwisedivr:   num_gt_zeroden_gt_zeronot_same_signmod_not_zeroneeds_fixing	fix_valueZresult_otherwiser=   r   r   r   np_int_sdiv_impl   sB   
rs   c                 C   s   t ||d |\}}|jd }| |d}|d||}|j}	t||? |j}
|||}|d||}|d||}|	||}|d||}|
||}||||}|||}W d    n1 sgw   Y  ||j}|||	 |||
 |S )NrN   r   rT   rS   )r(   r   rU   rX   r\   r	   if_unlikelyr]   r^   r_   rY   r`   ra   rb   rV   rc   )r.   r-   r$   r   rd   re   r   rf   den_not_zerobb_no_ifbb_ifr:   rm   rn   ro   rp   rq   rr   Z	final_modr=   r   r   r   np_int_srem_impl   s*   
rx   c                 C   H   t | ||jd |j |}t| ||jd |j |}| ||j||gS Nr   rP   )rs   r   r   rx   
make_tupler.   r-   r$   r   rl   remr   r   r   np_int_sdivrem_impl      r~   c              	   C   s   t ||d |\}}|jd }| |d}|d||}|j|dd:\}	}
|	 |j}W d    n1 s6w   Y  |
 |||}|j}W d    n1 sQw   Y  W d    n1 s`w   Y  ||j}|	|| |	|| |S )NrN   r   rQ   FrR   )
r(   r   rU   rX   r[   r\   Zudivrb   rV   rc   )r.   r-   r$   r   rd   re   r   rf   Zdiv_by_zerorh   ri   rj   rl   rk   r=   r   r   r   np_int_udiv_impl   s&   
	r   c                 C   s   t ||d |\}}|jd }| |d}|d||}|j}	t|| |j}
|||}W d    n1 s9w   Y  ||j	}|
||	 |
||
 |S )NrN   r   rT   )r(   r   rU   rX   r\   r	   rt   Zuremrb   rV   rc   )r.   r-   r$   r   rd   re   r   rf   ru   rv   rw   r:   r=   r   r   r   np_int_urem_impl   s   
r   c                 C   ry   rz   )r   r   r   r   r{   r|   r   r   r   np_int_udivrem_impl   r   r   c                 C      t ||d |j| S NrN   )r(   fdivr.   r-   r$   r   r   r   r   np_real_div_impl  s   
r   c                 C   s   t ||d |\}}|jd }| |d}|||}|d||}	|d||}
|d||}||	||
|}||||}|||S )NrN   r           rT   <)	r(   r   rU   fremfcmp_orderedrY   r_   r`   fadd)r.   r-   r$   r   in1in2r   rf   resZres_ne_zeroZden_lt_zeroZres_lt_zerorq   rr   r   r   r   np_real_mod_impl  s   

r   c                 C   r   r   )r(   r   r   r   r   r   np_real_fmod_impl  s   
r   c                 C   s8   t j|jd}|||}|d||}||||S )Nr   r   )r2   r3   ConstantrV   fsubr   r`   )r.   r-   r   rf   Zarg_negatedZarg_is_negativer   r   r   _fabs   s   r   c                    s    fdd|D \}}|j }|j}|j }|j}	|jtfdd||||	fD s/J d j}
tjd}tjd}t	 |}t	 |	} 
d||} |\}}|  
d||} 
d||} ||} |z\}}|  |||
_  |||
_W d    n1 sw   Y  |F  |	|} |	|} ||} ||} ||} ||} ||} ||} |||
_  |||
_W d    n1 sw   Y  W d    n1 sw   Y  W d    n	1 s	w   Y  |F  ||	} ||} |	|} ||} ||} ||} ||} ||} |||
_  |||
_W d    n1 sZw   Y  W d    |
 S W d    |
 S 1 sww   Y  |
 S )	Nc                    "   g | ]}j  jd  |dqS r   valuerD   r   r   r-   r.   r$   r   r   r/   /      z'np_complex_div_impl.<locals>.<listcomp>c                       g | ]}|j  kqS r   rV   r   iftyper   r   r/   7  rA   mismatched typesr         ?>=rQ   )realimagrV   r   make_helperr   r2   r3   r   r   r   r[   rY   r   fmulr   r   	_getvalue)r.   r-   r$   r   r   r   in1rin1iin2rin2irI   rf   ONEin2r_absin2i_absin2r_abs_ge_in2i_absrh   ri   Zin2r_is_zeroZin2i_is_zeroZin2_is_zeroZinn_thenZinn_otherwiserattmp1tmp2Zscltmp3tmp4tmp5Ztmp6r   r-   r.   r   r$   r   np_complex_div_impl'  sx   
& 
-
--r   c                 C      d S r   r   x1x2r   r   r   _npy_logaddexpt     r   c                    s    t | dd fdd}d S )Ngenerictargetc                    s(   | |krd S |   fdd}|S )Nc                    sX   | |}}||kr| S || }|dkr| |  S |dkr*| | S |S )Nr   r   )r   r   xytmp)expfnlog1pfnshiftr   r   impl  s   
z;_generate_logaddexp.<locals>.ol_npy_logaddexp.<locals>.implr   )r   r   r   constr   r   )r   r   ol_npy_logaddexp{  s
   z-_generate_logaddexp.<locals>.ol_npy_logaddexpr   )Z
fnoverloadr   r   r   r   r   r   r   _generate_logaddexpw  s   
r   c                 C   r   r   r   r   r   r   r   r     r   c                 C   F   t ||d | jt}|| jg |jR i }| ||}|||S r   )r(   typing_contextresolve_value_typer   get_call_typer   get_functionr.   r-   r$   r   r;   r   r   r   r   np_real_logaddexp_impl  
   
r   c                 C   r   r   r   r   r   r   r   _npy_logaddexp2  r   r   c                 C   r   r   r   r   r   r   r   npy_log2_1p  r   r   r   r   c                    s   | t   fdd}|S )Nc                    s    t |  S r   )nplog1pr   ZLOG2Er   r   r     s   zol_npy_log2_1p.<locals>.impl)
_NPY_LOG2E)r   r   r   r   r   ol_npy_log2_1p  s   r   r   c                 C   r   r   )r(   r   r   r   r   r   r   r   r   r   r   np_real_logaddexp2_impl  r   r   c                    sf   |\}}|j  t fdd|D sJ d|j\}}| |||tj}| |||tj}|||S )Nc                 3   s    | ]}|j  kV  qd S r   r   r   Zlltyper   r   r     s    z&np_int_truediv_impl.<locals>.<genexpr>zmust have homogeneous types)rV   r   r   r+   r   r8   r   )r.   r-   r$   r   rd   re   ZnumtyZdentyr   r   r   np_int_truediv_impl  s   
r   c                 C   s.   t | |||}t|j|j}t| |||fS r   )r   r   	signaturer   np_real_floor_impl)r.   r-   r$   r   r   sr   r   r   np_real_floor_div_impl  s   r   c                 C   ry   rz   )r   r   r   r   r{   r|   r   r   r   np_real_divmod_impl  r   r   c              	      s
  j d j}t||} fdd|D \}}|j}|j}	|j}
|j}|jtfdd||	|
|fD s;J dtj	
d} j}||_t |
}t |} d||} |\}}|5  ||
} |	|} ||} ||} |
|} ||}t ||f|_W d    n1 sw   Y  |5  |
|} ||} |
|} |	|} ||} ||}t ||f|_W d    n1 sw   Y  W d    | S W d    | S 1 sw   Y  | S )Nr   c                    r   r   r   r   r   r   r   r/     r   z-np_complex_floor_div_impl.<locals>.<listcomp>c                    r   r   r   r   r   r   r   r/     rA   r   r   r   )r   underlying_floatr   r   r   r   rV   r   r2   r3   r   r   r   r   r   r[   r   r   r   r   r   )r.   r-   r$   r   Z
float_kindZ	floor_sigr   r   r   r   r   r   rf   rI   r   r   r   rh   ri   r   r   r   r   r   r   r   r   r   np_complex_floor_div_impl  sV   
&	

r   c                 C      t ||d t| |||S r   r(   r   Zcomplex_power_implr   r   r   r   np_complex_power_impl     r   c                 C   r   r   )r(   r   Zreal_power_implr   r   r   r   real_float_power_impl  r   r   c                 C   r   r   r   r   r   r   r   np_complex_float_power_impl$  r   r   c                 C   r   r   )r(   r   Zgcd_implr   r   r   r   np_gcd_impl-     r   c           
      C   sX   |j \}}||  kr|jksJ  J |\}}dd }| ||||}	t| ||j|	S )Nc                 S   s$   | dkrdS t | |t||   S )z7
        Like gcd, heavily cribbed from Julia.
        r   )absr   gcd)abr   r   r   lcm;  s   $znp_lcm_impl.<locals>.lcm)r   r   compile_internalr   )
r.   r-   r$   r   ZxtyZytyr   r   r   r   r   r   r   np_lcm_impl5  s   
r   c                 C   s$  t ||d tdkrdd }| ||||}t| ||j|S |d }|jd }| ||}|j}	| |	d}
| |	d}| |	d}| |	t	d	}|
|_
|
|_tjtjg|gd
 R  }|| g}t| |||}t| |||}t| |||}|||
|}||||}|||||_
| S )NrP   )rN   r   c                 S   s$   t | j| j}|dkrdS | | S )Nr   y                )mathhypotr   r   )zr   r   r   r   complex_signO  s   z*np_complex_sign_impl.<locals>.complex_signr   r   r         nanrN   )r(   r   r   r   r   r   rD   r   rU   floatr   r   r   r   r   booleanr   np_complex_ge_implnp_complex_eq_implnp_complex_lt_implr`   )r.   r-   r$   r   r   r   opr   r=   float_tyrf   r   rg   ZNANZcmp_sigZcmp_argsarg1_ge_arg2Zarg1_eq_arg2Zarg1_lt_arg2Zreal_when_geZreal_when_nger   r   r   np_complex_sign_implH  s0   
r  c                 C      t ||d t|d|S )NrP   z	llvm.rintr(   r   Zcall_fp_intrinsicr   r   r   r   np_real_rint_implu     r  c           	      C   s|   t ||d |jd }|j}| j|||d d}| ||}tj|gd  }t| |||jg|_t| |||jg|_|	 S )NrP   r   r   rN   )
r(   r   r   rD   r   r   r  r   r   r   )	r.   r-   r$   r   r   r  r   rI   	inner_sigr   r   r   np_complex_rint_impl{  s   
r  c                 C   r   NrP   )r(   r   exp_implr   r   r   r   np_real_exp_impl  r   r  c                 C   r   r  )r(   r   r  r   r   r   r   np_complex_exp_impl  r   r  c                 C   J   t ||d |d j}tj||g}tj|j|dd}|||d gS )NrP   r   z	llvm.exp2r)   	r(   rV   r2   r3   r4   r	   r5   r0   r7   r.   r-   r$   r   ll_tyr;   r<   r   r   r   np_real_exp2_impl     

r  c           	      C   s|   t ||d |jd }|j}| j|||d d}| ||}| |t}|||j|_|||j|_t	| |||
 gS NrP   r   r   )r(   r   r   rD   rU   
_NPY_LOGE2r   r   r   r  r   )	r.   r-   r$   r   r   r  r   r   Zloge2r   r   r   np_complex_exp2_impl  s   
r  c                 C   r   r  )r(   r   log_implr   r   r   r   np_real_log_impl  r   r  c                 C   r   r  )r(   r   r  r   r   r   r   np_complex_log_impl  r   r  c                 C   r  )NrP   r   z	llvm.log2r)   r  r  r   r   r   np_real_log2_impl  r  r  c                 C   n   t ||d |jd }|j}t| |||}| j|||d}| |t}|||j|_|||j	|_	|
 S r  )r(   r   r   r  rD   rU   r   r   r   r   r   )r.   r-   r$   r   r   r  r   Zlog2er   r   r   np_complex_log2_impl     
r  c                 C   r   r  )r(   r   Z
log10_implr   r   r   r   np_real_log10_impl  r   r   c                 C   r  r  )r(   r   r   r  rD   rU   _NPY_LOG10Er   r   r   r   )r.   r-   r$   r   r   r  r   Zlog10er   r   r   np_complex_log10_impl  r  r"  c                 C   r   r  )r(   r   Z
expm1_implr   r   r   r   np_real_expm1_impl  r   r#  c                 C   s   t ||d |jd }|j}tj|gd  }| |d}| j|||d d}t| |||jg}	| ||}
t	| |||j
g}t| |||j
g}||	|}||	||
_
||||
_|
 S )NrP   r   rN   r   r   )r(   r   r   r   r   rU   rD   r  r   np_real_cos_implr   np_real_sin_implr   r   r   )r.   r-   r$   r   r   r  float_unary_sigrg   r   r   rI   Zcos_imagZsin_imagr   r   r   r   np_complex_expm1_impl  s   
r'  c                 C   r   r  )r(   r   Z
log1p_implr   r   r   r   np_real_log1p_impl	  r   r(  c                 C   s   t ||d |jd }|j}tj|gd  }tj|gd  }| |d}| j|||d d}	| ||}
||	j|}t	| ||||	j
g}t| |||	j
|g|
_
t| |||g|
_|
 S )NrP   r   rN      r   r   )r(   r   r   r   r   rU   rD   r   r   np_real_hypot_implr   np_real_atan2_implr  r   )r.   r-   r$   r   r   r  r&  Zfloat_binary_sigr   r   rI   Zreal_plus_onelr   r   r   np_complex_log1p_impl  s"   
r-  c                 C   r   r  )r(   r   	sqrt_implr   r   r   r   np_real_sqrt_impl&  r   r/  c                 C   r   r  )r(   r   r.  r   r   r   r   np_complex_sqrt_impl+  r   r0  c                 C       t ||d ||d |d S NrP   r   )r(   mulr   r   r   r   np_int_square_impl3     r4  c                 C   r1  r2  )r(   r   r   r   r   r   np_real_square_impl8  r5  r6  c                 C   s:   t ||d tj|jgd  }t| |||d |d gS NrP   r)  r   )r(   r   r   r   r   complex_mul_impl)r.   r-   r$   r   
binary_sigr   r   r   np_complex_square_impl<  s
   
r:  c                    s:   t ||d tdddd   fdd}| ||||S )NrP   T)Zfastmathc                 S   s$   | dk rt |  d S t | dS )Nr   gUUUUUU?)r   powerr   r   r   r   cbrtK  s   znp_real_cbrt_impl.<locals>.cbrtc                    s   t | rt jS  | S r   )r   isnanr   r   r<  r   r   _cbrtR  s   
z np_real_cbrt_impl.<locals>._cbrt)r(   r   r   )r.   r-   r$   r   r?  r   r>  r   np_real_cbrt_implF  s
   
r@  c           	      C   sd   t ||d |j}tj|gd  }| ||d |tj}| tjd}|||}| ||tj|S r7  )	r(   r   r   r   r+   r   r8   rU   r   )	r.   r-   r$   r   r   r9  Zin_as_floatr   Zresult_as_floatr   r   r   np_int_reciprocal_impl]  s   rA  c                 C   s*   t ||d | |jd}|||d S )NrP   r   r   )r(   rU   r   r   )r.   r-   r$   r   r   r   r   r   np_real_reciprocal_implk  s   rB  c              	   C   s  t ||d |jd }|j}| |d}| |d}| j|||d d}| ||}	|j}
|j}t| ||
}t| ||}|d||}|	|\}}|0 |
||
}|||}||
|}|
||}|||}||	_||||	_W d    n1 sw   Y  |. |
|
|}||
|}|||}|
||}||||	_||||	_W d    n1 sw   Y  W d    |	 S W d    |	 S 1 sw   Y  |	 S )NrP   r   r   r   r   <=)r(   r   r   rU   rD   r   r   r   r   r[   r   r   r   r   r   )r.   r-   r$   r   r   r  rf   r   r   rI   r   r   Zin1r_absZin1i_absZin1i_abs_le_in1r_absrh   ri   rZtmp0dinv_dZminus_rr   r   r   np_complex_reciprocal_implq  sJ   


rG  c                 C   r   r  )r(   r   sin_implr   r   r   r   r%    r   r%  c                 C   r   r  )r(   r   rH  r   r   r   r   np_complex_sin_impl  r   rI  c                 C   r   r  )r(   r   cos_implr   r   r   r   r$    r   r$  c                 C   r   r  )r(   r   rJ  r   r   r   r   np_complex_cos_impl  r   rK  c                 C   r   r  )r(   r   Ztan_implr   r   r   r   np_real_tan_impl  r   rL  c                 C   r   r  )r(   r   Z	asin_implr   r   r   r   np_real_asin_impl  r   rM  c                 C   r   r  )r(   r   Z	acos_implr   r   r   r   np_real_acos_impl  r   rN  c                 C   r   r  )r(   r   Z	atan_implr   r   r   r   np_real_atan_impl  r   rO  c                 C   r   r   )r(   r   Zatan2_float_implr   r   r   r   r+    r   r+  c                 C   r   r   )r(   r   Zhypot_float_implr   r   r   r   r*    r   r*  c                 C   r   r  )r(   r   Z	sinh_implr   r   r   r   np_real_sinh_impl  r   rP  c                 C   s   t ||d |jd }|j}tj|gd  }| |||d }| ||}|j}	|j}
t| |||
g}t	| |||	g}t
| |||
g}t| |||	g}||||_||||_| S NrP   r   rN   )r(   r   r   r   r   rD   r   r   r%  rP  r$  np_real_cosh_implr   r   )r.   r-   r$   r   r   ftyfsig1r   rI   xrxisxishxrcxichxrr   r   r   np_complex_sinh_impl  s   
r[  c                 C   r   r  )r(   r   Z	cosh_implr   r   r   r   rR    r   rR  c                 C   s   t ||d |jd }|j}tj|gd  }| |||d }| ||}|j}	|j}
t| |||
g}t	| |||	g}t
| |||
g}t| |||	g}||||_||||_| S rQ  )r(   r   r   r   r   rD   r   r   r$  rR  r%  rP  r   r   )r.   r-   r$   r   r   rS  rT  r   rI   rU  rV  rY  rZ  rW  rX  r   r   r   np_complex_cosh_impl  s   
r\  c                 C   r   r  )r(   r   Z	tanh_implr   r   r   r   np_real_tanh_impl&  r   r]  c                 C   sn  t ||d |jd }|j}tj|gd  }| |d}| |||d }| ||}	|j}
|j}t	| |||g}t
| |||g}t| |||
g}t| |||
g}|||}|||}|||}|||}|||}|||}|||}|||}|||}|||}|||}|||}|||}|||}||||	_||||	_|	 S )NrP   r   rN   r   )r(   r   r   r   r   rU   rD   r   r   r%  r$  rP  rR  r   r   r   r   r   )r.   r-   r$   r   r   rS  rT  r   r   rI   rU  rV  siciZshrZchr_rsis_rcZicZsqr_rcZsqr_icrE  rF  Zrs_rcZis_icZis_rcZrs_icZnumrZnumir   r   r   np_complex_tanh_impl+  s<   
rc  c                 C   r   r  )r(   r   Z
asinh_implr   r   r   r   np_real_asinh_implT  r   rd  c                 C   r   r  )r(   r   Z
acosh_implr   r   r   r   np_real_acosh_impl\  r   re  c                 C   s   t ||d |jd }tj|gd  }| ||d}|d }t| ||||g}t| ||||g}	t| |||g}
t| |||	g}t	| |||
|g}t| ||||g}t
| |||gS )NrP   r   r)  y      ?        )r(   r   r   r   Zget_constant_genericr   Zcomplex_add_implZcomplex_sub_implr0  r8  r  )r.   r-   r$   r   r   Zcsig2r   r   Z
x_plus_oneZx_minus_oneZsqrt_x_plus_oneZsqrt_x_minus_oneZ	prod_sqrtZlog_argr   r   r   np_complex_acosh_impla  s,   

rf  c                 C   r   r  )r(   r   Z
atanh_implr   r   r   r   np_real_atanh_impl  r   rg  c                 C   r  )NrP   z
llvm.floorr  r   r   r   r   r     r	  r   c                 C   r  )NrP   z	llvm.ceilr  r   r   r   r   np_real_ceil_impl  r	  rh  c                 C   r  )NrP   z
llvm.truncr  r   r   r   r   np_real_trunc_impl  r	  ri  c                 C   r  )NrP   z	llvm.fabsr  r   r   r   r   np_real_fabs_impl  r	  rj  c                       t ||dtjd |jd  fdd|D \}}|j}|j}|j}|j}	 d||}
 d||	} d||} d	||	} |
|} ||} ||S )
NrN   r   r   c                       g | ]
}j  |d qS r   rD   r   r,   r   r   r/         z&np_complex_ge_impl.<locals>.<listcomp>rS   ordrQ   r   	r(   r   r   r   r   r   r   rY   rZ   )r.   r-   r$   r   r   r   rU  rV  yryixr_gt_yrno_nan_xi_yixr_eq_yrZxi_ge_yi
first_termsecond_termr   r,   r   r        
r   c                    rk  )
NrN   rl  r   c                    rm  rn  ro  r   r,   r   r   r/     rp  z&np_complex_le_impl.<locals>.<listcomp>r   rq  rQ   rC  rr  )r.   r-   r$   r   r   r   rU  rV  rs  rt  xr_lt_yrrv  rw  Zxi_le_yirx  ry  r   r,   r   np_complex_le_impl  rz  r|  c                       t ||dtjd |jd  fdd|D \}}|j}|j}|j}|j}	 d||}
 d||	} d||} d||	} |
|} ||} ||S )	NrN   rl  r   c                    rm  rn  ro  r   r,   r   r   r/     rp  z&np_complex_gt_impl.<locals>.<listcomp>rS   rq  rQ   rr  )r.   r-   r$   r   r   r   rU  rV  rs  rt  ru  rv  rw  Zxi_gt_yirx  ry  r   r,   r   np_complex_gt_impl  rz  r~  c                    r}  )	NrN   rl  r   c                    rm  rn  ro  r   r,   r   r   r/     rp  z&np_complex_lt_impl.<locals>.<listcomp>r   rq  rQ   rr  )r.   r-   r$   r   r   r   rU  rV  rs  rt  r{  rv  rw  Zxi_lt_yirx  ry  r   r,   r   r    rz  r  c                    v   t ||dtjd |jd  fdd|D \}}|j}|j}|j}|j}	 d||}
 d||	} |
|S )NrN   rl  r   c                    rm  rn  ro  r   r,   r   r   r/     rp  z&np_complex_eq_impl.<locals>.<listcomp>rQ   )r(   r   r   r   r   r   r   rY   )r.   r-   r$   r   r   r   rU  rV  rs  rt  rw  Zxi_eq_yir   r,   r   r        
r   c                    r  )NrN   rl  r   c                    rm  rn  ro  r   r,   r   r   r/     rp  z&np_complex_ne_impl.<locals>.<listcomp>rT   )r(   r   r   r   r   r   fcmp_unorderedrZ   )r.   r-   r$   r   r   r   rU  rV  rs  rt  Zxr_ne_yrZxi_ne_yir   r,   r   np_complex_ne_impl  r  r  c                 C   s8   | j |||d}t||j}t||j}|||S )Nr   )rD   r	   is_truer   r   rZ   )r.   r-   r   valcomplex_valZre_trueZim_truer   r   r   _complex_is_true)  s   r  c                 C   >   t ||dtjd t||d }t||d }|||S NrN   rl  r   rP   )r(   r   r   r	   r  rY   r.   r-   r$   r   r   r   r   r   r   np_logical_and_impl0     r  c                 C   N   t ||dtjd t| ||jd |d }t| ||jd |d }|||S r  )r(   r   r   r  r   rY   r  r   r   r   np_complex_logical_and_impl7     r  c                 C   r  r  )r(   r   r   r	   r  rZ   r  r   r   r   np_logical_or_impl>  r  r  c                 C   r  r  )r(   r   r   r  r   rZ   r  r   r   r   np_complex_logical_or_implE  r  r  c                 C   r  r  )r(   r   r   r	   r  r_   r  r   r   r   np_logical_xor_implL  r  r  c                 C   r  r  )r(   r   r   r  r   r_   r  r   r   r   np_complex_logical_xor_implS  r  r  c                 C   "   t ||dtjd t||d S NrP   rl  r   )r(   r   r   r	   Zis_falser   r   r   r   np_logical_not_implZ     r  c                 C   s4   t ||dtjd t| ||jd |d }||S r  )r(   r   r   r  r   not_)r.   r-   r$   r   r   r   r   r   np_complex_logical_not_impl_  s   
r  c                 C   0   t ||d |\}}|d||}||||S NrN   r   r(   r^   r`   )r.   r-   r$   r   arg1arg2Zarg1_sge_arg2r   r   r   np_int_smax_impln     r  c                 C   r  r  r(   rX   r`   )r.   r-   r$   r   r  r  Zarg1_uge_arg2r   r   r   np_int_umax_implu  r  r  c                 C   h   t ||d |\}}|d||}|d||}||||}|d||}	||	||}
||||
S NrN   unor   r(   r  r`   r   )r.   r-   r$   r   r  r  arg1_nanany_nan
nan_resultr  non_nan_resultr   r   r   np_real_maximum_impl|     r  c                 C   sh   t ||d |\}}|d||}|d||}||||}|d||}	||	||}
||||
S r  r  )r.   r-   r$   r   r  r  arg2_nanr  r  r  r  r   r   r   np_real_fmax_impl  r  r  c                 C      t ||d |jd }ttj|}tjtjg|gd R  }|\}}t| |||g}	t| |||g}
||	|
}||	||}t	| |||}||||}||||S NrN   r   
r(   r   r   r   r   r   np_complex_isnan_implrZ   r`   r   r.   r-   r$   r   r   bc_sigbcc_sigr  r  r  r  r  r  r  r  r   r   r   np_complex_maximum_impl     
r  c                 C      t ||d |jd }ttj|}tjtjg|gd R  }|\}}t| |||g}	t| |||g}
||	|
}||
||}t	| |||}||||}||||S r  r  r  r   r   r   np_complex_fmax_impl     
r  c                 C   r  NrN   rC  r  )r.   r-   r$   r   r  r  Zarg1_sle_arg2r   r   r   np_int_smin_impl  r  r  c                 C   r  r  r  )r.   r-   r$   r   r  r  Zarg1_ule_arg2r   r   r   np_int_umin_impl  r  r  c                 C   r  NrN   r  rC  r  r.   r-   r$   r   r  r  r  r  r  arg1_le_arg2r  r   r   r   np_real_minimum_impl  r  r  c                 C   sh   t ||d |\}}|d||}|d||}||||}|d||}	||	||}
||||
S r  r  r  r   r   r   np_real_fmin_impl  r  r  c                 C   r  r  
r(   r   r   r   r   r   r  rZ   r`   r|  r.   r-   r$   r   r   r  r  r  r  r  r  r  r  r  r  r   r   r   np_complex_minimum_impl  r  r  c                 C   r  r  r  r  r   r   r   np_complex_fmin_impl  r  r  c                 C      t ||dtjd tjS NrP   rl  r(   r   r   r	   Z	false_bitr   r   r   r   np_int_isnan_impl     r  c                 C   r  r  )r(   r   r   r   is_nanr   r   r   r   np_real_isnan_impl$  r  r  c                 C   <   t ||dtjd |\}|j\}| j|||d}t||S NrP   rl  r   )r(   r   r   r   rD   r   r  r.   r-   r$   r   r   r   r  r   r   r   r  )  s
   r  c                 C   r  r  )r(   r   r   r	   Ztrue_bitr   r   r   r   np_int_isfinite_impl2  r  r  c                 C   &   t ||dtjd |d|d tjS )NrP   rl  rT   r   )r(   r   r   rX   r   NATr   r   r   r   np_datetime_isfinite_impl7     r  c                 C   r  )NrP   rl  rQ   r   )r(   r   r   r^   r   r  r   r   r   r   np_datetime_isnat_impl<  r  r  c                 C   r  r  )r(   r   r   r   	is_finiter   r   r   r   np_real_isfinite_implA  r  r  c                 C   r  r  )r(   r   r   r   rD   r   r  r  r   r   r   np_complex_isfinite_implF  
   r  c                 C   r  r  r  r   r   r   r   np_int_isinf_implN  r  r  c                 C   r  r  )r(   r   r   r   is_infr   r   r   r   np_real_isinf_implS  r  r  c                 C   r  r  )r(   r   r   r   rD   r   r  r  r   r   r   np_complex_isinf_implX  r  r  c           
   	   C   s   t ||dtjd tj| tjdtj| tjdtj| tj	di}|j
d }ttd|j }| |}|||d ||| }|d||d}	|	S )	NrP   rl  i   l        l            r   ZuintrT   )r(   r   r   Zfloat16rU   Zuint16float32Zuint32r8   Zuint64r   getattrZbitwidthr?   rY   ZbitcastrX   rV   )
r.   r-   r$   r   masksZarg_tyZ
arg_int_tyZarg_ll_int_tyZint_resZbool_resr   r   r   np_real_signbit_impl`  s   

r  c                 C   r   r   )r(   r   Zcopysign_float_implr   r   r   r   np_real_copysign_implr  r   r  c                 C   s.   t ||d tjdtjdi}t| ||||dS )NrN   numba_nextafterfnumba_nextafter	nextafter)r(   r   r  r8   rM   )r.   r-   r$   r   dispatch_tabler   r   r   np_real_nextafter_implw  s   
r  c                 C   s   t ||d tjdtjdi}|j\}t|j||}|d j}|t	j
}tj|||g}	tj|j|	dd}
||
||d g}||g }t| ||||d}|||d S )NrP   r  r  r   zllvm.copysignr)   r  )r(   r   r  r8   r   r   r   r   rV   r   infr2   r3   r4   r	   r5   r0   r7   rM   r   )r.   r-   r$   r   r  r   r
  r  Zll_infr;   r<   Zll_sinfZ
inner_argsr  r   r   r   np_real_spacing_impl  s&   



r  c           	      C   sH   |\}}|j \}}| |||tj}t||tj}t| ||||fS r   )r   r+   r   Zintcr   r   r   Z
ldexp_impl)	r.   r-   r$   r   r   r   Zty1Zty2Zf_fi_sigr   r   r   np_real_ldexp_impl  s
   
r  r   )__doc__r   Zllvmlite.irr2   numpyr   Znumba.core.extendingr   Znumba.core.imputilsr   Z
numba.corer   r   r   r   r	   r
   r   Znumba.npr   Znumba.np.mathr   r   r   Znumba.np.numpy_supportr   r   r!  r  r(   ZUSE_LEGACY_TYPE_SYSTEMr8   Zcast_arg_tyZ
np_float64r>   rM   rs   rx   r~   r   r   r   Znp_int_fmod_implr   r   r   r   r   r   r   r   expr   r   r   r   Zexp2r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r   r"  r#  r'  r(  r-  r/  r0  r4  r6  r:  r@  rA  rB  rG  r%  rI  r$  rK  rL  rM  rN  rO  r+  r*  rP  r[  rR  r\  r]  rc  rd  re  rf  rg  r   rh  ri  rj  r   r|  r~  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   <module>   s$    
>%M


6		-
	
*)				
