o 6a'@s8dZddlZddlZddlmZmZddlmmZddl Zddl m Z m Z m Z m Z mZddlmZmZmZmZmZmZgdZddlmZgd ZeeZd,d dZd-ddZd.ddZddZd.ddZd.ddZeZ d/ddZ!e!Z"  d0ddZ#d1d d!Z$d1d"d#Z%d2d$d%Z&d2d&d'Z'd1d(d)Z(d.d*d+Z)dS)3zMiscellaneous 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_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|jjdkr%t||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 astyper less_equalumathabsolute) ab fill_valuertolatolmd1d2xydr94/usr/lib/python3/dist-packages/numpy/ma/testutils.pyr)s $rc Cstt|t|}t|}t|}|jjdks|jjdkr%t||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*raroundabs) r.r/decimalr0r3r4r5r6r7r8r9r9r:r?s rcCsJtt|t||tt|D]}t||||d|d|qdS)z; Asserts the equality of two non-array sequences. item= N)rlenrange)actualdesirederr_msgkr9r9r:_assert_equal_on_sequencesRs"rIcCsdt|j|j|jjD]$}t||t||}}|tur/|tur/tt||t||q dS)zI Asserts that two records are equal. Pretty crude for now. N)rr%namesoperatorgetitemr)r.r/fafbfr9r9r:r]s rcCs|t|trDt|tsttt|tt|t|||D]!\}}||vr1t|d|t||||d|d|q dSt|tt frYt|tt frYt ||ddSt|t stt|t stt ||g|}||ksrt|dS|t ur||t us|t ur|t urt ||g|ddd}t|t|}t|}|j|j}}|jd kr|jd krt ||ddSt|||S) z, Asserts that two items are equal. z not in key=rBNr@rGr6r7)headerrJS) isinstancedictAssertionErrorreprtyperrCitemslisttuplerIrrr ValueErrorr' asanyarrayr%r&tolistr)rErFrGrHimsg actual_dtype desired_dtyper9r9r:rls>  "   rcCs.t|trAt|tsttt|tt|t|||D]\}}||vr.tt|t||||d|d|q dSt|tt frtt|tt frttt|t||t t|D]}t||||d|d|q_dSt|t j st|t j rt |||St||g|}||kst|dS)z< Raises an assertion error if two items are equal. rPrBNrA)rUrVrWrXrY fail_if_equalrCrZr[r\rDr'rrr)rErFrGrHr`rar9r9r:rds(   "" rdcCs^t|tjs t|tjrt|||||dSt||g||d}tt|||dks-t|dS)z~ Asserts that two items are almost equal. The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal). )r?rGverbose)rGrfrN)rUr'rrrroundr>rW)rErFr?rGrfrar9r9r:rsrc Cstt|t|}t|d|ddd}t|d|ddd}|tur#|tus+|tur:|tur:t||g|||dd}t|tjj|| || ||||dS)zn Asserts that comparison between two masked arrays is satisfied. The comparison is elementwise. F)r#r$ keep_masksubokrR)rGrfrSrJrGrfrS) r r r rrr]r'testingrr) comparisonr6r7rGrfrSr0r3rar9r9r:rs  rcCttj||||dddS)z@ Checks the elementwise equality of two masked arrays. Arrays are not equalrjN)rrK__eq__r6r7rGrfr9r9r:r  rcCs dd}t|||||dddS)zT Raises an assertion error if two masked arrays are not equal elementwise. cSstt|| S)N)r'alltruerrRr9r9r:comparesz$fail_if_array_equal..comparernrjNr)r6r7rGrfrsr9r9r:rs  rc$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 equalrjNrtr6r7r?rGrfrsr9rxr:r   rcru)rvcs t||S)rw)rrRrxr9r:rss z*assert_array_almost_equal..compareryrjNrtrzr9rxr:rr{rcCrm)z7 Checks that x is smaller than y elementwise. zArrays are not less-orderedrjN)rrK__lt__rpr9r9r:r rqrcCs:|tur t|tu|turt|tut|||ddS)z- Asserts the equality of two masks. rQN)r rr)m1m2rGr9r9r:rs   r)Trr )r;T)r@)rer@T)r@Tr@T)r@T)r;r@T)*__doc__rKnumpyr'rrnumpy.core.umathcorer, numpy.testingrrrrrr r r r rr __all__maskedunittestr__some__from_testing__all__rrrIrrrdrrrrrrrrrrr9r9r9r:s<       '