a :jg,@s^ddlZddlmZmZmZmZmZmZm Z ddl Z ej dej ddZ GdddZ dS)N)assert_ assert_equalassert_array_equalassert_almost_equalassert_array_almost_equal assert_raisesassert_allcloseZ AllIntegerZAllFloatOc@seZdZddZddZddZejde e dd d d Z d d Z ddZ ddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdS)(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)selfpqrrI/usr/local/lib/python3.9/site-packages/numpy/lib/tests/test_polynomial.pytest_poly1d_str_and_reprs"z'TestPolynomial.test_poly1d_str_and_reprcCsXtgd}tgd}t|ddt|ddt|ddt|dddS) Nr rrrgC@r gU@rrrrrrrrrtest_poly1d_resolution%s 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_math type_codeN)r0returnc Cst|}tjgd|d}t|}tt||tt|j|tt|ddddddd}|D]@\}}||}t|||tjkrt |t sJqnt|j|qndS)Nrr r)dtyper rrr)rrrr r) rr3arrayrrZasarraylenitemsobject_ isinstanceint) rr0r3arrZcomparison_dctindexrefZscalarrrrtest_poly1d_miscBs    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_argWsz'TestPolynomial.test_poly1d_variable_argc Csbttdtd tdggdgdgdgdg}tt|gdtttgdtttgd tttgd tttgd tttgd tttd dgtttddgtttd dgtjdtj dd tj d}tttt |t |fdS)Nrr )rrrr2)r%r!rC)r)riii)yZd;O?yCl@yClyZd;O)?y?@?y? @y? )rFrGrHy?@y?)rFrIrGrH)rFrI@yrFrIrry*d) rrpolysqrtrZ isrealobjZ iscomplexobjrandomseedZrandn concatenate conjugate)rAarrr test_polyas  zTestPolynomial.test_polycCsttgdddgdS)N)rrrr)rrrootsrrrr test_rootsyszTestPolynomial.test_rootscCsTtgd}d|d<tt|dtddg}d|d<d|d<tt|ddS)N)r%rr rrrrrr z 0rArrrrrtest_str_leading_zeros|sz%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 rD)rrrrrrrrErrg@T)degcov)r\)gz6>W@gH?gCl?r%)decimal)g ? 1w-!?)r^gH}x@B>٬)r_r`g~jt?)wr\)g@g*:HgY8m?)g@&SH}8?)rbg:@hs)rcrdgz6>W[?Zunscaled)gгY?ŏ1wſ{?)regv/?ŏ1w-!)rfrggǺ?)Zaxis{)r%i')sizeg?g{Gz?)Zatol)rar[r\r*r')rr4ZlinspaceZpolyvalaranger ValueErrorZpolyfitrZnewaxisrQrOrPnormalzerosshaperZstdrNmeanZonesfull)rcxr>errweightsmr\ZestZval0m2Zcov2valZm3Zcov3yyccrorarrr test_polyfitst  .   "" $$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.0rz1.333333333333333333333333333r z1.5r) r]r{rrrr-r,Z issubdtypecoeffsr3r7rMr)rr{rp2rrr test_objectss  zTestPolynomial.test_objectscCsNtgd}|}t|jgdk|}t|jddgkdS)N)y@rJrF)rFrFrFry@rJ)rrr,rr|allr-rrr}rrr test_complexs zTestPolynomial.test_complexcCs:tgd}|jdgdd}t|jgdkdS)N)rr rr) rDrC)k)g?gUUUUUU?gUUUUUU?g@rDrC)rrr,rr|rrrrrtest_integ_coeffss z TestPolynomial.test_integ_coeffscCs,zttdWnty&Yn0dS)N)rr)rrMrmrkrWrrrtest_zero_dimss zTestPolynomial.test_zero_dimscCs,tdd}tt|tt|dS)z. Regression test for gh-5096. rN)rrjrrMZdiag)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) rr4rZastypeZint64rr|r3Zfloat32Z complex64)rzrrrrtest_zero_poly_dtypesz#TestPolynomial.test_zero_poly_dtypecCsftgd}tgd}t|dkdt|dkdt||kdt||kdt||kddS)Nr2)rr r%FTr"rrrr test_poly_eq szTestPolynomial.test_poly_eqc Cstgd}tgd}t||\}}t|jjtjt|jjtjt||||gd}tgd}t||\}}t|tjsJt|tjsJt||\} } t| tjsJt| tjsJdS)N)r rCrCr)rIrGyrr2)rrr.rr|r3Z complex128r8) rbrTrrrqdsturrrr test_polydivszTestPolynomial.test_polydivcCshtgd}|jd7_t|jgd|jdd7<t|jgdttt|dtddS) z# Coefficients should be modifiable r2r)r rr%r )r rr|N)rrr|rrAttributeErrorsetattrr4rYrrrtest_poly_coeffs_mutable#s z'TestPolynomial.test_poly_coeffs_mutable)__name__ __module__ __qualname__r r$r/pytestmarkZ parametrize TYPE_CODESrr=rBrUrXrZrzr~rrrrrrrrrrrrr s&   J r )numpyrZ numpy.testingrrrrrrrr typecodesrr rrrrs$