HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/numpy/ma/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/numpy/ma/__pycache__/testutils.cpython-36.pyc
3

���h;(�@sLdZddlZddlZddlmZmZddljjZddl	Zddl	m
Z
mZmZm
Z
mZddlmZmZmZmZmZmZddd	d
ddd
dddddddgZddlmZdddddgZeeZd1dd�Zd2d d�Zd3d"d#�Zd$d�Zd4d%d�Zd5d&d'�ZeZ d6d)d	�Z!e!Z"d7d*d�Z#d8d+d
�Z$d9d,d�Z%d:d-d�Z&d;d.d
�Z'd<d/d�Z(d=d0d�Z)dS)>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 $

�N)�ndarray�float_)�assert_�assert_allclose�assert_array_almost_equal_nulp�
assert_raises�
build_err_msg�)�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_equal)�TestCaserrrrrT��h㈵��>�:�0�yE>cCs�tt|�t|��}t|�}t|�}|jjdks:|jjdkrJtj||�j�Stt|d|d�|�j	t
�}tt|d|d�d�j	t
�}	tjtj
||	�||tj
|	��}
|
j�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	)r
rr�dtype�char�np�equal�ravelr�astyperZ
less_equal�umathZabsolute)�a�b�
fill_value�rtolZatol�m�d1�d2�x�y�d�r5�3/tmp/pip-build-5_djhm0z/numpy/numpy/ma/testutils.pyr)s$�c
Cs�tt|�t|��}t|�}t|�}|jjdks:|jjdkrJtj||�j�Stt|d|d�|�j	t
�}tt|d|d�d�j	t
�}tjtj||�|�d|k}	|	j�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(rr)rZaround�abs)
r+r,�decimalr-r/r0r1r2r3r4r5r5r6r?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�kr5r5r6�_assert_equal_on_sequencesRs rAcCsht|j|j�xT|jjD]H}tj||�tj||�}}|tk	r|tk	rttj||�tj||��qWdS)zI
    Asserts that two records are equal.

    Pretty crude for now.

    N)rr$�names�operator�getitemr)r+r,�f�afZbfr5r5r6r]scCs�t|t�r�t|t�s$ttt|����tt|�t|�|�xH|j�D]<\}}||krbtd||f��t||||d||f�qBWdSt|tt	f�r�t|tt	f�r�t
||dd�St|t�p�t|t�s�t||g|�}||ks�t|��dS|t
ko�|t
k	�s|t
k�r(|t
k	�r(t||g|dd
d�}t|��tj|d	d
d�}tj|d	d
d�}|j|j}}|jdk�r�|jdk�r�t
|j�|j�dd�St|||�S)z,
    Asserts that two items are equal.

    z%s not in %sz	key=%r
%sNr:)r?r2r3)�headerrBFT)r"�subok�S)r2r3)�
isinstance�dict�AssertionError�repr�typerr;�items�list�tuplerArrr�
ValueErrorr&�arrayr$r%�tolistr)r=r>r?r@�i�msgZactual_dtypeZ
desired_dtyper5r5r6rls:

 cCs4t|t�r�t|t�s$ttt|����tt|�t|�|�xD|j�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|tj��st|tj��rt
|||�St||g|�}||k�s0t|��dS)z<
    Raises an assertion error if two items are equal.

    z	key=%r
%sNz
item=%r
%s)rJrKrLrMrN�
fail_if_equalr;rOrPrQr<r&rrr)r=r>r?r@rUrVr5r5r6rW�s&

  
rW�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).

    )r9r?�verbose)r?rYrN)rJr&rrr�roundr8rL)r=r>r9r?rYrVr5r5r6r�s

c	Cs�tt|�t|��}t|d|ddd�}t|d|ddd�}|tkrF|tk	sV|tkrt|tk	rtt||g|||dd�}t|��tjj||j	|�|j	|�|||d�S)zn
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    F)r"r#Z	keep_maskrHr2r3)r?rYrGrB)r?rYrG)r2r3)
r
rrrrrRr&Ztestingrr)	Z
comparisonr2r3r?rYrGr-r/rVr5r5r6r�s	
cCsttj||||dd�dS)z@
    Checks the elementwise equality of two masked arrays.

    zArrays are not equal)r?rYrGN)rrC�__eq__)r2r3r?rYr5r5r6r�s
cCs dd�}t|||||dd�dS)zT
    Raises an assertion error if two masked arrays are not equal elementwise.

    cSstjt||��S)N)r&Zalltruer)r2r3r5r5r6�compare�sz$fail_if_array_equal.<locals>.comparezArrays are not equal)r?rYrGN)r)r2r3r?rYr\r5r5r6r�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$@)r.)r)r2r3)r9r5r6r\�sz*assert_array_approx_equal.<locals>.comparezArrays are not almost equal)r?rYrGN)r)r2r3r9r?rYr\r5)r9r6r�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)r2r3)r9r5r6r\sz*assert_array_almost_equal.<locals>.comparezArrays are not almost equal)r?rYrGN)r)r2r3r9r?rYr\r5)r9r6r�scCsttj||||dd�dS)z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-ordered)r?rYrGN)rrC�__lt__)r2r3r?rYr5r5r6r
s
cCs:|tkrt|tk�|tkr(t|tk�t|||d�dS)z-
    Asserts the equality of two masks.

    )r?N)r
rr)�m1�m2r?r5r5r6rs
)Trr )r7T)r:)r:)r:)rXr:T)r:Tr:T)r:T)r:T)r7r:T)r7r:T)r:T)r:)*�__doc__rCZnumpyr&rrZnumpy.core.umath�corer*Z
numpy.testingrrrrrr
rrr
rrZ
__all__maskedZunittestrZ__some__from_testing�__all__rrrArrrWrrrrrrrrrrr5r5r5r6�<module>sB 



'