a :jg (@s0dZddlZddlZddlmZddlmmZddlZddlm Z m Z m Z m Z m Z ddlmZmZmZmZmZmZgdZddlmZgd ZeeZd,d dZd-ddZd.ddZddZd/ddZd0ddZeZ d1ddZ!e!Z"d2ddZ#d3d d!Z$d4d"d#Z%d5d$d%Z&d6d&d'Z'd7d(d)Z(d8d*d+Z)dS)9zMiscellaneous 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)ndarray)assert_assert_allcloseassert_array_almost_equal_nulp assert_raises build_err_msg)mask_orgetmask masked_arraynomaskmaskedfilled)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>c Cstt|t|}t|}t|}|jjdks:|jjdkrJt||Stt|d|d| tj }tt|d|dd tj } 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 astypefloat64Z less_equalumathabsolute) ab fill_valuertolZatolmd1d2xydr7rEr4r5)headerrHS) isinstancedictAssertionErrorreprtyperrAitemslisttuplerGrrr ValueErrorr&Z asanyarrayr$r%tolistr)rCrDrErFimsgZ actual_dtypeZ desired_dtyper7r7r8rpsD  "  rcCs4t|trt|ts$ttt|tt|t|||D]<\}}||vr\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. rNr@Nr?)rSrTrUrVrW fail_if_equalrArXrYrZrBr&rrr)rCrDrErFr]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=rEverbose)rErarN)rSr&rrrroundr<rU)rCrDr=rErar^r7r7r8rsrc Cstt|t|}t|d|ddd}t|d|ddd}|turF|tusV|turt|turtt||g|||dd}t|tjj|| || ||||dS)zn Asserts that comparison between two masked arrays is satisfied. The comparison is elementwise. F)r"r#Z keep_maskZsubokrP)rErarQrHrErarQ) r r r r rr[r&Ztestingrr) Z comparisonr4r5rErarQr/r1r^r7r7r8rs$  rcCsttj||||dddS)z@ Checks the elementwise equality of two masked arrays. Arrays are not equalrcN)rrI__eq__r4r5rErar7r7r8rs rcCs dd}t|||||dddS)zT Raises an assertion error if two masked arrays are not equal elementwise. cSstt|| S)N)r&allrrPr7r7r8comparesz$fail_if_array_equal..comparerdrcNr)r4r5rErarhr7r7r8rs rcs$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 equalrcNrir4r5r=rErarhr7rlr8rs  rcs$fdd}t|||||dddS)rjcs t||S)rk)rrPrlr7r8rh sz*assert_array_almost_equal..comparermrcNrirnr7rlr8rs  rcCsttj||||dddS)z7 Checks that x is smaller than y elementwise. zArrays are not less-orderedrcN)rrI__lt__rfr7r7r8rs rcCs:|turt|tu|tur(t|tut|||ddS)z- Asserts the equality of two masks. rON)r rr)m1m2rEr7r7r8rs   r)Trr)r9T)r>)r>)r>)r`r>T)r>Tr>T)r>T)r>T)r9r>T)r9r>T)r>T)r>)*__doc__rInumpyr&rZnumpy._core.umathZ_corer+Z numpy.testingrrrrrcorer r r r r rZ __all__maskedZunittestrZ__some__from_testing__all__rrrGrrr_rrrrrrrrrrr7r7r7r8s:       '