i )dZddlZddlZddlmcmZddlZddlmZddlm Z m Z m Z m Z m Z ddlmZmZmZmZmZmZgdZddlmZgd ZeezZdd ZddZd dZdZd dZd dZeZ d!dZ!e!Z" d"dZ#d#dZ$d#dZ%d$dZ&d$dZ'd#dZ(d dZ)dS)%zMiscellaneous functions for testing masked arrays and subclasses :author: Pierre Gerard-Marchant :contact: pierregm_at_uga_dot_edu N)ndarray)assert_assert_allcloseassert_array_almost_equal_nulp assert_raises build_err_msg)filledgetmaskmask_ormasked masked_arraynomask)almostapproxassert_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)TestCase)rrrrrTh㈵>:0yE>ctt|t|}t|}t|}|jjdks|jjdkr't j||Stt|d|| t j }tt|d|d t j } t j tj || z ||tj | zz} | 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 r dtypecharnpequalravelrastypefloat64 less_equalumathabsolute) ab fill_valuertolatolmd1d2xyds @C:\PYTHON\_runtimes\venv\Lib\site-packages\numpy/ma/testutils.pyrr-s  GAJJ''A B B x}rx}33xB%%'''Re!,,,j   fRZ |BU333Q77>>rzJJA enQU++TD5>!;L;L4L-LMMA 7799ctt|t|}t|}t|}|jjdks|jjdkr't j||Stt|d|| t j }tt|d|d t j }t j t j ||z |d| zk} | 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 r r&r'r(r)r*rr+r,aroundabs) r0r1decimalr2r5r6r7r8r9r:s r;rrEs   GAJJ''A B B x}rx}33xB%%'''Re!,,,j   fRZ |BU333Q77>>rzJJA "&Q--))Twh-??A 7799r<c tt|t||tt|D]%}t||||d|d|&dS)z; Asserts the equality of two non-array sequences. item= N)rlenrange)actualdesirederr_msgks r;_assert_equal_on_sequencesrMZs{ Vc'llG444 3w<< FFVAY ,DA,D,D7,D,DEEEEFFr<c<t|j|j|jjD]t}tj||tj||}}|t ur?|t ur6ttj||tj||udS)zI Asserts that two records are equal. Pretty crude for now. N)rr&namesoperatorgetitemr )r0r1fafbfs r;rrds!'""" W]II$Q**H,dSt|ttfr.t|ttfrt||dSt|ts>t|ts)t||g|}||kst|dS|tur |tus|tur-|tur$t||g|dd}t|tj|}tj|}|j|j}}|jd krA|jd kr6t||dSt'|||S) z, Asserts that two items are equal. z not in key=rFNrCrKr8r9)headerrOS) isinstancedictAssertionErrorreprtyperrGlisttuplerMrrr ValueErrorr( asanyarrayr&r'tolistr)rIrJrKrLmsg actual_dtype desired_dtypes r;rrrsH '4  &$'' 5 d6ll!3!344 4S[[#g,,888 I IA$%;%;6%;%;<<< GAJ0Gq0G0Gg0G0G H H H H'D%=))Gj$.O.OG)&'2FFFF vw ' ':gw+G+GVW-w88&   %% % 6  Gv$5$5&F*:*:VW-#BjBBBoo ]6 " "FmG$$G%+\7==\CM$6#$=$=)&--//*1..*:*:24666 6 fgw 7 77r<c t|trt|ts)ttt |t t |t |||D]E}||vrtt|t ||||d|d|FdSt|ttfrt|ttfrot t |t ||tt |D]%}t ||||d|d|&dSt|tj st|tj rt|||St||g|}||kst|dS)z< Raises an assertion error if two items are equal. rVrFNrE)r[r\r]r^r_ fail_if_equalrGr`rarHr(rrr)rIrJrKrLres r;riris '4  &$'' 5 d6ll!3!344 4c&kk3w<<999 J JA$T!WW--- &)WQZ1H1H1Hw1H1H I I I I'D%=))j$.O.Oc&kk3w<<999s7||$$ K KA &)WQZ1I1I1I1I1I J J J J&"*%%=GRZ)H)H="67G<<< )7 3 3C f  S!!!  r<c$t|tjst|tjrt|||||St ||g||}t t ||z |dkst|dS)z~ Asserts that two items are almost equal. The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal). )rBrKverbose)rKrlrN)r[r(rrrroundrAr])rIrJrBrKrlres r;rrs&"*%%KGRZ)H)HK('18'KKK K ) ' : : :C Wv%&& 0 0A 5 5S!!! 6 5r<ctt|t|}t|d|dd}t|d|dd}|tur |tus|tur.|tur%t ||g|||d}t |t j|| || ||||S)zn Asserts that comparison between two masked arrays is satisfied. The comparison is elementwise. F)r$r% keep_masksubokrX)rKrlrYrOrKrlrY) r r rr rrbr(testingrr ) comparisonr8r9rKrlrYr2r5res r;rrs  GAJJ''AQUe5IIIAQUe5IIIA fqF{{6kkAKKQFGW#)===oo : * *:+,88J+?+?+,88J+?+?3:3:6 + K KKr<cDttj||||ddS)z@ Checks the elementwise equality of two masked arrays. Arrays are not equalrqN)rrP__eq__r8r9rKrls r;rrs5 !Q!(' 6888888r<c6d}t|||||ddS)zT Raises an assertion error if two masked arrays are not equal elementwise. cHtjt|| S)N)r(allrrXs r;comparez$fail_if_array_equal..comparesF6!Q<<((()r<rurqNr)r8r9rKrlr{s r;rrs? ***!Q 6888888r<c<fd}t|||||ddS)| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. c0t||d zS).comparesa1111r<Arrays are not almost equalrqNr|r8r9rBrKrlr{s ` r;rrsL22222!Q =??????r<c<fd}t|||||ddS)r~c&t||S)r)rrs r;r{z*assert_array_almost_equal..compare saG$$$r<rrqNr|rs ` r;rrsL%%%%%!Q =??????r<cDttj||||ddS)z7 Checks that x is smaller than y elementwise. zArrays are not less-orderedrqN)rrP__lt__rws r;rrs5 !Q!(' =??????r<c|turt|tu|turt|tut|||dS)z- Asserts the equality of two masks. rWN)rrr)m1m2rKs r;rrsU  V||f  V||f r2w//////r<)Trr )r=T)rC)rjrCT)rCTrCT)rCT)r=rCT)*__doc__rPnumpyr(numpy._core.umath_corer. numpy.testingrrrrrrcorer r r r rr __all__maskedunittestr__some__from_testing__all__rrrMrrrirrrrrrrrrrr<r;rs^ !!!!!!!!!IHHHHHHHHHHHHHHH  . .0*FFFF I I I$8$8$8$8N""""4! " " " " # MO$(KKKK288888888 ? ? ? ? ? ? ? ????? 0 0 0 0 0 0r<