U Dx`%(@sRdZddlZddlZddlmZmZddlmmZddl Zddl m Z m Z m Z m Z mZddlmZmZmZmZmZmZddd d d d d dddddddgZddlmZdddddgZeeZd1ddZd2d dZd3d"d#Zd$dZd4d%dZd5d&d'ZeZ d6d)d Z!e!Z"d7d*d Z#d8d+d Z$d9d,dZ%d:d-d Z&d;d.d Z'dzMiscellaneous 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 $ N)ndarrayfloat_)assert_assert_allcloseassert_array_almost_equal_nulp assert_raises build_err_msg)mask_orgetmask masked_arraynomaskmaskedfilledalmostapproxassert_almost_equalassert_array_almost_equalassert_array_approx_equalassert_array_compareassert_array_equalassert_array_less assert_close assert_equalassert_equal_recordsassert_mask_equalassert_not_equalfail_if_array_equal)TestCaserrrrrTh㈵>:0yE>c Cstt|t|}t|}t|}|jjdks:|jjdkrJt||Stt|d|d| t }tt|d|dd t } t t || ||t | } | S)a 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. OFcopymaskr )r r rdtypecharnpequalravelr astyperZ less_equalumathabsolute) ab fill_valuertolZatolmd1d2xydr79/tmp/pip-target-zr53vnty/lib/python/numpy/ma/testutils.pyr)s $c Cstt|t|}t|}t|}|jjdks:|jjdkrJt||Stt|d|d| t }tt|d|dd t }t t |||d| k} | S)z 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. r!Fr"r $@) r r rr%r&r'r(r)r r*rZaroundabs) r-r.decimalr/r1r2r3r4r5r6r7r7r8r?s cCsJtt|t||tt|D]$}t||||d|d|q dS)z; Asserts the equality of two non-array sequences. item= N)rlenrange)actualdesirederr_msgkr7r7r8_assert_equal_on_sequencesRs"rFcCsdt|j|j|jjD]H}t||t||}}|tk r|tk rtt||t||qdS)zI Asserts that two records are equal. Pretty crude for now. N)rr%namesoperatorgetitemr)r-r.fafZbfr7r7r8r]s  cCst|trt|ts$ttt|tt|t|||D]B\}}||krbt|d|t||||d|d|q@dSt|tt frt|tt frt ||ddSt|t st|t st ||g|}||kst|dS|t kr|t k s|t kr*|t k r*t ||g|ddd}t|tj|d d d }tj|d d d }|j|j}}|jd kr|jd krt ||ddSt|||S) z, Asserts that two items are equal. z not in key=r?Nr=rDr4r5)headerrGFT)r#subokS) isinstancedictAssertionErrorreprtyperr@itemslisttuplerFrrr ValueErrorr'arrayr%r&tolistr)rBrCrDrEimsgZ actual_dtypeZ desired_dtyper7r7r8rlsH  "cCs4t|trt|ts$ttt|tt|t|||D]<\}}||kr\tt|t||||d|d|q@dSt|tt frt|tt frtt|t||t t|D]$}t||||d|d|qdSt|t j st|t j rt |||St||g|}||ks0t|dS)z< Raises an assertion error if two items are equal. rLr?Nr>)rRrSrTrUrV fail_if_equalr@rWrXrYrAr'rrr)rBrCrDrEr]r^r7r7r8r_s&   ""  r_cCs^t|tjst|tjr*t|||||dSt||g||d}tt|||dksZt|dS)z~ Asserts that two items are almost equal. The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal). )r<rDverbose)rDrarN)rRr'rrrroundr;rT)rBrCr<rDrar^r7r7r8rsc Cstt|t|}t|d|ddd}t|d|ddd}|tkrF|tk sV|tkrt|tk rtt||g|||dd}t|tjj|| || ||||dS)zn Asserts that comparison between two masked arrays is satisfied. The comparison is elementwise. F)r#r$Z keep_maskrPrN)rDrarOrGrDrarO) r r r rrrZr'Ztestingrr) Z comparisonr4r5rDrarOr/r1r^r7r7r8rs(  cCsttj||||dddS)z@ Checks the elementwise equality of two masked arrays. Arrays are not equalrcN)rrH__eq__r4r5rDrar7r7r8rs  cCs dd}t|||||dddS)zT Raises an assertion error if two masked arrays are not equal elementwise. cSstt|| S)N)r'ZalltruerrNr7r7r8comparesz$fail_if_array_equal..comparerdrcNr)r4r5rDrargr7r7r8rs cs$fdd}t|||||dddS)| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. cst||d dS).compareArrays are not almost equalrcNrhr4r5r<rDrargr7rkr8rs  cs$fdd}t|||||dddS)rics t||S)rj)rrNrkr7r8rgsz*assert_array_almost_equal..comparerlrcNrhrmr7rkr8rs  cCsttj||||dddS)z7 Checks that x is smaller than y elementwise. zArrays are not less-orderedrcN)rrH__lt__rfr7r7r8r s  cCs:|tkrt|tk|tkr(t|tkt|||ddS)z- Asserts the equality of two masks. rMN)r rr)m1m2rDr7r7r8rs   )Trr )r9T)r=)r=)r=)r`r=T)r=Tr=T)r=T)r=T)r9r=T)r9r=T)r=T)r=)*__doc__rHnumpyr'rrZnumpy.core.umathcorer+Z numpy.testingrrrrrr r r r rrZ __all__maskedZunittestrZ__some__from_testing__all__rrrFrrr_rrrrrrrrrrr7r7r7r8s`      '