o
    8ήc-                     @   s   d dl Z d dlZd dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZmZ ddlT d dlZe Zde_e ZG dd	 d	eZG d
d deeZG dd deeZedkr]e  dS dS )    N)compile_isolatedFlagsutils)types)TestCasetag   )*Tc                   @   sB   e Zd Zdd Zdd Zdd Zddefd	d
ZdefddZdS )BaseComplexTestc              	   C   sJ   ddddddt dt dg}tjd	kr|t d
g7 }dd t||D S )N               r         ?g      -inf+infwin32nanc                 S      g | ]	\}}t ||qS  complex.0xyr   r   ?/tmp/pip-target-vg8gfxp4/lib/python/numba/tests/test_complex.py
<listcomp>       z0BaseComplexTest.basic_values.<locals>.<listcomp>)floatsysplatform	itertoolsproductselfrealsr   r   r   basic_values   s   
zBaseComplexTest.basic_valuesc              	   C   sR   ddddt j t j
 tdtdg}tjdkr|tdg7 }d	d
 t||D S )Nr   r   r   r   r   r   r   r   c                 S   r   r   r   r   r   r   r   r       r   z/BaseComplexTest.more_values.<locals>.<listcomp>)mathpir   r   r    r!   r"   r#   r   r   r   more_values   s   
zBaseComplexTest.more_valuesc              	   C   s:   ddddt j t j
 tdtdg}dd t||D S )	Nr   r   r   r   infr   c                 S   r   r   r   r   r   r   r   r   %   r   z2BaseComplexTest.non_nan_values.<locals>.<listcomp>)r'   r(   r   r!   r"   r#   r   r   r   non_nan_values"   s   zBaseComplexTest.non_nan_valuesr   Nc                 C   s   |D ]T}t ||g|d}|j}	|tjtjfv rdnd}
|D ]8}z||}W n ty? } z| dt| W Y d }~qd }~ww |	|}d||
f }| j|||
|||d qqd S )Nflagssingledoublemath domain errorfor input %r with prec %r)preculpsabs_tolmsg)	r   entry_pointr   float32	complex64
ValueErrorassertInstrassertPreciseEqual)r$   pyfuncx_typesx_valuesr3   r4   r-   txcrcfuncr2   vxexpectedegotr5   r   r   r   	run_unary'   s&   
zBaseComplexTest.run_unaryc                 C   s   |D ]j\}}t |||g|d}|j}	t||gttjtjg@ r"dnd}
|D ]E\}}z|||}W n" tyK } z| dt| W Y d }~q&d }~w t	yS   Y q&w |	||}d||f|
f }| j
|||
||d q&qd S )Nr,   r.   r/   r0   r1   )r2   r3   r5   )r   r6   setr   r7   r8   r9   r:   r;   ZeroDivisionErrorr<   )r$   r=   value_typesvaluesr3   r-   r@   tyrA   rB   r2   rC   vyrD   rE   rF   r5   r   r   r   
run_binary8   s0   

zBaseComplexTest.run_binary)	__name__
__module____qualname__r&   r)   r+   enable_pyobj_flagsrG   rN   r   r   r   r   r
      s    
r
   c                   @   s\   e Zd ZefddZdd ZefddZdd Zefd	d
Zdd Z	efddZ
dd ZdS )TestComplexc                 C   ^   | j ttjtjg|  |d | j ttjtjgg d|d | j ttjtj	gddg|d d S Nr,   )r   r   r   g      )
rG   real_usecaser   r8   
complex128r&   int8int64r7   float64r$   r-   r   r   r   	test_realP      
zTestComplex.test_realc                 C      | j td d S Nr,   )r]   no_pyobj_flagsr$   r   r   r   test_real_npmX      zTestComplex.test_real_npmc                 C   rT   rU   )
rG   imag_usecaser   r8   rX   r&   rY   rZ   r7   r[   r\   r   r   r   	test_imag[   r^   zTestComplex.test_imagc                 C   r_   r`   )rf   ra   rb   r   r   r   test_imag_npmc   rd   zTestComplex.test_imag_npmc                 C   rT   rU   )
rG   conjugate_usecaser   r8   rX   r&   rY   rZ   r7   r[   r\   r   r   r   test_conjugatef   r^   zTestComplex.test_conjugatec                 C   r_   r`   )ri   ra   rb   r   r   r   test_conjugate_npmn   rd   zTestComplex.test_conjugate_npmc                 C   sF   t t|  |  }tjtjftjtjfg}| jt|||d dS )zN
        Test complex.__div__ implementation with non-trivial values.
        r,   N)	listr!   r"   r)   r   rX   r8   rN   div_usecaser$   r-   rK   rJ   r   r   r   test_divq   s
   

zTestComplex.test_divc                 C   r_   r`   )rn   ra   rb   r   r   r   test_div_npm{   rd   zTestComplex.test_div_npmN)rO   rP   rQ   rR   r]   rc   rf   rg   ri   rj   rn   ro   r   r   r   r   rS   N   s    
rS   c                   @   s  e Zd ZdZdd Z		ddddZdd	 Zd
d Zdd Zdd Z	e
fddZdd Ze
fddZdd Ze
fddZdd Ze
fddZdd Zd d! Zd"d# Zd$d% Zd&d' Ze
fd(d)Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/dZd[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4dS )e	TestCMathz)
    Tests for cmath module support.
    c                 C   s"   | j |tjtjg|  |d d S r`   )rG   r   rX   r8   r&   )r$   r=   r-   r   r   r   check_predicate_func   s   
zTestCMath.check_predicate_funcr   Nc                 C   sH   | j |tjg|p|  |||d | j |tjg|p|  |||d d S )N)r-   r3   r4   )rG   r   rX   r)   r8   r&   )r$   r=   r-   r3   r4   rK   r   r   r   check_unary_func   s   
zTestCMath.check_unary_funcc                 C      |  tt d S N)rr   phase_usecaserR   rb   r   r   r   
test_phase   rd   zTestCMath.test_phasec                 C   rs   rt   )rr   ru   ra   rb   r   r   r   test_phase_npm   rd   zTestCMath.test_phase_npmc                 C   rs   rt   )rr   polar_usecaserR   rb   r   r   r   
test_polar   rd   zTestCMath.test_polarc                 C   rs   rt   )rr   rx   ra   rb   r   r   r   test_polar_npm   rd   zTestCMath.test_polar_npmc                    s2    fdd}|t j  |t j  d S )Nc                    s*   dd |D }j t| | fg| d d S )Nc                 S   s.   g | ]}t |jr|jd kr|j|jfqS )r   )r'   isinfimagreal)r   zr   r   r   r      s
    
z8TestCMath.test_rect.<locals>.do_test.<locals>.<listcomp>r,   )rN   rect_usecase)tpseed_valuesrK   r-   r$   r   r   do_test   s   z$TestCMath.test_rect.<locals>.do_test)r   r[   r)   r7   r&   )r$   r-   r   r   r   r   	test_rect   s   zTestCMath.test_rectc                 C   r_   r`   )r   ra   rb   r   r   r   test_rect_npm   rd   zTestCMath.test_rect_npmc                 C   rs   rt   )rq   isnan_usecaserR   r\   r   r   r   
test_isnan   rd   zTestCMath.test_isnanc                 C   rs   rt   )rq   r   ra   rb   r   r   r   test_isnan_npm   rd   zTestCMath.test_isnan_npmc                 C   rs   rt   )rq   isinf_usecaserR   r\   r   r   r   
test_isinf   rd   zTestCMath.test_isinfc                 C   rs   rt   )rq   r   ra   rb   r   r   r   test_isinf_npm   rd   zTestCMath.test_isinf_npmc                 C   rs   rt   )rq   isfinite_usecaserR   r\   r   r   r   test_isfinite   rd   zTestCMath.test_isfinitec                 C   rs   rt   )rq   r   ra   rb   r   r   r   test_isfinite_npm   rd   zTestCMath.test_isfinite_npmc                 C      | j ttdd d S N   )r3   )rr   exp_usecaserR   rb   r   r   r   test_exp      zTestCMath.test_expc                 C   r   r   )rr   r   ra   rb   r   r   r   test_exp_npm   s   zTestCMath.test_exp_npmc                 C   rs   rt   )rr   log_usecaserR   rb   r   r   r   test_log   rd   zTestCMath.test_logc                 C   rs   rt   )rr   r   ra   rb   r   r   r   test_log_npm   rd   zTestCMath.test_log_npmc                 C   sH   t t|  |  }tjtjftjtjfg}| jt|||dd d S )N   )r-   r3   )	rk   r!   r"   r)   r   rX   r8   rN   log_base_usecaserm   r   r   r   test_log_base   s   


zTestCMath.test_log_basec                 C   r_   r`   )r   ra   rb   r   r   r   test_log_base_npm   rd   zTestCMath.test_log_base_npmc                 C   rs   rt   )rr   log10_usecaserR   rb   r   r   r   
test_log10   rd   zTestCMath.test_log10c                 C   rs   rt   )rr   r   ra   rb   r   r   r   test_log10_npm   rd   zTestCMath.test_log10_npmc                 C   rs   rt   )rr   sqrt_usecaserR   rb   r   r   r   	test_sqrt   rd   zTestCMath.test_sqrtc                 C   s:   |  tt dd tddD }| jttjg|td d S )Nc                 S   s   g | ]}d |  qS )
   r   )r   ir   r   r   r      s    z+TestCMath.test_sqrt_npm.<locals>.<listcomp>$   )   r,   )rr   r   ra   rangerG   r   rX   )r$   rK   r   r   r   test_sqrt_npm   s
   
zTestCMath.test_sqrt_npmc                 C   r   r   )rr   acos_usecaserR   rb   r   r   r   	test_acos   r   zTestCMath.test_acosc                 C   r   r   )rr   r   ra   rb   r   r   r   test_acos_npm   r   zTestCMath.test_acos_npmc                 C   r   r   )rr   asin_usecaserR   rb   r   r   r   	test_asin   r   zTestCMath.test_asinc                 C   r   r   )rr   r   ra   rb   r   r   r   test_asin_npm   r   zTestCMath.test_asin_npmc                 C   r   r   )rr   atan_usecaserR   rb   r   r   r   	test_atan   r   zTestCMath.test_atanc                 C   r   r   )rr   r   ra   rb   r   r   r   test_atan_npm   r   zTestCMath.test_atan_npmc                 C   r   r   )rr   cos_usecaserR   rb   r   r   r   test_cos   r   zTestCMath.test_cosc                 C   r   r   )rr   r   ra   rb   r   r   r   test_cos_npm  r   zTestCMath.test_cos_npmc                 C   r   Neps)r4   )rr   sin_usecaserR   rb   r   r   r   test_sin  s   zTestCMath.test_sinc                 C   r   r   )rr   r   ra   rb   r   r   r   test_sin_npm
  r   zTestCMath.test_sin_npmc                 C   r   r   rr   tan_usecaserR   rb   r   r   r   test_tan  r   zTestCMath.test_tanc                 C   r   r   r   rb   r   r   r   test_tan_npm  r   zTestCMath.test_tan_npmc                 C   rs   rt   )rr   acosh_usecaserR   rb   r   r   r   
test_acosh  rd   zTestCMath.test_acoshc                 C   rs   rt   )rr   r   ra   rb   r   r   r   test_acosh_npm  rd   zTestCMath.test_acosh_npmc                 C   r   r   )rr   asinh_usecaserR   rb   r   r   r   
test_asinh  r   zTestCMath.test_asinhc                 C   r   r   )rr   r   ra   rb   r   r   r   test_asinh_npm  r   zTestCMath.test_asinh_npmc                 C   r   r   )rr   atanh_usecaserR   rb   r   r   r   
test_atanh!  r   zTestCMath.test_atanhc                 C   r   r   )rr   r   ra   rb   r   r   r   test_atanh_npm$  r   zTestCMath.test_atanh_npmc                 C   r   r   )rr   cosh_usecaserR   rb   r   r   r   	test_cosh'  r   zTestCMath.test_coshc                 C   r   r   )rr   r   ra   rb   r   r   r   test_cosh_npm*  r   zTestCMath.test_cosh_npmc                 C   r   r   )rr   sinh_usecaserR   rb   r   r   r   	test_sinh-  r   zTestCMath.test_sinhc                 C   r   r   )rr   r   ra   rb   r   r   r   test_sinh_npm0  r   zTestCMath.test_sinh_npmc                 C   r   r   rr   tanh_usecaserR   rb   r   r   r   	test_tanh3  r   zTestCMath.test_tanhc                 C   r   r   r   rb   r   r   r   test_tanh_npm6  r   zTestCMath.test_tanh_npm)r   NN)5rO   rP   rQ   __doc__rq   rr   rv   rw   ry   rz   rR   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   rp      sh    
	
rp   __main__)cmathr!   r'   r   numba.core.compilerr   r   r   
numba.corer   numba.tests.supportr   r   complex_usecasesunittestrR   enable_pyobjectra   objectr
   rS   rp   rO   mainr   r   r   r   <module>   s&    <1 <