o
    1ήcZ                     @   sd  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! eeejd jd kpFeeejd jejkZW d   n1 sQw   Y  e jd p^e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   J/tmp/pip-target-vg8gfxp4/lib/python/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                    sx   d}t jdd*  t tt j t j}|jdks |jdkr*t||j|jf W d    d S 1 s5w   Y  d S )Nz0cexp(-inf, inf) is (%f, %f), expected (+-0, +-0)r   invalidr   )r   errstatearrayr   infr   r   AssertionErrordummymsgformzr   r   r   _check_ninf_infH      "z5TestCexp.test_special_values.<locals>._check_ninf_infc                    sz   d}t jdd+  t tt jt j}t |jr!t |js+t	||j|jf W d    d S 1 s6w   Y  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      "z4TestCexp.test_special_values.<locals>._check_inf_infc                    sx   d}t jdd*  t tt j t j}|jdks |jdkr*t||j|jf W d    d S 1 s5w   Y  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\   r+   z5TestCexp.test_special_values.<locals>._check_ninf_nanc                    sz   d}t jdd+  t tt jt j}t |jr!t |j	s+t
||j|j	f W d    d S 1 s6w   Y  d S )Nz2cexp(-inf, nan) is (%f, %f), expected (+-inf, nan)r   r   )r   r!   r"   r   r#   r0   r,   r   r-   r   r$   r%   r)   r   r   _check_inf_nanf   r/   z4TestCexp.test_special_values.<locals>._check_inf_nan)r   r   r   PZERONZEROr#   r0   pi)r   r   r*   r.   r1   r2   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   r0   )r   r   r   r   r   r   test_special_values2{   s   zTestCexp.test_special_values2N)
__name__
__module____qualname__r   platform_skipr6   pytestmarkskipr7   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absangler   r   xy_ryr   r   r   r      s   
zTestClog.test_simplearmv5telzSee gh-413.r
   c                 C   sL  g }g }t jdd  t jt jgtd}tt j t j}ttt j	| W d    n1 s-w   Y  t jdd t
t 	|| W d    n1 sKw   Y  || || t jdd t jdgtd}tt j d}ttt j	| W d    n1 sw   Y  t jdd t
t 	|| W d    n1 sw   Y  || || 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 d    n	1 sw   Y  t jdd	 t
t 	|| W d    n	1 s7w   Y  || || t jdd	 t jt jdt j  gtd}W d    n	1 sfw   Y  t jdd	 t
t 	|| W d    n	1 sw   Y  || || 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 	||  ||   qW d    d S 1 sw   Y  d S )Nraise)dividedtyper   r   r         ?r   r         ?rB   r         ?)r   r!   r"   r4   r   r#   r5   r   FloatingPointErrorrC   r   appendr0   rangelenconj)r   xlylrG   rI   xayair   r   r   r6      s   





























$$zTestClog.test_special_valuesN)r8   r9   r:   r   r;   r<   r=   skipifplatformmachiner6   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   rO      Fr   )r   r   sqrt)r   rres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      t t | S N)r   ra   rV   )r(   r   r   r   r   %     z*TestCsqrt.test_simple_conjugate.<locals>.fF)r   rV   ra   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   s~   d}t t tt j t j}t jdd t |jr#t 	|j
s-t||j|j
f W d    d S 1 s8w   Y  d S )Nz3csqrt(-inf, nan) is (%f, %f), expected (nan, +-inf)r   r   )r   ra   r"   r   r#   r0   r!   r-   r   r,   r   r$   r%   r   r   r   r1   N  s   "z6TestCsqrt.test_special_values.<locals>._check_ninf_nan)r   r   ra   r3   r4   r#   r0   )r   r   r   r1   r   r   r   r6   -  s,   zTestCsqrt.test_special_valuesN)r8   r9   r:   r   rg   r;   r6   r   r   r   r   r_     s
    r_   c                   @   4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestCpowc                 C      t jdd| _d S Nr   r   r   seterrolderrr   r   r   r   setup_methode     zTestCpow.setup_methodc                 C      t jdi | j d S Nr   rl   ro   r   r   r   teardown_methodh     zTestCpow.teardown_methodc                 C   s:   t dddt jt jg}|d }t |d}t|| d S )N      ?      ?               @rA   r`   )r   r"   r#   r0   powerr   rF   r   r   r   r   k  s   zTestCpow.test_simplec                    s   t ddddt jt jg t g d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   rB   r`         @Gz?r   rB               ?r{   r`      r@   gF̛?        
hx?X?SLJ#4?4C?c                    s   g | ]
} | |  qS r   r   ).0r[   rG   rI   r   r   
<listcomp>  s    z(TestCpow.test_scalar.<locals>.<listcomp>Loop %d
err_msg	r   r"   r#   r0   listrT   rU   r   r   )r   lxp_rn_rr[   r   r   r   test_scalarq  s   	zTestCpow.test_scalarc                 C   s   t ddddt jt jg}t g d}ttt|}dddd	tt jt jtt jt jg}|| }|D ]}t|| || d
| d q4d S )Nr   rB   r`   ry   rz   r@   r}   r~   r   r   r   r   )r   rG   rI   r   r   r   r[   r   r   r   
test_array  s   	zTestCpow.test_arrayN)r8   r9   r:   rp   rt   r   r   r   r   r   r   r   ri   d  s    ri   c                   @   rh   )TestCabsc                 C   rj   rk   rl   ro   r   r   r   rp     rq   zTestCabs.setup_methodc                 C   rr   rs   rl   ro   r   r   r   rt     ru   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 )Nrv   rw   rA   g       @r`      )r   r"   r#   r0   ra   rD   r   rF   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@   rM   r   )	r   r"   r   r   rD   r   r4   r#   r0   )r   rG   r   r   r   	test_fabs  s   zTestCabs.test_fabsc           	      C   s@  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rt|ksJ  J t	||D ]\}}|||}t|||| qd S )Nc                 S   rd   re   )r   rD   rV   )ar   r   r   r     rf   z%TestCabs.test_cabs_inf_nan.<locals>.fc                 S   s   t t| |S re   )r   rD   r   )r   br   r   r   g  rf   z%TestCabs.test_cabs_inf_nan.<locals>.grM   )
rS   r   r0   check_real_valuerD   r#   r"   r   rU   zip)	r   rG   rI   r   r   rY   xiyir   r   r   r   test_cabs_inf_nan  s*   
(
zTestCabs.test_cabs_inf_nanN)r8   r9   r:   rp   rt   r   r   r   r   r   r   r   r     s    r   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   FrO   rQ   )r   ncu_argr   r5   r3   ro   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   rO         )r   r   r   r   r4   r3   r5   ro   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   rO   r   r   g      rQ   g      пr   )	r   r   r   r   r#   r5   r3   r4   r0   ro   r   r   r   r6     s    zTestCarg.test_special_valuesN)	r8   r9   r:   r   r<   r=   r>   r   r6   r   r   r   r   r     s    
r   Tc                 C   s:   t t||g}|rt| || d S t| || d S re   )r   r"   r   r   r   )r   x1y1rG   exactz1r   r   r   r     s   r   c                 C   s   t t||g}t||}t jdd" |rt| || nt| || W d    d S W d    d S 1 s9w   Y  d S rk   )r   r"   r   r!   r   r   )r   r   r   x2y2r   r   z2r   r   r   r   #  s   
"r   c                   @   s<   e Zd Zejdg dejdejejgdd Z	dS )TestSpecialComplexAVXstride)r   r   r`      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 d    d S 1 sw   Y  d S )N        rM   r   r   )r   r"   r   r0   r#   r   rN   r   rD   r!   square)r   r   r   arrabs_truesq_truer   r   r   r   -  s:   



4	$	&"z TestSpecialComplexAVX.test_arrayN
r8   r9   r:   r<   r=   parametrizer   	complex64
complex128r   r   r   r   r   r   ,  s    r   c                   @   sN   e Zd Zejdg dejdg dejdejejgdd Z	dS )	TestComplexAbsoluteAVX	arraysize)r   r`   r|   r   r            	   
                     r   r   r   r   r   r`   r|   r   r   c                 C   sH   t j||d}t j||jjd}tt |d d | |d d |  d S )NrM   )r   onesr   rN   r   rD   )r   r   r   r   r   r   r   r   r   r   H  s   (z!TestComplexAbsoluteAVX.test_arrayNr   r   r   r   r   r   G  s
    r   c                   @   sN   e Zd Zejdg dejdejejgejdg ddd Z	dS )	TestComplexAbsoluteMixedDTypesr   r   r   func)rD   r   	conjugatec              
   C   s   ddddddddd	|fd
g
}t jg d|d}tt |}|d	 }||d d | }|d	  }	||	d d | }
t|
j|jd t|
j|jd d S )N)template_id<i8)
bank_chisq<f4)bank_chisq_dofr   )chisqr   )	chisq_dofr   )
cont_chisqr   )psd_var_valr   )sg_chisqr   	mycomplex)
time_indexr   )	)
r   r   r   gW@?   r   r   rP   y      @      @iZ	 )
r   r   r   g/ݤNp@*   r   r   rP   y      @      (@is )
r   r   r   gڊeJ@r   r   r   rP   y       @      .@iN )
r   r   r   g77J@r   r   r   rP   y      @      8@iT )
r`   r   r   g2 {s@:   r   r   rP   y      4@      5@i{ )
r|   r   r   gar@4   r   r   rP   y      (@     A@i )
r   r   r   g=,ԚC@   r   r   g/EH]"@y      "@      D@ih )
r   r   r   g+~5S@r   r   r   rP   y      <@     F@i+ )
r   r   r   gmoa@   r   r   g1˞%@y      &@      N@ic rM   r   )r   r"   getattrcopyr   r   r   )r   r   r   r   rN   vecmyfuncr   r   r   hr   r   r   r   S  s   
	

z)TestComplexAbsoluteMixedDTypes.test_arrayNr   r   r   r   r   r   R  s
    r   )T)(sysr]   r<   numpyr   numpy.core._multiarray_umathcore_multiarray_umathr   numpy.testingr   r   r   r   r   r!   r   r   r#   r   rC   r4   r5   functions_seem_flaky
startswithxfail_complex_testsr=   r\   r;   r   r?   r_   ri   r   r   r   r   r   r   r   r   r   r   r   <module>   s6    d P5>
D
	