o 6a)@s>ddlZddlmZmZmZmZmZmZm Z GdddZ dS)N)assert_ assert_equalassert_array_equalassert_almost_equalassert_array_almost_equal assert_raisesassert_allclosec@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%S)&TestPolynomialcCstgd}tt|dtt|dtgd}tt|dtt|dtgd}tt|dtttgd d dS) N?zpoly1d([1., 2., 3.])z 2 1 x + 2 x + 3@r zpoly1d([3., 2., 1.]) 2 3 x + 2 x + 1)y [f?@yg"GBtk~y@?z= 3 2 (1.9 + 2j) x - 3j x - 5.123 x + (2 + 1j))z 2 -3 x - 2 x - 1)nppoly1drreprstr)selfpqrrA/usr/lib/python3/dist-packages/numpy/lib/tests/test_polynomial.pytest_poly1d_str_and_repr s"z'TestPolynomial.test_poly1d_str_and_reprcCsXtgd}tgd}t|ddt|ddt|ddt|dddS) Nr rrrgC@r gU@rrrrrrrrrtest_poly1d_resolutions z%TestPolynomial.test_poly1d_resolutioncCstgd}tgd}t||tdgtddgft|tgdt|dtgdtgd}tgd }t||tgd t||tgd t||tgd t|d tgdt||tgdt||tgdt|tddgt|dtdgtttgdtddgtddgtdgfdS)N)r r )@r r?g?g@)gUUUUUU?r r%rr r)r @g,@r(r)r%r%r%)gr'@r$) r r(gB@gZ@gj@gs@g@t@gk@g@T@)g"@(@g0@r(g@)rr*g@@gD@gA@r)r )rrrr gr')rrrintegderivpolydivr"rrrtest_poly1d_math's$$ zTestPolynomial.test_poly1d_mathcCs\tgd}tt|tgdtt|dt|d|d|d|dfddS)Nr )r r)rr rrr )rr)r r)rrrasarrayarraylenrrrrrtest_poly1d_misc<s&zTestPolynomial.test_poly1d_misccCsDtjgddd}tt|dtjgddd}tt|ddS)Nr y)variablez 2 1 y + 2 y + 3lambdaz! 2 1 lambda + 2 lambda + 3rrrr)rrrrrtest_poly1d_variable_argBsz'TestPolynomial.test_poly1d_variable_argc Csbttdtd tdggdgdgdgdg}tt|gdtttgdtttgd tttgd tttgd tttgd tttd dgtttddgtttd dgtjdtj dd tj d}tttt |t |fdS)Nr r )rrrrr r )r$r r9)r)riii)yZd;O?yCl@yClyZd;O)?y?@?y? @y? )r=r>r?y?@y?)r=r@r>r?)r=r@@yr=r@rry*d) rrpolysqrtr isrealobj iscomplexobjrandomseedrandn concatenate conjugate)rAarrr test_polyLs  (zTestPolynomial.test_polycCsttgdddgdS)N)rrrr)rrrootsrrrr test_rootsdszTestPolynomial.test_rootscCsTtgd}d|d<tt|dtddg}d|d<d|d<tt|ddS)N)r$r r rrr rrr z 0r7r2rrrtest_str_leading_zerosgsz%TestPolynomial.test_str_leading_zeroscCstgd}tddd}t||}gd}tddddd }tttjdgdgdd d tj|||dd d \}}gd }t||ddgdgdgdg} t| |ddtj|||d|d d\} } tgd| ddgdgdgdg} t| | ddtj|||d|dd\} }tgd| ddgdgdgdg} t| |dd|ddtj f}|ddtj f}t|t||dtj ||fdd}tj ||fdd}t|t||dtj||t|ddtj fdd d \}}t||dddfddt||dddfddt| |dddddfddt| |dddddfddtj dtj j dd}tjt|jd|dd d \}}t|d d!d"tt|d d!d"tjt|jd|t|jdddd#\}}t|d d!d"tt|d t|jdd$}tjt|jd||dd d#\}}t|d d!d"tt|d d!d"tjt|jd||ddd#\}}t|d d!d"tt|d%dS)&N)rr)r rr r;)rrrrrrrr<rrg@T)degcov)rU)gz6>W@gH?gCl?r$)decimal)g ? 1w-!?)rWgH}x@B>٬)rXrYg~jt?)wrU)g@g*:HgY8m?)g@&SH}8?)r[g:@hs)r\r]gz6>W[?unscaled)gгY?ŏ1wſ{?)r_gv/?ŏ1w-!)r`ragǺ?)axis{)r$i')sizeg?g{Gz?)atol)rZrTrUr)r&)rr0linspacepolyvalaranger ValueErrorpolyfitrnewaxisrKrHrInormalzerosshaperstdrEmeanonesfull)rcxr4errweightsmrUestval0m2cov2valm3cov3yyccrprZrrr test_polyfitsst  .   "" $$zTestPolynomial.test_polyfitcCsddlm}t|d|d|dg}||d}t|d|dk|}t|d|d k|}t|d |d kt|d |d ktt|jj tj t |d|d g}t t |d|d gd|d|d gdS)Nr)Decimalz4.0z3.0z2.0z1.333333333333333rz3.9999999999999990z8.0r z1.333333333333333333333333333r z1.5r) rVrrrrr,r+ issubdtypecoeffsdtypeobject_rDr)rrrp2rrr test_objectss  zTestPolynomial.test_objectscCsNtgd}|}t|jgdk|}t|jddgkdS)N)y@rAr=)r=r=r=ry@rA)rrr+rrallr,rrrrrr test_complexs zTestPolynomial.test_complexcCs:tgd}|jdgdd}t|jgdkdS)N)r r rr ) r;r9)k)g?gUUUUUU?gUUUUUU?g@r;r9)rrr+rrrrrrrtest_integ_coeffss z TestPolynomial.test_integ_coeffscCs,z ttdWdStyYdSw)N)rr)rrDrmrirQrrrtest_zero_dimss  zTestPolynomial.test_zero_dimscCs,tdd}tt|tt|dS)z. Regression test for gh-5096. rN)rrhrrDdiag)rvrrrtest_poly_int_overflows  z%TestPolynomial.test_poly_int_overflowcCsxtgd}t|tj}t|jjtjt|tj}t|jjtjt|tj }t|jjtj dS)z/ Regression test for gh-16354. )rrrN) rr0rastypeint64rrrfloat32 complex64)rzrrrrtest_zero_poly_dtypesz#TestPolynomial.test_zero_poly_dtypecCsftgd}tgd}t|dkdt|dkdt||kdt||kdt||kddS)Nr:)rr r$FTr!rrrr test_poly_eqszTestPolynomial.test_poly_eqc Cstgd}tgd}t||\}}t|jjtjt|jjtjt||||gd}tgd}t||\}}t|tjsJJt|tjsRJt||\} } t| tjsbJt| tjsjJdS)N)r r9r9r)r@r>yrr:)rrr-rrr complex128 isinstance) rbrNrrrsdsturrrr test_polydivszTestPolynomial.test_polydivcCshtgd}|jd7_t|jgd|jdd7<t|jgdttt|dtddS) z# Coefficients should be modifiable r:r)r r r$r )r r rN)rrrrrAttributeErrorsetattrr0r2rrrtest_poly_coeffs_mutables z'TestPolynomial.test_poly_coeffs_mutableN)__name__ __module__ __qualname__rr#r.r3r8rOrRrSrrrrrrrrrrrrrrr s&  J r ) numpyr numpy.testingrrrrrrrr rrrrs$