B <�Fd�(�@sndZddlmZmZmZddlZddlZddlmZm Z ddl m m Z ddl mZmZmZmZmZmZmZddlmmZddl mZmZmZmZmZmZdd d d d d ddddddddgZddddddgZeeZ d2dd �Z!d3d!d�Z"d4d#d$�Z#d%d�Z$d5d&d�Z%d6d'd(�Z&e&Z'd7d*d �Z(e(Z)d8d+d �Z*d9d,d�Z+d:d-d�Z,d;d.d �Z-d<d/d �Z.d=d0d�Z/d>d1d�Z0dS)?z�Miscellaneous 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 $ �)�division�absolute_import�print_functionN)�ndarray�float_)�TestCase�assert_�assert_allclose�assert_array_almost_equal_nulp� assert_raises� build_err_msg�run_module_suite�)�mask_or�getmask� masked_array�nomask�masked�filled�almost�approx�assert_almost_equal�assert_array_almost_equal�assert_array_approx_equal�assert_array_compare�assert_array_equal�assert_array_less� assert_close� assert_equal�assert_equal_records�assert_mask_equal�assert_not_equal�fail_if_array_equalrrr r r r T��h㈵��>�:�0�yE>c Cs�tt|�t|��}t|�}t|�}|jjdks:|jjdkrJt�||���Stt|d|d�|�� t �}tt|d|d�d�� 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)�copy�maskr)rrr�dtype�char�np�equal�ravelr�astyperZ less_equal�umathZabsolute) �a�b� fill_value�rtolZatol�m�d1�d2�x�y�d�r9�E/opt/alt/python37/lib64/python3.7/site-packages/numpy/ma/testutils.pyr*s $�c Cs�tt|�t|��}t|�}t|�}|jjdks:|jjdkrJt�||���Stt|d|d�|�� t �}tt|d|d�d�� 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'rg$@) rrrr(r)r*r+r,rr-rZaround�abs) r/r0�decimalr1r3r4r5r6r7r8r9r9r:r@s �cCsJtt|�t|�|�x0tt|��D] }t||||d||f�q"WdS)z; Asserts the equality of two non-array sequences. z item=%r %sN)r�len�range)�actual�desired�err_msg�kr9r9r:�_assert_equal_on_sequencesSs rEcCsht|j|j�xT|jjD]H}t�||�t�||�}}|tk r|tk rtt�||�t�||��qWdS)zI Asserts that two records are equal. Pretty crude for now. N)rr(�names�operator�getitemr)r/r0�fZafZbfr9r9r:r^s cCs�t|t�r�t|t�s$ttt|����tt|�t|�|�xH|��D]<\}}||krbtd||f��t||||d||f�qBWdSt|tt f�r�t|tt f�r�t ||dd�St|t �s�t|t �s�t ||g|�}||ks�t|��dS|t kr�|t k �s |t k�r(|t k �r(t ||g|ddd�}t|��tj|dd d �}tj|dd d �}|j|j}}|jd k�r�|jd k�r�t |��|��dd�St|||�S) z, Asserts that two items are equal. z %s not in %sz key=%r %sNr>)rC)r6r7)�headerrFFT)r&�subok�S)� isinstance�dict�AssertionError�repr�typerr?�items�list�tuplerErr r� ValueErrorr*Zarrayr(r)�tolistr)rArBrCrD�i�msgZ actual_dtypeZ desired_dtyper9r9r:rms:    cCs4t|t�r�t|t�s$ttt|����tt|�t|�|�xD|��D]8\}}||kr^tt|���t||||d||f�qBWdSt|tt f�r�t|tt f�r�tt|�t|�|�x0t t|��D] }t||||d||f�q�WdSt|t j ��st|t j ��rt |||�St||g|�}||k�s0t|��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 )rArBrCrDrWrXr9r9r:rY�s&       rY�cCs^t|tj�st|tj�r*t|||||d�St||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=rC�verbose)rCr[rN)rMr*rrr �roundr<rO)rArBr=rCr[rXr9r9r:r�s  c Cs�tt|�t|��}t|d|ddd�}t|d|ddd�}|tkrF|tk sV|tkrt|tk rtt||g|||dd�}t|��tj||�|�|�|�|||d�S)zn Asserts that comparison between two masked arrays is satisfied. The comparison is elementwise. F)r&r'Z keep_maskrK)r6r7)rCr[rJrF)rCr[rJ) rrrrr rU�utilsrr) Z comparisonr6r7rCr[rJr1r3rXr9r9r:r�s   cCsttj||||dd�dS)z@ Checks the elementwise equality of two masked arrays. zArrays are not equal)rCr[rJN)rrG�__eq__)r6r7rCr[r9r9r:r�s cCs dd�}t|||||dd�dS)zT Raises an assertion error if two masked arrays are not equal elementwise. cSst�t||�� S)N)r*Zalltruer)r6r7r9r9r:�compare�sz$fail_if_array_equal.<locals>.comparezArrays are not equal)rCr[rJN)r)r6r7rCr[r_r9r9r:r"�s cs$�fdd�}t|||||dd�dS)z| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. cst||d� d�S)z<Returns the result of the loose comparison between x and y).g$@)r2)r)r6r7)r=r9r:r_�sz*assert_array_approx_equal.<locals>.comparezArrays are not almost equal)rCr[rJN)r)r6r7r=rCr[r_r9)r=r:r�s  cs$�fdd�}t|||||dd�dS)z| Checks the equality of two masked arrays, up to given number odecimals. The equality is checked elementwise. cs t||��S)z<Returns the result of the loose comparison between x and y).)r)r6r7)r=r9r:r_sz*assert_array_almost_equal.<locals>.comparezArrays are not almost equal)rCr[rJN)r)r6r7r=rCr[r_r9)r=r:rs  cCsttj||||dd�dS)z7 Checks that x is smaller than y elementwise. zArrays are not less-ordered)rCr[rJN)rrG�__lt__)r6r7rCr[r9r9r:rs cCs:|tkrt|tk�|tkr(t|tk�t|||d�dS)z- Asserts the equality of two masks. )rCN)rrr)Zm1Zm2rCr9r9r:r s   )Tr#r$)r;T)r>)r>)r>)rZr>T)r>Tr>T)r>T)r>T)r;r>T)r;r>T)r>T)r>)1�__doc__Z __future__rrrrGZnumpyr*rrZnumpy.core.umathZcorer.Z numpy.testingrrr r r r r Znumpy.testing.utilsZtestingr]rrrrrrZ __all__maskedZ__some__from_testing�__all__rrrErrrYr!rrrrr"rrrr r9r9r9r:�<module>sB$      '