B []}(@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. OF)copymaskr )r rrdtypecharnpequalravelrastyperZ less_equalumathZabsolute) ab fill_valuertolZatolmd1d2xydr85/tmp/pip-install-svzetoqp/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$F)r%r&r g$@) r rrr'r(r)r*r+rr,rZaroundabs) r.r/decimalr0r2r3r4r5r6r7r8r8r9rAs cCsJtt|t||x0tt|D] }t||||d||fq"WdS)z; Asserts the equality of two non-array sequences. z item=%r %sN)rlenrange)actualdesirederr_msgkr8r8r9_assert_equal_on_sequencesTs rDcCsht|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/fafZbfr8r8r9r_s cCst|trt|ts$ttt|tt|t||xH|D]<\}}||krbtd||ft||||d||fqBWdSt|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 %sz key=%r %sNr=)rB)r5r6)headerrEFT)r%subokS) isinstancedictAssertionErrorreprtyperr>itemslisttuplerDrr r ValueErrorr)arrayr'r(tolistr)r@rArBrCimsgZ actual_dtypeZ desired_dtyper8r8r9rns:    cCs4t|trt|ts$ttt|tt|t||xD|D]8\}}||kr^tt|t||||d||fqBWdSt|tt frt|tt frtt|t||x0t t|D] }t||||d||fqWdSt|t j st|t j rt |||St||g|}||ks0t|dS)z< Raises an assertion error if two items are equal. z key=%r %sNz item=%r %s)rMrNrOrPrQ fail_if_equalr>rRrSrTr?r)rr r )r@rArBrCrXrYr8r8r9rZs&       rZcCs^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<rBverbose)rBr\rN)rMr)rrr roundr;rO)r@rAr<rBr\rYr8r8r9rs  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_maskrK)r5r6)rBr\rJrE)rBr\rJ) r rrrr rUr)Ztestingrr) Z comparisonr5r6rBr\rJr0r2rYr8r8r9rs   cCsttj||||dddS)z@ Checks the elementwise equality of two masked arrays. zArrays are not equal)rBr\rJN)rrF__eq__)r5r6rBr\r8r8r9rs cCs dd}t|||||dddS)zT Raises an assertion error if two masked arrays are not equal elementwise. cSstt|| S)N)r)Zalltruer)r5r6r8r8r9comparesz$fail_if_array_equal..comparezArrays are not equal)rBr\rJN)r)r5r6rBr\r_r8r8r9r s 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)rBr\rJN)r)r5r6r<rBr\r_r8)r<r9rs  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)rBr\rJN)r)r5r6r<rBr\r_r8)r<r9rs  cCsttj||||dddS)z7 Checks that x is smaller than y elementwise. zArrays are not less-ordered)rBr\rJN)rrF__lt__)r5r6rBr\r8r8r9rs cCs:|tkrt|tk|tkr(t|tkt|||ddS)z- Asserts the equality of two masks. )rBN)rrr)m1m2rBr8r8r9rs   )Tr"r#)r:T)r=)r=)r=)r[r=T)r=Tr=T)r=T)r=T)r:r=T)r:r=T)r=T)r=).__doc__ __future__rrrrFZnumpyr)rrZnumpy.core.umathcorer-Z numpy.testingrrr r r r rrrrrZ __all__maskedZunittestr!Z__some__from_testing__all__rrrDrrrZrrrrrr rrrrr8r8r8r9sD      '