U C^}(@sfdZddlmZmZmZddlZddlZddlmZm Z ddl m m Z ddl Zddl mZmZmZmZmZddl mZmZmZmZmZmZdd d d d d ddddddddgZddlmZdddddgZeeZd2dd Zd3d!dZd4d#d$Z d%dZ!d5d&dZ"d6d'd(Z#e#Z$d7d*d Z%e%Z&d8d+d Z'd9d,dZ(d:d-dZ)d;d.d Z*dd1dZ-dS)?zMiscellaneous 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 $ )divisionabsolute_importprint_functionN)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)TestCaser!rrr r Th㈵>: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 rrdtypecharnpequalravelrastyperZ less_equalumathZabsolute) ab fill_valuertolZatolmd1d2xydr95/tmp/pip-install-6_kvzl1k/numpy/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 rrr(r)r*r+r,rr-rZaroundabs) r/r0decimalr1r3r4r5r6r7r8r9r9r:rAs cCsFtt|t||tt|D] }t||||d||fq dS)z; Asserts the equality of two non-array sequences. item=%r %sN)rlenrange)actualdesirederr_msgkr9r9r:_assert_equal_on_sequencesTsrGcCsdt|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/r0fafZbfr9r9r:r_s  cCst|trt|ts$ttt|tt|t|||D]<\}}||kr`td||ft||||d||fq@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|dd d }tj|dd d }|j|j}}|jd kr|jd krt ||ddSt|||S) z, Asserts that two items are equal. z %s not in %s key=%r %sNr?rEr6r7)headerrHFT)r&subokS) isinstancedictAssertionErrorreprtyperrAitemslisttuplerGrr r ValueErrorr*arrayr(r)tolistr)rCrDrErFimsgZ actual_dtypeZ desired_dtyper9r9r:rnsH  cCs*t|tr~t|ts$ttt|tt|t|||D]8\}}||kr\tt|t||||d||fq@dSt|tt frt|tt frtt|t||t t|D] }t||||d||fqdSt|t j st|t j rt |||St||g|}||ks&t|dS)z< Raises an assertion error if two items are equal. rMNr@)rSrTrUrVrW fail_if_equalrArXrYrZrBr*rr r )rCrDrErFr^r_r9r9r:r`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>rEverbose)rErbrN)rSr*rrr roundr=rU)rCrDr>rErbr_r9r9r:rsc 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_maskrQrO)rErbrPrHrErbrP) r rrrr r[r*Ztestingrr) Z comparisonr6r7rErbrPr1r3r_r9r9r:rs(  cCsttj||||dddS)z@ Checks the elementwise equality of two masked arrays. Arrays are not equalrdN)rrI__eq__r6r7rErbr9r9r:rs  cCs dd}t|||||dddS)zT Raises an assertion error if two masked arrays are not equal elementwise. cSstt|| S)N)r*ZalltruerrOr9r9r:comparesz$fail_if_array_equal..comparererdNr)r6r7rErbrhr9r9r:r s cs$fdd}t|||||dddS)| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. cst||d dS)r9r:rhsz*assert_array_approx_equal..compareArrays are not almost equalrdNrir6r7r>rErbrhr9rlr:rs  cs$fdd}t|||||dddS)rjcs t||S)rk)rrOrlr9r:rhsz*assert_array_almost_equal..comparermrdNrirnr9rlr:rs  cCsttj||||dddS)z7 Checks that x is smaller than y elementwise. zArrays are not less-orderedrdN)rrI__lt__rgr9r9r:rs  cCs:|tkrt|tk|tkr(t|tkt|||ddS)z- Asserts the equality of two masks. rNN)rrr)m1m2rEr9r9r:rs   )Tr"r#)r;T)r?)r?)r?)rar?T)r?Tr?T)r?T)r?T)r;r?T)r;r?T)r?T)r?).__doc__ __future__rrrrIZnumpyr*rrZnumpy.core.umathcorer.Z numpy.testingrrr r r r rrrrrZ __all__maskedZunittestr!Z__some__from_testing__all__rrrGrrr`rrrrrr rrrrr9r9r9r:sb      '