a
    Lf,                     @   s^   d dl Zd dlmZmZmZmZmZmZm	Z	 d dl
Z
ejd ejd  d ZG dd dZdS )    N)assert_assert_equalassert_array_equalassert_almost_equalassert_array_almost_equalassert_raisesassert_allcloseZ
AllIntegerZAllFloatOc                   @   s   e Zd Zdd Zdd Zdd Zejde	e
d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d Zdd Zd d! Zd"d# Zd$d% Zd&d' ZdS )(TestPolynomialc                 C   s   t g d}tt|d tt|d t g d}tt|d tt|d t g d}tt|d ttt g d	d
 d S )N      ?      zpoly1d([1., 2., 3.])z   2
1 x + 2 x + 3      @r      zpoly1d([3., 2., 1.])   2
3 x + 2 x + 1)y[f?       @y             g"GBtk~y       @      ?z=            3      2
(1.9 + 2j) x - 3j x - 5.123 x + (2 + 1j))z    2
-3 x - 2 x - 1)nppoly1dr   reprstr)selfpqr r   X/var/www/ai-form-bot/venv/lib/python3.9/site-packages/numpy/lib/tests/test_polynomial.pytest_poly1d_str_and_repr   s"    z'TestPolynomial.test_poly1d_str_and_reprc                 C   sX   t g d}t g d}t|dd t|dd t|dd t|dd d S )	Nr   r   r   r      g      C@r   g     U@r   r   r   r   r   r   r   r   r   test_poly1d_resolution%   s    z%TestPolynomial.test_poly1d_resolutionc                 C   s  t g d}t g d}t|| t dgt ddgf t| t g d t|dt g d t g d}t g d	}t|| t g d
 t|| t g d t|| t g d t|d t g d t||t g d t||t g d t| t ddg t|dt dg tt t g dt ddgt ddgt dgf d S )N)r   r      )      @r   r         ?g      ?g      @)gUUUUUU?r   r&           r   r   r   )r          @g      ,@r)   r   )r&   r&   r&   )g       r(          @r%   )	r   r)   g      B@g      Z@g     j@g     s@g     @t@g      k@g     @T@)g      "@      (@g      0@r)   g      @)r   r+   g      @@g      D@g      A@r*   r   )r   r   r   r   g      r(   )r   r   r   integderivpolydivr#   r   r   r   test_poly1d_math-   s$    $ zTestPolynomial.test_poly1d_math	type_codeN)r0   returnc           	      C   s   t |}t jg d|d}t |}tt || tt |j| tt|d dddddd}| D ]@\}}|| }t|| |t jkrt	|t
sJ qnt|j| qnd S )Nr   r   r   )dtyper   r   r   r   )r   r   r   r   r   )r   r3   arrayr   r   Zasarraylenitemsobject_
isinstanceint)	r   r0   r3   arr   Zcomparison_dctindexrefZscalarr   r   r   test_poly1d_miscB   s    



zTestPolynomial.test_poly1d_miscc                 C   sD   t jg ddd}tt|d t jg ddd}tt|d d S )Nr   y)variablez   2
1 y + 2 y + 3lambdaz!        2
1 lambda + 2 lambda + 3r   r   r   r   )r   r   r   r   r   test_poly1d_variable_argW   s    z'TestPolynomial.test_poly1d_variable_argc                 C   sb  t tdtd tdgg d g dg dg dg}t t|g d tttg d tttg d	 tttg d
 tttg d tttg d tttddg tttddg tttddg tjd tj	ddtj	d  }tttt
|t|f d S )Nr   r   )r   r   r      r2   )r%   r!   rC   )      r   )r   iii)y        Zd;O?y        Cl@y       Cly       Zd;O)              ?y                    ?       @      ?       y      ?      @y      ?      )rF                rG   rH   y      ?      @y      ?      )rF   rI   rG   rH   )rF   rI                  @y              rF   rI   r   r   y         *   d   )r   r   polysqrtr   Z	isrealobjZiscomplexobjrandomseedZrandnconcatenate	conjugate)r   Aar   r   r   	test_polya   s     zTestPolynomial.test_polyc                 C   s   t tg dddg d S )N)r   r   r   r   )r   r   rootsr   r   r   r   
test_rootsy   s    zTestPolynomial.test_rootsc                 C   sT   t g d}d|d< tt|d t ddg}d|d< d|d< tt|d d S )N)r%   r   r   r   r   r   r   r   r   z 
0rA   r   r   r   r   r   test_str_leading_zeros|   s    z%TestPolynomial.test_str_leading_zerosc                 C   s  t g d}t ddd}t ||}g d}t dddd d	 }ttt jdgdgdd
d t j||| dd
d\}}g d}t||dd g dg dg dg}	t|	|dd t j||| d|d
d\}
}tg d|
dd g dg dg dg}t||dd t j||| d|dd\}}tg d|dd g dg dg dg}t||dd |d d t j	f }|d d t j	f }t|t ||d t j
||fdd}t j
||fdd}t|t ||d t j||t |d d t j	f  dd
d\}}t||d d df dd t||d d df dd t|	|d d d d df dd t|	|d d d d df dd t jd t jjdd}t jt |jd |dd
d\}}t| d d!d" tt | d d!d" t jt |jd |t |jd ddd#\}}t| d d!d" tt | d  t |jd d$}t jt |jd ||dd
d#\}}t| d d!d" tt | d d!d" t jt |jd ||ddd#\}}t| d d!d" tt | d% d S )&N)r   r*   r   r   r   rD   )r   r   r   r   r   r   r   rE   r   r   g      @T)degcov)r\   )gz6>W@gH?gCl?r%   )decimal)g?1w-!?)r^   gH}x@B>٬ )r_   r`   g~jt?)wr\   )g@g*:HgY8m?)g@&SH}8?)rb   g:@hs)rc   rd   gz6>W[?Zunscaled)gгY?ŏ1wſ{?)re   gv/?ŏ1w-!)rf   rg   gǺ?)Zaxis{   )r%   i'  )sizeg      ?g{Gz?)Zatol)ra   r[   r\   r*   r'   )r   r4   ZlinspaceZpolyvalaranger   
ValueErrorZpolyfitr   ZnewaxisrQ   rO   rP   normalzerosshaper   ZstdrN   meanZonesfull)r   cxr>   errweightsmr\   ZestZval0m2Zcov2valZm3Zcov3yyccro   ra   r   r   r   test_polyfit   st    .  ""
$$zTestPolynomial.test_polyfitc                 C   s   ddl m} t|d|d|dg}||d }t|d |dk | }t|d |d	k | }t|d
 |dk t|d |dk tt|jj	tj
 t|d|dg}tt|d|dgd|d|dg d S )Nr   )Decimalz4.0z3.0z2.0z1.333333333333333r   z3.9999999999999990z8.0r   z1.333333333333333333333333333r   z1.5r   )r]   r{   r   r   r   r-   r,   Z
issubdtypecoeffsr3   r7   rM   r   )r   r{   r   p2r   r   r   test_objects   s    zTestPolynomial.test_objectsc                 C   sN   t g d}| }t|jg dk  | }t|jddgk  d S )N)y              @rJ   rF   )rF   rF   rF   r   y              @rJ   )r   r   r,   r   r|   allr-   r   r   r}   r   r   r   test_complex   s
    zTestPolynomial.test_complexc                 C   s:   t g d}|jdg dd}t|jg dk  d S )N)r   r   r   r   )	   rD   rC   )k)g?gUUUUUU?gUUUUUU?g      @rD   rC   )r   r   r,   r   r|   r   r   r   r   r   test_integ_coeffs   s
    z TestPolynomial.test_integ_coeffsc                 C   s,   zt t d W n ty&   Y n0 d S )N)r   r   )r   rM   rm   rk   rW   r   r   r   test_zero_dims   s    zTestPolynomial.test_zero_dimsc                 C   s,   t dd}tt |t t | dS )z.
        Regression test for gh-5096.
        r      N)r   rj   r   rM   Zdiag)r   vr   r   r   test_poly_int_overflow   s    z%TestPolynomial.test_poly_int_overflowc                 C   sx   t g d}t |t j}t|jjt j t |t j}t|jjt j t |t j	}t|jjt j	 dS )z/
        Regression test for gh-16354.
        )r   r   r   N)
r   r4   r   ZastypeZint64r   r|   r3   Zfloat32Z	complex64)r   zr   r   r   r   test_zero_poly_dtype   s    z#TestPolynomial.test_zero_poly_dtypec                 C   sf   t g d}t g d}t|d kd t|d kd t||kd t||kd t||kd d S )Nr2   )r   r   r%   FTr"   r   r   r   r   test_poly_eq	  s    zTestPolynomial.test_poly_eqc                 C   s   t g d}t g d}t ||\}}t|jjt j t|jjt j t|| | | g d}t g d}t ||\}}t|t jsJ t|t jsJ t ||\}	}
t|	t jsJ t|
t jsJ d S )N)r   rC   rC   r   )rI   rG   y             r   r2   )r   r   r.   r   r|   r3   Z
complex128r8   )r   brT   r   r   rq   dstur   r   r   r   test_polydiv  s    zTestPolynomial.test_polydivc                 C   sh   t g d}| jd7  _t|jg d |jd  d7  < t|jg d ttt|dt d dS )	z# Coefficients should be modifiable r2   r   )r   r   r%   r   
   )r   r      r|   N)r   r   r|   r   r   AttributeErrorsetattrr4   rY   r   r   r   test_poly_coeffs_mutable#  s    z'TestPolynomial.test_poly_coeffs_mutable)__name__
__module____qualname__r    r$   r/   pytestmarkZparametrize
TYPE_CODESr   r=   rB   rU   rX   rZ   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r
      s&   
J	r
   )numpyr   Znumpy.testingr   r   r   r   r   r   r   r   	typecodesr   r
   r   r   r   r   <module>   s   $