B @`%(@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. OF)copymaskr )r r rdtypecharnpequalravelr astyperZ less_equalumathabsolute) ab fill_valuertolZatolmd1d2xydr66/tmp/pip-unpacked-wheel-ecq9wray/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!F)r"r#r g$@) r r rr$r%r&r'r(r r)rZaroundabs) r,r-decimalr.r0r1r2r3r4r5r6r6r7r?s cCsNtt|t||x4tt|D]$}t||||d|d|q"WdS)z; Asserts the equality of two non-array sequences. zitem= N)rlenrange)actualdesirederr_msgkr6r6r7_assert_equal_on_sequencesRs$rCcCsht|j|jxT|jjD]H}t||t||}}|tk r|tk rtt||t||qWdS)zI Asserts that two records are equal. Pretty crude for now. N)rr$namesoperatorgetitemr)r,r-fafZbfr6r6r7r]s cCst|trt|ts$ttt|tt|t||xN|D]B\}}||krdt|d|t||||d|d|qBWdSt|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 zkey=r<Nr;)rA)r3r4)headerrDFT)r"subokS) isinstancedictAssertionErrorreprtyperr=itemslisttuplerCrrr ValueErrorr&arrayr$r%tolistr)r?r@rArBimsgZ actual_dtypeZ desired_dtyper6r6r7rls:  $ cCs<t|trt|ts$ttt|tt|t||xH|D]<\}}||kr^tt|t||||d|d|qBWdSt|tt frt|tt frtt|t||x4t t|D]$}t||||d|d|qWdSt|t j s t|t j rt |||St||g|}||ks8t|dS)z< Raises an assertion error if two items are equal. zkey=r<Nzitem=)rLrMrNrOrP fail_if_equalr=rQrRrSr>r&rrr)r?r@rArBrWrXr6r6r7rYs&   $$  rYcCs^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:rAverbose)rAr[rN)rLr&rrrroundr9rN)r?r@r:rAr[rXr6r6r7rs  c 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_maskrJ)r3r4)rAr[rIrD)rAr[rI) r r r rrrTr&Ztestingrr) Z comparisonr3r4rAr[rIr.r0rXr6r6r7rs   cCsttj||||dddS)z@ Checks the elementwise equality of two masked arrays. zArrays are not equal)rAr[rIN)rrE__eq__)r3r4rAr[r6r6r7rs cCs dd}t|||||dddS)zT Raises an assertion error if two masked arrays are not equal elementwise. cSstt|| S)N)r&Zalltruer)r3r4r6r6r7comparesz$fail_if_array_equal..comparezArrays are not equal)rAr[rIN)r)r3r4rAr[r^r6r6r7rs cs$fdd}t|||||dddS)z| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. cst||d dS)z.comparezArrays are not almost equal)rAr[rIN)r)r3r4r:rAr[r^r6)r:r7rs  cs$fdd}t|||||dddS)z| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. cs t||S)z.comparezArrays are not almost equal)rAr[rIN)r)r3r4r:rAr[r^r6)r:r7rs  cCsttj||||dddS)z7 Checks that x is smaller than y elementwise. zArrays are not less-ordered)rAr[rIN)rrE__lt__)r3r4rAr[r6r6r7r s cCs:|tkrt|tk|tkr(t|tkt|||ddS)z- Asserts the equality of two masks. )rAN)r rr)m1m2rAr6r6r7rs   )Trr )r8T)r;)r;)r;)rZr;T)r;Tr;T)r;T)r;T)r8r;T)r8r;T)r;T)r;)*__doc__rEZnumpyr&rrZnumpy.core.umathcorer*Z numpy.testingrrrrrr r r r rrZ __all__maskedZunittestrZ__some__from_testing__all__rrrCrrrYrrrrrrrrrrr6r6r6r7sB      '