σ 2ΔΘ[c@`sdZddlmZmZmZddlZddlZddlmZm Z ddl j j Z ddl Zddl mZmZmZmZmZddl mZmZmZmZmZmZdd d d d d ddddddddgZddlmZdddddgZeeZeddd„Zded „Z d!d"„Z!d#„Z"d!d$„Z#d!d%„Z$e$Z%d&d!ed'„Z&e&Z'd!ed!ed(„Z(d!ed)„Z)d!ed*„Z*dd!ed+„Z+dd!ed,„Z,d!ed-„Z-d!d.„Z.dS(/sΜMiscellaneous functions for testing masked arrays and subclasses :author: Pierre Gerard-Marchant :contact: pierregm_at_uga_dot_edu :version: $Id: testutils.py 3529 2007-11-13 08:01:14Z jarrod.millman $ i(tdivisiontabsolute_importtprint_functionN(tndarraytfloat_(tassert_tassert_allclosetassert_array_almost_equal_nulpt assert_raisest build_err_msgi(tmask_ortgetmaskt masked_arraytnomasktmaskedtfilledtalmosttapproxtassert_almost_equaltassert_array_almost_equaltassert_array_approx_equaltassert_array_comparetassert_array_equaltassert_array_lesst assert_closet assert_equaltassert_equal_recordstassert_mask_equaltassert_not_equaltfail_if_array_equal(tTestCaseRRRRRgρh㈡ψδ>g:Œ0βŽyE>c C`sϋtt|ƒt|ƒƒ}t|ƒ}t|ƒ}|jjdksW|jjdkrmtj||ƒjƒStt|dt d|ƒ|ƒj t ƒ}tt|dt d|ƒdƒj t ƒ} tj t j|| ƒ||t j| ƒƒ} | jƒS(s† Returns true if all components of a and b are equal to given tolerances. If fill_value is True, masked values considered equal. Otherwise, masked values are considered unequal. The relative error rtol should be positive and << 1.0 The absolute error atol comes into play for those elements of b that are very small or zero; it says how small a must be also. tOtcopytmaski(R R RtdtypetchartnptequaltravelR tFalsetastypeRt less_equaltumathtabsolute( tatbt fill_valuetrtoltatoltmtd1td2txtytd((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyR+s   $**0ic C`sυtt|ƒt|ƒƒ}t|ƒ}t|ƒ}|jjdksW|jjdkrmtj||ƒjƒStt|dt d|ƒ|ƒj t ƒ}tt|dt d|ƒdƒj t ƒ}tj tj ||ƒ|ƒd| k} | jƒS(s³ Returns True if a and b are equal up to decimal places. If fill_value is True, masked values considered equal. Otherwise, masked values are considered unequal. RR R!ig$@(R R RR"R#R$R%R&R R'R(Rtaroundtabs( R,R-tdecimalR.R1R2R3R4R5R6((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRAs  $***tcC`s_tt|ƒt|ƒ|ƒx<tt|ƒƒD](}t||||d||fƒq/WdS(s; Asserts the equality of two non-array sequences. s item=%r %sN(Rtlentrange(tactualtdesiredterr_msgtk((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyt_assert_equal_on_sequencesTs&cC`s“t|j|jƒxy|jjD]k}tj||ƒtj||ƒ}}|tk r |tk r ttj||ƒtj||ƒƒq q WdS(sI Asserts that two records are equal. Pretty crude for now. N(RR"tnamestoperatortgetitemR(R,R-tftaftbf((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyR_s %,cC`sBt|tƒr½t|tƒs9ttt|ƒƒƒ‚ntt|ƒt|ƒ|ƒxa|jƒD]S\}}||kr“td||fƒ‚nt||||d||fƒqbWdSt|tt fƒrϊt|tt fƒrϊt ||ddƒSt|t ƒpt|t ƒsLt ||g|ƒ}||ksHt|ƒ‚ndS|t krd|t k s||t kr¬|t k r¬t ||g|dddd ƒ}t|ƒ‚ntj|d td tƒ}tj|d td tƒ}|j|j}}|jd kr2|jd kr2t |jƒ|jƒddƒSt|||ƒS(s, Asserts that two items are equal. s %s not in %ss key=%r %sNR?R:theaderRBR4R5R tsuboktS(R4R5(t isinstancetdicttAssertionErrortreprttypeRR;titemstlistttupleRARR Rt ValueErrorR$tarrayR'tTrueR"R#ttolistR(R=R>R?R@titmsgt actual_dtypet desired_dtype((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRns: &*    cC`sͺt|tƒrΉt|tƒs9ttt|ƒƒƒ‚ntt|ƒt|ƒ|ƒx]|jƒD]O\}}||krtt|ƒƒ‚nt||||d||fƒqbWdSt|tt fƒrBt|tt fƒrBtt|ƒt|ƒ|ƒx<t t|ƒƒD](}t||||d||fƒqWdSt|t j ƒsft|t j ƒrvt |||ƒSt||g|ƒ}||ks¦t|ƒ‚ndS(s< Raises an assertion error if two items are equal. s key=%r %sNs item=%r %s(RKRLRMRNROt fail_if_equalR;RPRQRRR<R$RRR (R=R>R?R@RWRX((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyR[•s& &*&$ ic C`s“t|tjƒs$t|tjƒrCt||d|d|d|ƒSt||gd|d|ƒ}tt||ƒ|ƒdkst|ƒ‚ndS(s~ Asserts that two items are almost equal. The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal). R9R?tverboseiN(RKR$RRR troundR8RM(R=R>R9R?R\RX((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyR²s$ c C`stt|ƒt|ƒƒ}t|dtd|dtdtƒ}t|dtd|dtdtƒ}|tkr{|tk s“|tkrΜ|tk rΜt||gd|d|d|dd ƒ}t|ƒ‚ntjj ||j |ƒ|j |ƒd|d|d|ƒS( sn Asserts that comparison between two masked arrays is satisfied. The comparison is elementwise. R R!t keep_maskRIR?R\RHRBR4R5(R4R5( R R R R'RR RSR$ttestingRR( t comparisonR4R5R?R\RHR.R1RX((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRΕs $$  c C`s)ttj||d|d|ddƒdS(s@ Checks the elementwise equality of two masked arrays. R?R\RHsArrays are not equalN(RRCt__eq__(R4R5R?R\((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRήs c C`s/d„}t|||d|d|ddƒdS(sT Raises an assertion error if two masked arrays are not equal elementwise. cS`stjt||ƒƒ S(N(R$talltrueR(R4R5((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pytcompareνsR?R\RHsArrays are not equalN(R(R4R5R?R\Rc((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRθs c `s5‡fd†}t|||d|d|ddƒdS(s| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. c`st||ddˆ ƒS(s<Returns the result of the loose comparison between x and y).R/g$@(R(R4R5(R9(s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRcϊsR?R\RHsArrays are not almost equalN(R(R4R5R9R?R\Rc((R9s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRσsc `s5‡fd†}t|||d|d|ddƒdS(s| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. c`st||ˆƒS(s<Returns the result of the loose comparison between x and y).(R(R4R5(R9(s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRcsR?R\RHsArrays are not almost equalN(R(R4R5R9R?R\Rc((R9s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRsc C`s)ttj||d|d|ddƒdS(s7 Checks that x is smaller than y elementwise. R?R\RHsArrays are not less-orderedN(RRCt__lt__(R4R5R?R\((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRs cC`sU|tkrt|tkƒn|tkr>t|tkƒnt||d|ƒdS(s- Asserts the equality of two masks. R?N(R RR(tm1tm2R?((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pyRs   (/t__doc__t __future__RRRRCtnumpyR$RRtnumpy.core.umathtcoreR*t numpy.testingRRRRR R R R R RRt __all__maskedtunittestRt__some__from_testingt__all__RURRRARRR[RRRRRRRRRR(((s1/tmp/pip-build-fiC0ax/numpy/numpy/ma/testutils.pytsD   (.         '