U
    #cZ                  	   @   sP  d dl Z d dlZd dlZd dlZd dlm  mZ d dl	m
Z
mZmZmZmZ ejdd8 eeejd jd kpeeejd jejkZW 5 Q R X e jd peZejjeddZG dd	 d	ZG d
d dZG dd dZG dd dZ G dd dZ!G dd dZ"dddZ#d ddZ$G dd dZ%G dd dZ&G dd dZ'dS )!    N)assert_raisesassert_equalassert_array_equalassert_almost_equalassert_array_max_ulpignore)alllinuxzInadequate C99 complex supportreasonc                   @   s6   e Zd Zdd Zedd Zejjdddd Z	d	S )
TestCexpc                 C   sz   t }tj}||ddtddd ||ddtdtdd tdttdtd }||dd|j|jd d S )N   r   F)check_complex_valuenpexpcossincomplexrealimag)selfcheckfref r   G/tmp/pip-unpacked-wheel-b2rbor69/numpy/core/tests/test_umath_complex.pytest_simple!   s     zTestCexp.test_simplec                    s  t }tj | tjdddd | tjdddd | dtjtjtj | dtjtjtj | dtjtjtj | tjdtjd | tj dtjtj | tj dtj tjtj | tjdtjtj | tjdtj tj tj  fdd}|d   fdd	}|d   fd
d}|d   fdd}|d  | tjdtjtj | tjdtjtj | tjtjtjtj | tjtj tjtj | tjtjtjtj d S )Nr   r   F      ?c              	      sb   d}t jddH  t tt j t j}|jdks@|jdkrTt||j|jf W 5 Q R X d S )Nz0cexp(-inf, inf) is (%f, %f), expected (+-0, +-0)r   invalidr   )r   errstatearrayr   infr   r   AssertionErrordummyZmsgformzr   r   r   _check_ninf_infH   s
    z5TestCexp.test_special_values.<locals>._check_ninf_infc              	      sd   d}t jddJ  t tt jt j}t |jrBt |jsVt	||j|jf W 5 Q R X d S )Nz1cexp(inf, inf) is (%f, %f), expected (+-inf, nan)r   r   )
r   r!   r"   r   r#   isinfr   isnanr   r$   r%   r(   r   r   _check_inf_infR   s
    z4TestCexp.test_special_values.<locals>._check_inf_infc              	      sb   d}t jddH  t tt j t j}|jdks@|jdkrTt||j|jf W 5 Q R X d S )Nz0cexp(-inf, nan) is (%f, %f), expected (+-0, +-0)r   r   r   )	r   r!   r"   r   r#   nanr   r   r$   r%   r(   r   r   _check_ninf_nan\   s
    z5TestCexp.test_special_values.<locals>._check_ninf_nanc              	      sd   d}t jddJ  t tt jt j}t |jrBt |j	sVt
||j|j	f W 5 Q R X d S )Nz2cexp(-inf, nan) is (%f, %f), expected (+-inf, nan)r   r   )r   r!   r"   r   r#   r-   r*   r   r+   r   r$   r%   r(   r   r   _check_inf_nanf   s
    z4TestCexp.test_special_values.<locals>._check_inf_nan)r   r   r   PZERONZEROr#   r-   pi)r   r   r)   r,   r.   r/   r   r(   r   test_special_values+   s2    zTestCexp.test_special_valuesz)cexp(nan + 0I) is wrong on most platformsr
   c                 C   s"   t }tj}||tjdtjd d S )Nr   )r   r   r   r-   )r   r   r   r   r   r   test_special_values2{   s    zTestCexp.test_special_values2N)
__name__
__module____qualname__r   platform_skipr3   pytestmarkskipr4   r   r   r   r   r       s
   

Or   c                   @   s8   e Zd Zdd Zeejje	 dkdddd Z
dS )	TestClogc                 C   sD   t ddg}t t |dt |  }t |}t|| d S )N      ?              ?       @              ?)r   r"   logabsZangler   r   xZy_ryr   r   r   r      s    
zTestClog.test_simpleZarmv5telzSee gh-413.r
   c              	   C   s  g }g }t jdd6 t jt jgtd}tt j t j}ttt j	| W 5 Q R X t jdd t
t 	|| W 5 Q R X || || t jdd2 t jdgtd}tt j d}ttt j	| W 5 Q R X t jdd t
t 	|| W 5 Q R X || || t jtdt jgtd}tt jdt j }t
t 	|| || || t jtdt jgtd}t
t 	|| || || t jdd	, t jtd
t jgtd}tt jt j}W 5 Q R X t jdd	 t
t 	|| W 5 Q R X || || t jdd	" t jt jdt j  gtd}W 5 Q R X t jdd	 t
t 	|| W 5 Q R X || || t jt j d gtd}tt jt j}t
t 	|| || || t jt jd gtd}tt jd}t
t 	|| || || t jtt j t jgtd}tt jdt j }t
t 	|| || || t jtt jt jgtd}tt jdt j }t
t 	|| || || t jtt jt jgtd}tt jt j}t
t 	|| || || t jtt j t jgtd}t
t 	|| || || t jtt jdgtd}tt jt j}t
t 	|| || || t jtt jt jgtd}tt jt j}t
t 	|| || || t jtt jt jgtd}tt jt j}t
t 	|| || || t j|td}t j|td}t jdd: tt|D ]&}t
t 	||  ||   qVW 5 Q R X d S )Nraise)dividedtyper   r   r         ?r   r         ?r?   r         ?)r   r!   r"   r1   r   r#   r2   r   FloatingPointErrorr@   r   appendr-   rangelenconj)r   ZxlZylrC   rD   xaZyair   r   r   r3      s    









&



















zTestClog.test_special_valuesN)r5   r6   r7   r   r8   r9   r:   skipifplatformmachiner3   r   r   r   r   r<      s   r<   c                   @   s(   e Zd Zdd Zdd Zedd ZdS )	TestCsqrtc                 C   sN   t tjdddd dtd }|}t tjdd||d t tjdddd d S )Nr   r   rI      Fr   )r   r   sqrt)r   ZrresZiresr   r   r   r     s
    zTestCsqrt.test_simplec                 C   s8   t t tdd}dd }t|dd|j|jd d S )Nr   c                 S   s   t t | S N)r   rX   rP   )r'   r   r   r   r   %  s    z*TestCsqrt.test_simple_conjugate.<locals>.fF)r   rP   rX   r   r   r   r   )r   r   r   r   r   r   test_simple_conjugate"  s    zTestCsqrt.test_simple_conjugatec                 C   s  t }tj}||tjddd ||tjddd ||dtjtjtj ||dtjtjtj ||tjtjtjtj ||tjtjtjtj ||tjtjtjtj ||tj tjtjtj ||tj tjtjtj ||dtjtjtj ||dtjtjtj ||dtjtjtj ||tj dtjtj ||tjdtjtj dd }|d  ||tjtjtjtj ||tjdtjtj ||tjdtjtj ||tjtjtjtj d S )Nr   r   r   c              	   S   sh   d}t t tt j t j}t jdd2 t |jrFt 	|j
sZt||j|j
f W 5 Q R X d S )Nz3csqrt(-inf, nan) is (%f, %f), expected (nan, +-inf)r   r   )r   rX   r"   r   r#   r-   r!   r+   r   r*   r   r$   r%   r   r   r   r.   N  s
    z6TestCsqrt.test_special_values.<locals>._check_ninf_nan)r   r   rX   r0   r1   r#   r-   )r   r   r   r.   r   r   r   r3   -  s,    zTestCsqrt.test_special_valuesN)r5   r6   r7   r   rZ   r8   r3   r   r   r   r   rV     s   rV   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestCpowc                 C   s   t jdd| _d S Nr   r   r   ZseterrZolderrr   r   r   r   setup_methode  s    zTestCpow.setup_methodc                 C   s   t jf | j d S rY   r]   r^   r   r   r   teardown_methodh  s    zTestCpow.teardown_methodc                 C   s:   t dddt jt jg}|d }t |d}t|| d S )N      ?      ?               @r>   rW   )r   r"   r#   r-   powerr   rB   r   r   r   r   k  s    zTestCpow.test_simplec                    s   t ddddt jt jg t ddddddgttt }ddd	d
tt jt jtt jt jg} fdd|D }|D ]}t|| || d| d q|d S )Nr   r?   rW         @Gz?            ?   r=   gF̛?        
hx?X?SLJ#4?4C?c                    s   g | ]} | |  qS r   r   ).0rR   rC   rD   r   r   
<listcomp>  s     z(TestCpow.test_scalar.<locals>.<listcomp>Loop %d
err_msg	r   r"   r#   r-   listrN   rO   r   r   )r   lxp_rn_rrR   r   rk   r   test_scalarq  s    	zTestCpow.test_scalarc                 C   s   t ddddt jt jg}t ddddddg}ttt|}ddd	d
tt jt jtt jt jg}|| }|D ]}t|| || d| d qpd S )Nr   r?   rW   rd   re   rf   r=   rg   rh   ri   rm   rn   rp   )r   rC   rD   rr   rs   rt   rR   r   r   r   
test_array  s    	zTestCpow.test_arrayN)r5   r6   r7   r_   r`   r   ru   rv   r   r   r   r   r[   d  s
   r[   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestCabsc                 C   s   t jdd| _d S r\   r]   r^   r   r   r   r_     s    zTestCabs.setup_methodc                 C   s   t jf | j d S rY   r]   r^   r   r   r   r`     s    zTestCabs.teardown_methodc                 C   sT   t dddt jt jg}t t ddt dt jt jg}t |}t|| d S )Nra   rb   r>   g       @rW      )r   r"   r#   r-   rX   rA   r   rB   r   r   r   r     s    $
zTestCabs.test_simplec                 C   s   t jdgtd}tt |t | t jtdt jgtd}tt |t | t jtt jt jgtd}tt |t | t jtt jt jgtd}tt |t | d S )Nr=   rG   r   )	r   r"   r   r   rA   r   r1   r#   r-   )r   rC   r   r   r   	test_fabs  s    zTestCabs.test_fabsc           	      C   sD  g g  }}| tj | tj ttjtjtjtj | tj | tj  ttjtj tjtj | tj | tj ttjtjtjtj | tj  | tj ttjtj tjtj dd }dd }tj|td}t|t|  krt|ksn t	t
||D ]"\}}|||}t|||| qd S )Nc                 S   s   t t | S rY   )r   rA   rP   )ar   r   r   r     s    z%TestCabs.test_cabs_inf_nan.<locals>.fc                 S   s   t t| |S rY   )r   rA   r   )rz   br   r   r   g  s    z%TestCabs.test_cabs_inf_nan.<locals>.grG   )rM   r   r-   check_real_valuerA   r#   r"   r   rO   r$   zip)	r   rC   rD   r   r|   rQ   xiyir   r   r   r   test_cabs_inf_nan  s(    
*
zTestCabs.test_cabs_inf_nanN)r5   r6   r7   r_   r`   r   ry   r   r   r   r   r   rw     s
   rw   c                   @   s2   e Zd Zdd Zejjdddd Zdd Zd	S )
TestCargc                 C   s\   t tjdddd t tjdddtj d t tjdddtj d t tjtjtjtj d S )Nr   r   FrI   rK   )r}   ncu_argr   r2   r0   r^   r   r   r   r     s    zTestCarg.test_simplez;Complex arithmetic with signed zero fails on most platformsr
   c                 C   s$  t tjtjtjtjd t tjtjtjtj d t tjtjtjtj t tjtjtjtj t tjdtjtjd t tjdtjtjd t tjdtjtjd t tjdtjtj d t tjtjddtj d t tjtjddtj d t tjtjddtj d t tjtjddtj d d S )NFr   r   rI         )r}   r   r   r   r1   r0   r2   r^   r   r   r   	test_zero  s    zTestCarg.test_zeroc                 C   sl  t tjtj dtjd t tjtj dtj d t tjtjdtjd t tjtjdtjd t tjdtjdtj d t tjdtj dtj d t tjtj tjdtj d t tjtj tj dtj d t tjtjtjdtj d t tjtjtj d	tj d t tjtjd
tjd t tjd
tjtjd t tjtjtjtjd t tjtjtjtjd d S )Nr   Fr   rI   r   r   g      rK   g      пr   )	r}   r   r   r   r#   r2   r0   r1   r-   r^   r   r   r   r3     s     zTestCarg.test_special_valuesN)	r5   r6   r7   r   r9   r:   r;   r   r3   r   r   r   r   r     s   
r   Tc                 C   s8   t t||g}|r&t| || nt| || d S rY   )r   r"   r   r   r   )r   x1y1rC   exactz1r   r   r   r}     s    r}   c              	   C   sZ   t t||g}t||}t jdd( |r>t| || nt| || W 5 Q R X d S r\   )r   r"   r   r!   r   r   )r   r   r   Zx2y2r   r   Zz2r   r   r   r   #  s    
r   c                	   @   sD   e Zd Zejdddddddgejdejejgd	d
 Z	dS )TestSpecialComplexAVXstrider   r   rW      astypec                 C   s~  t jtt jt jtt jt jtt jt jtt jt jtdt jtt jdtddtdt jtt jdg	|d}t jt jt jt jt jt jt jdt jt jg	|jjd}t jtt jt jtt jt jtt jt jtt jt jtt j t jtt jt jtddtt jt jtt jt jg	|d}tt |d d | |d d |  t j	dd* tt 
|d d | |d d |  W 5 Q R X d S )N        rG   r   r   )r   r"   r   r-   r#   r   rH   r   rA   r!   square)r   r   r   arrabs_trueZsq_truer   r   r   rv   -  s8    



	4	$z TestSpecialComplexAVX.test_arrayN
r5   r6   r7   r9   r:   Zparametrizer   Z	complex64Z
complex128rv   r   r   r   r   r   ,  s   r   c                   @   sv   e Zd Zejddddddddd	d
dddddddgejdddddddddgejdejejgdd Z	dS )TestComplexAbsoluteAVX	arraysizer   rW   rf   r   rx            	   
                     r   r   r   r   r   c                 C   sH   t j||d}t j||jjd}tt |d d | |d d |  d S )NrG   )r   Zonesr   rH   r   rA   )r   r   r   r   r   r   r   r   r   rv   H  s    z!TestComplexAbsoluteAVX.test_arrayNr   r   r   r   r   r   G  s   ,r   c                   @   s\   e Zd Zejddddddddd	gejd
ejejgejddddgdd Z	dS )TestComplexAbsoluteMixedDTypesr   r   r   r   r   r   rW   rf   r   r   funcrA   r   	conjugatec              
   C   s   ddddddddd	|fd
g
}t jdddddddddg	|d}tt |}|d	 }||d d | }|d	  }	||	d d | }
t|
j|jd t|
j|jd d S )N)Ztemplate_id<i8)Z
bank_chisq<f4)Zbank_chisq_dofr   )Zchisqr   )Z	chisq_dofr   )Z
cont_chisqr   )Zpsd_var_valr   )Zsg_chisqr   Z	mycomplex)Z
time_indexr   )
r   r   r   gW@?   r   r   rJ   y      @      @iZ	 )
r   r   r   g/ݤNp@*   r   r   rJ   y      @      (@is )
r   r   r   gڊeJ@r   r   r   rJ   y       @      .@iN )
r   r   r   g77J@r   r   r   rJ   y      @      8@iT )
rW   r   r   g2 {s@:   r   r   rJ   y      4@      5@i{ )
rf   r   r   gar@4   r   r   rJ   y      (@     A@i )
r   r   r   g=,ԚC@   r   r   g/EH]"@y      "@      D@ih )
r   r   r   g+~5S@r   r   r   rJ   y      <@     F@i+ )
rx   r   r   gmoa@   r   r   g1˞%@y      &@      N@ic rG   r   )r   r"   getattrcopyr   r   r   )r   r   r   r   rH   ZvecZmyfuncrz   r|   r{   hr   r   r   rv   S  s<         	

z)TestComplexAbsoluteMixedDTypes.test_arrayNr   r   r   r   r   r   R  s   r   )T)T)(sysrT   r9   Znumpyr   Znumpy.core._multiarray_umathcoreZ_multiarray_umathr   Znumpy.testingr   r   r   r   r   r!   r   r   r#   r   r@   r1   r2   Zfunctions_seem_flaky
startswithZxfail_complex_testsr:   rS   r8   r   r<   rV   r[   rw   r   r}   r   r   r   r   r   r   r   r   <module>   s2   d P5>D

	