B Z6d?d@Z7dAdBZ8dCdDZ9e:dEkredS)GzTest inter-conversion of different polynomial classes. This tests the convert and cast methods of all the polynomial classes. )divisionabsolute_importprint_functionN)Number) PolynomialLegendre ChebyshevLaguerreHermiteHermiteE)assert_almost_equal assert_raises assert_equalassert_run_module_suite)longccsNx2tD]*}x$tD]}t||fVt||fVqWqWxtD]}t|fVt|fVt|fVt|fVt|fVt|fVt |fVt |fVt |fVt |fVt |fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVt|fVq                            r4cCsly>tt|j|jktt|j|jkt|j|jWn(tk rfd||ff}t|YnXdS)NzResult: %s Target: %s)rnpalldomainwindowr coefAssertionError)p1p2msgr2r2r3assert_poly_almost_equalAs r?c Cstddd}td}|jtdd}|jtdd}||||d}|jtdd}|jtdd}|j|||d} t| j|t| j|t| |||dS) Nr ))g?)r8r9)Zkindr8r9)r6linspacerandomr8r9Zconvertr ) r/r0xr:d1w1r<d2w2r=r2r2r3rPs  rc Cstddd}td}|jtdd}|jtdd}||||d}|jtdd}|jtdd}|j|||d} t| j|t| j|t| |||dS)Nrr@rA)rB)rCg?)r8r9)r6rDrEr8r9castr ) r/r0rFr:rGrHr<rIrJr=r2r2r3ras  rcCsr|jtdd}|jtdd}t|d|dd}|j||d}t|j|t|j|t|||dS)N)rCg?rr@ )r8r9)r8rEr9r6rDZidentityrr )r1dwrFpr2r2r3rws  rcCsh|jtdd}|jtdd}|jd||d}t|j|t|j|t|jdgddgdS)N)rCg?)r8r9rr@)r8rEr9basisrr:)r1rMrNrOr2r2r3rs   rcCs|jtdd}|jtdd}td}|j|||d}t|t|t|j|t|j|t||dtj}tj}tj |||d}t|j dddS)N)rCg?)rP)r8r9rr@) r8rEr9 fromrootsrdegreelenr rrKr:)r1rMrNrr<ZpdomZpwinr=r2r2r3rs  rc Csdd}tdd}||}|||d}t|jddgt|||t|d|jtdd}|jtdd}|j||d||d}t|||t|j|t|j||j||ddd dg||d}t|||t|j|t|j||||dg}t|j|jt|j|j|||ddd dgg}t|j|jt|j|jt |}|t|j d}d|ddd <||ddd |ddd d}|j||d|d } |j||ddd dg|d } t||| |t| || |dS) NcSs||d|dS)Nr@rCr2)rFr2r2r3fszcheck_fit..frrB)rCg?)r8r9r@rC)rN) r6rDZfitr r8rrTrEr9Z zeros_likeshape) r1rWrFyrOrMrNzr<r=p3r2r2r3rs>      "rcCs|dddgddgddgd}|dddgddgddgd}|dddgddgddgd}|dddgddgddgd}t||kt||k t||k t||k dS)Nr@rCrBr)r8r9)r)r1r<r=r[p4r2r2r3rs rcCs|dddgddgddgd}|dddgddgddgd}|dddgddgddgd}|dddgddgddgd}t||k t||kt||kt||kdS)Nr@rCrBr)r8r9)r)r1r<r=r[r\r2r2r3rs  rcCs*ttdd}ttdd}||}||}||}t|||t|||t|||t|t||tt|||t|t||tt|||tttj ||dg|j ddtttj ||dg|j dd|t krtttj |t dgntttj |t dgdS)N)g?)rBrr@)r8)r9)listrEr?tupler6arrayr TypeErroropaddr8r9rr)r1c1c2r<r=r[r2r2r3rs"   rcCs2ttdd}ttdd}||}||}||}t||| t|||t||| t|t||tt||| t|t||tt||| tttj ||dg|j ddtttj ||dg|j dd|t krtttj |t dgntttj |t dgdS)N)r]g?)rBrr@)r8)r9)r^rEr?r_r6r`r rarbsubr8r9rr)r1rdrer<r=r[r2r2r3rs"   rcCsZttdd}ttdd}||}||}||}t|||t|||t|||t|t||tt|||t|t||tt|||t|d||dgtd|||dgtttj ||dg|j ddtttj ||dg|j dd|t kr@tttj |t dgntttj |t dgdS) N)r]g?)rBrCrr@)r8)r9)r^rEr?r_r6r`r rarbmulr8r9rr)r1rdrer<r=r[r2r2r3r s&   rc Csvttdd}ttdd}ttdd}||}||}||}|||}t|j}t|||t|||t|||t|t||tt|||t|t||tt|||td||dgt|dd|ttt j ||dg|j ddttt j ||dg|j dd |t kr\ttt j |tdgnttt j |t dgdS) N)r]g?)rB)rCrCrr@)r8)r9)r^rEr:r?r_r6r`r rarbfloordivr8r9rr) r1rdrec3r<r=r[r\c4r2r2r3r"s0   rcCsR|dddg}|d}xNtjD]D}t|trt|tr8q|d}tt|||tt tj||qWxs*   $ r c Csxttdd}ttdd}ttdd}||}||}||}|||}t|j}t|||t|||t|||t|t||tt|||t|t||tt|||td||dgt|d|dgttt j ||dg|j ddttt j ||dg|j dd |t kr^ttt j |tdgnttt j |t dgdS) N)r]g?)rB)rCrCrr@)r8)r9)r^rEr:r?r_r6r`r rarbmodr8r9rr) r1rdrerir<r=r[r\rjr2r2r3r!Ys,     r!c Cs.ttdd}ttdd}ttdd}||}||}||}|||}t|j}t||\} } t| |t| |t||\} } t| |t| |t||\} } t| |t| |t|t|\} } t| |t| |tt||\} } t| |t| |t|t|\} } t| |t| |tt||\} } t| |t| |t|d\} } t| d|t| |dgtd|\} } t| |dgt| |dgtt t||dg|j ddtt t||dg|j dd |t krtt t|t dgntt t|t dgdS) N)r]g?)rB)rCrCrr@)r8)r9)r^rEr:divmodr?r_r6r`r rar8r9rr) r1rdrerir<r=r[r\rjZquoZremr2r2r3r"tsP                 r"cCsx|jtdd}|jtdd}ttd}t|j|||d}t||t||}t||dS)N)rCg?)rP)r8r9)r8rEr9r6sortrSrootsr )r1rMrNtgtresr2r2r3r&s r&cCs|d}t|ddS)NrP)rQrrT)r1rOr2r2r3r)s r)cCs^|d}|}t||kt||k t|j|jk t|j|jk t|j|jk dS)NrP)rQcopyrr:r8r9)r1r<r=r2r2r3r*s   r*cCst}||dddg}||}||d}t||ddddgt||dddddg||dddg}||jdd}||jdddgd}t||ddddgt||dddddg||dddg}||jdd }||jddd }t||d dddgt||dd dddgd|j}|j|dddg|d }||}||d}t||ddddgt||dddddgdS) NrC rrBr]r@)k)Zlbndi)r8)rrKintegr?r8)r1PZp0r<r=rMr2r2r3r$s, r$cCs|jtdd}|jtdd}|dddg||d}|jdddgd}|jddgd}t|dj|jt|dj|j|dddg}|jdddgd}|jddgd}t|dj|jt|dj|jdS)N)rCg?r@rCrB)r8r9)r})r8rEr9r~r Zderivr:)r1rMrNr<r=r[r2r2r3r%sr%cCs|jtdd}|jtdd}|dddg||d}t|d|dd}||}|d\}}t||t||tddd}||}|jdddgd \}}t||t||dS) N)rCg?r@rCrB)r8r9r)r8)r8rEr9r6rDr )r1rMrNrOZxtgtZytgtZxresZyresr2r2r3r's   r'cCs|jtdd}|jtdd}|dg||d}|dddg||d}x&tdD]}t|||||}qRW|dg}|dddg}x&tdD]}t|||||}qWtttj|dtttj|d dS) N)rCg?r@)r8r9rCrBrPg?rR) r8rEr9ranger?r ValueErrorrbpow)r1rMrNrxZtstir2r2r3r#s   r#cCs^t}|j}t|d|dd}||dddg}d|dd|}||}t||dS)Nrr@rLrCrB)rr8r6rDrKr )r1rrMrFrOrxryr2r2r3rsrcCs~|dddg}tt|jdtt|jdtt|ddtt|ddtt|ddtt|dddS)Nr@rCrBg?rRr)r rZcutdegrrU)r1rOr2r2r3r+sr+cCs~|dddg}tt|jdtt|jdtt|ddtt|ddtt|ddtt|dddS)Nr@rCrBg?rr])r rtruncaterrU)r1rOr2r2r3r,%sr,cCsdddddg}||}t|j|ddt|dj|ddt|dj|dddS) Nr@gư>g-q=rrBg|=rCgh㈵>)rZtrimr:)r1crOr2r2r3r-/s  r-cCs`|j}|j}|dg||d}tddg|d|d}|dg||d}tddg|dS)Nr@)r8r9rrC)r8r9r Zmapparms)r1rMrNrOr2r2r3r(7s r(cCs<|dddg}td}tttj||tttj||dS)Nr@rCrB)r6Zonesr rarc)r1rOrFr2r2r3r.Cs r.__main__)r5);__doc__Z __future__rrroperatorrbZnumbersrZnumpyr6Znumpy.polynomialrrrr r r Z numpy.testingr r rrrZ numpy.compatrrr4rEr?rrrrrrrrrrrrr r!r"r&r)r*r$r%r'r#rr+r,r-r(r.__name__r2r2r2r3sT   %   ,  -