%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib64/python3.7/site-packages/numpy/testing/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/numpy/testing/__pycache__/utils.cpython-37.pyc

B

�9�`'�#@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
mZmZddl
Z
ddlZddlmZmZddlmZddlmZmZmZmZmZmZmZddlmZejdd	kr�dd
lm Z ndd
l m Z ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-g#Z!Gd.d(�d(e"�Z#e#Z$dZ%d/ej&kZ'e(ed0d�dk	Z)d1d2�Z*d�d4d�Z+d5d6�Z,d7d8�Z-d9d:�Z.ed;d<�d=d��Z/ej0d>k�r�d�d@dA�Z1d�dCd�Z2n2ej3ddD�dEk�r�dFe�4�fdGd�Z2ndHd�Z2ej3ddD�dEk�rdFe�4�gfdId�Z5ngfdJd�Z5d�dOd�Z6d�dPd�Z7dQd�Z8d�dSd�Z9d�dTd
�Z:d�dVdW�Z;d�dXd�Z<d�dYd�Z=d�dZd�Z>d[d�Z?d\d�Z@d�d]d�ZAd^d�ZBd_d�ZCd`d �ZDd�dad�ZEd�dcd�ZFddde�ZGd�dgd$�ZHd�dhd�ZId�did!�ZJd�djdk�ZKdldm�ZLdndo�ZMGdpdq�dqeN�ZOGdrds�dseN�ZPejQd�dtdu��ZRdvd"�ZSejQd�dwdx��ZTdyd#�ZUedzd{fd|d}�ZVGd~d%�d%e"�ZWejQdd*��ZXejQd�d)��ZYGd�d&�d&e	jZ�Z[Gd�d-�d-eN�Z\dS)�z*
Utility function to facilitate testing.

�)�division�absolute_import�print_functionN)�partial�wraps)�mkdtemp�mkstemp)�SkipTest)�float32�empty�arange�
array_repr�ndarray�isnat�array)�	deprecate�)�StringIO�assert_equal�assert_almost_equal�assert_approx_equal�assert_array_equal�assert_array_less�assert_string_equal�assert_array_almost_equal�
assert_raises�
build_err_msg�decorate_methods�jiffies�memusage�print_assert_equal�raises�rand�rundocs�	runstring�verbose�measure�assert_�assert_array_almost_equal_nulp�assert_raises_regex�assert_array_max_ulp�assert_warns�assert_no_warnings�assert_allclose�IgnoreException�clear_and_catch_warningsr	�KnownFailureException�temppath�tempdir�IS_PYPY�HAS_REFCOUNT�suppress_warningsc@seZdZdZdS)r0z<Raise this exception to mark a test as a known failing test.N)�__name__�
__module__�__qualname__�__doc__�r:r:�F/opt/alt/python37/lib64/python3.7/site-packages/numpy/testing/utils.pyr0)sZ__pypy__�getrefcountcCsTd}d}yddl}Wntk
r,d}YnX|j|kr<d}|sPd|}t|��|S)z# Import nose only when needed.
    T)�rrrNFz@Need nose >= %d.%d.%d for tests - see http://nose.readthedocs.io)�nose�ImportErrorZ__versioninfo__)Znose_is_goodZminimum_nose_versionr>�msgr:r:r;�import_nose5s

rA�cCs8d}|s4y
|�}Wntk
r*|}YnXt|��dS)aI
    Assert that works in release mode.
    Accepts callable msg to allow deferring evaluation until failure.

    The Python built-in ``assert`` does not work when executing code in
    optimized mode (the ``-O`` flag) - no byte-code is generated for it.

    For documentation on usage, refer to the Python documentation.

    TN)�	TypeError�AssertionError)�valr@�__tracebackhide__Zsmsgr:r:r;r'Ks

cCs.ddlm}||�}t|tt��r*td��|S)a�like isnan, but always raise an error if type not supported instead of
    returning a TypeError object.

    Notes
    -----
    isnan and other ufunc sometimes return a NotImplementedType object instead
    of raising any exception. This function is a wrapper to make sure an
    exception is always raised.

    This should be removed once this problem is solved at the Ufunc level.r)�isnanz!isnan not supported for this type)�
numpy.corerG�
isinstance�type�NotImplementedrC)�xrG�str:r:r;�gisnan_s
rNc	CsHddlm}m}|dd��$||�}t|tt��r:td��WdQRX|S)a�like isfinite, but always raise an error if type not supported instead of
    returning a TypeError object.

    Notes
    -----
    isfinite and other ufunc sometimes return a NotImplementedType object instead
    of raising any exception. This function is a wrapper to make sure an
    exception is always raised.

    This should be removed once this problem is solved at the Ufunc level.r)�isfinite�errstate�ignore)�invalidz$isfinite not supported for this typeN)rHrOrPrIrJrKrC)rLrOrPrMr:r:r;�	gisfiniteqsrSc	CsHddlm}m}|dd��$||�}t|tt��r:td��WdQRX|S)a�like isinf, but always raise an error if type not supported instead of
    returning a TypeError object.

    Notes
    -----
    isinf and other ufunc sometimes return a NotImplementedType object instead
    of raising any exception. This function is a wrapper to make sure an
    exception is always raised.

    This should be removed once this problem is solved at the Ufunc level.r)�isinfrPrQ)rRz!isinf not supported for this typeN)rHrTrPrIrJrKrC)rLrTrPrMr:r:r;�gisinf�srUzNnumpy.testing.rand is deprecated in numpy 1.11. Use numpy.random.rand instead.)�messagecGsNddl}ddlm}m}|||�}|j}x tt|��D]}|��||<q6W|S)z�Returns an array of random numbers with the given shape.

    This only uses the standard library, so it is useful for testing purposes.
    rN)�zeros�float64)�randomrHrWrXZflat�range�len)�argsrYrWrX�results�f�ir:r:r;r"�s
�nt���c	Cs�ddl}|dkr|j}|�|||d||f�}|��}z<|�||�}	z|�|�|�|	|�\}
}|S|�|	�XWd|�|�XdS)Nr)	�win32pdh�PDH_FMT_LONGZMakeCounterPathZ	OpenQueryZ
AddCounterZCollectQueryDataZGetFormattedCounterValueZ
RemoveCounterZ
CloseQuery)�objectZcounter�instanceZinum�format�machinerb�pathZhqZhcrJrEr:r:r;�GetPerformanceAttributes�s

ri�pythoncCsddl}tdd|||jd�S)NrZProcessz
Virtual Bytes)rbrirc)ZprocessNamererbr:r:r;r�s�Zlinuxz
/proc/%s/statcCs<y,t|d�}|���d�}|��t|d�SdSdS)zM
        Return virtual memory size in bytes of the running python.

        �r� �N)�open�readline�split�close�int)�_proc_pid_statr^�lr:r:r;r�s
cCst�dS)zK
        Return memory usage of running python. [Not implemented]

        N)�NotImplementedErrorr:r:r:r;r�scCsjddl}|s|�|���y,t|d�}|���d�}|��t|d�Std|��|d�SdS)z�
        Return number of jiffies elapsed.

        Return number of jiffies (1/100ths of a second) that this
        process has been scheduled in user mode. See man 5 proc.

        rNrlrm�
�d)�time�appendrorprqrrrs)rt�
_load_timeryr^rur:r:r;r�s	
cCs2ddl}|s|�|���td|��|d�S)z�
        Return number of jiffies elapsed.

        Return number of jiffies (1/100ths of a second) that this
        process has been scheduled in user mode. See man 5 proc.

        rNrx)ryrzrs)r{ryr:r:r;r�s�Items are not equal:T�ZACTUALZDESIRED�cCsd|g}|rN|�d�dkrDt|�dt|�krD|dd|g}n
|�|�|�r
x�t|�D]�\}}t|t�r~tt|d�}	nt}	y|	|�}
Wn4t	k
r�}zd�
t|�j|�}
Wdd}~XYnX|
�
d�dkr�d�|
��dd��}
|
d	7}
|�d
|||
f�q^Wd�|�S)N�
ra�Orrm)�	precisionz[repr failed for <{}>: {}]rz...z %s: %s)�findr[rz�	enumeraterIrrr
�repr�	ExceptionrfrJr6�count�join�
splitlines)Zarrays�err_msg�headerr%�namesr�r@r_�aZr_funcrl�excr:r:r;rs&
"

$c
CsBd}t|t�r�t|t�s(ttt|����tt|�t|�||�xF|��D]:\}}||krdtt|���t||||d||f|�qHWdSt|tt	f�r�t|tt	f�r�tt|�t|�||�x2t
t|��D]"}t||||d||f|�q�WdSddlm}m
}m}	ddlm}
m}m}t||��s4t||��rBt||||�St||g||d�}
y|
|��pf|
|�}Wntk
�r�d	}YnX|�r|
|��r�||�}||�}n|}d}|
|��r�||�}||�}n|}d}yt||�t||�Wntk
�r
t|
��YnX||�||�k�r&t|
��y�t|��r<t|��s�t|�}t|�}|�sX|�rn|�rd|�s�t|
��n||k�s�t|
��dS|dk�r�|dk�r�|	|�|	|�k�s�t|
��Wntttfk
�r�YnXy<t|�t|�k�rt|�jjt|�jjk�rdSt|
��Wntttfk
�r*YnX||k�s>t|
��dS)
aa
    Raises an AssertionError if two objects are not equal.

    Given two objects (scalars, lists, tuples, dictionaries or numpy arrays),
    check that all elements of these objects are equal. An exception is raised
    at the first conflicting values.

    Parameters
    ----------
    actual : array_like
        The object to check.
    desired : array_like
        The expected object.
    err_msg : str, optional
        The error message to be printed in case of failure.
    verbose : bool, optional
        If True, the conflicting values are appended to the error message.

    Raises
    ------
    AssertionError
        If actual and desired are not equal.

    Examples
    --------
    >>> np.testing.assert_equal([4,5], [4,6])
    ...
    <type 'exceptions.AssertionError'>:
    Items are not equal:
    item=1
     ACTUAL: 5
     DESIRED: 6

    Tz	key=%r
%sNz
item=%r
%sr)r�isscalar�signbit)�iscomplexobj�real�imag)r%F)rI�dictrDr�rJrr[�items�list�tuplerZrHrr�r��	numpy.libr�r�r�rr�
ValueErrorrSrNrCrvrr�dtype)�actual�desiredr�r%rF�kr_rr�r�r�r�r�r@�
usecomplex�actualr�actuali�desiredr�desirediZisdesnanZisactnanr:r:r;r"s�#

""








cCs`d}ddl}||ks\t�}|�|�|�d�|�||�|�d�|�||�t|����dS)a�
    Test if two objects are equal, and print an error message if test fails.

    The test is performed with ``actual == desired``.

    Parameters
    ----------
    test_string : str
        The message supplied to AssertionError.
    actual : object
        The object to test for equality against `desired`.
    desired : object
        The expected result.

    Examples
    --------
    >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 1])
    >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 2])
    Traceback (most recent call last):
    ...
    AssertionError: Test XYZ of func xyz failed
    ACTUAL:
    [0, 1]
    DESIRED:
    [0, 2]

    TrNz failed
ACTUAL: 
z
DESIRED: 
)�pprintr�writerD�getvalue)Ztest_stringr�r�rFr�r@r:r:r;r �s


�c	s�d}ddlm}ddlm}m}m}	y|��p4|��}
Wntk
rPd}
YnX�����fdd�}|
r�|��r�|��}|	��}
n�}d}
|��r�|��}|	��}n�}d}y t||�d�t|
|�d�Wntk
r�t|���YnXt	�|t
tf��st	�|t
tf��r t�����Sydt
���r6t
���s�t���sJt���rjt���r^t���s~t|���n��k�s~t|���d	SWnttfk
�r�YnXt���d
d�k�r�t|���d	S)ap
    Raises an AssertionError if two items are not equal up to desired
    precision.

    .. note:: It is recommended to use one of `assert_allclose`,
              `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
              instead of this function for more consistent floating point
              comparisons.

    The test verifies that the elements of ``actual`` and ``desired`` satisfy.

        ``abs(desired-actual) < 1.5 * 10**(-decimal)``

    That is a looser test than originally documented, but agrees with what the
    actual implementation in `assert_array_almost_equal` did up to rounding
    vagaries. An exception is raised at conflicting values. For ndarrays this
    delegates to assert_array_almost_equal

    Parameters
    ----------
    actual : array_like
        The object to check.
    desired : array_like
        The expected object.
    decimal : int, optional
        Desired precision, default is 7.
    err_msg : str, optional
        The error message to be printed in case of failure.
    verbose : bool, optional
        If True, the conflicting values are appended to the error message.

    Raises
    ------
    AssertionError
      If actual and desired are not equal up to specified precision.

    See Also
    --------
    assert_allclose: Compare two array_like objects for equality with desired
                     relative and/or absolute precision.
    assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal

    Examples
    --------
    >>> import numpy.testing as npt
    >>> npt.assert_almost_equal(2.3333333333333, 2.33333334)
    >>> npt.assert_almost_equal(2.3333333333333, 2.33333334, decimal=10)
    ...
    <type 'exceptions.AssertionError'>:
    Items are not equal:
     ACTUAL: 2.3333333333333002
     DESIRED: 2.3333333399999998

    >>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]),
    ...                         np.array([1.0,2.33333334]), decimal=9)
    ...
    <type 'exceptions.AssertionError'>:
    Arrays are not almost equal
    <BLANKLINE>
    (mismatch 50.0%)
     x: array([ 1.        ,  2.33333333])
     y: array([ 1.        ,  2.33333334])

    Tr)r)r�r�r�Fcsd�}t��g��|d�S)Nz*Arrays are not almost equal to %d decimals)r%r�)r)r�)r��decimalr�r�r%r:r;�_build_err_msgsz+assert_almost_equal.<locals>._build_err_msg)r�Ng�?g$@)rHrr�r�r�r�r�rrDrIr�r�rrSrNrvrC�abs)r�r�r�r�r%rFrr�r�r�r�r�r�r�r�r�r:)r�r�r�r�r%r;r�sNA




c	Cs|d}ddl}tt||f�\}}||kr*dS|jdd��6d|�|�|�|�}|�d|�|�|���}WdQRXy||}Wntk
r�d}YnXy||}	Wntk
r�d}	YnXt	||g|d	||d
�}
y\t
|�r�t
|��s0t|�s�t|��rt|��rt|��s,t|
��n||k�s,t|
��dSWnt
tfk
�rLYnX|�||	�|�d|d�k�rxt|
��dS)
aU
    Raises an AssertionError if two items are not equal up to significant
    digits.

    .. note:: It is recommended to use one of `assert_allclose`,
              `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
              instead of this function for more consistent floating point
              comparisons.

    Given two numbers, check that they are approximately equal.
    Approximately equal is defined as the number of significant digits
    that agree.

    Parameters
    ----------
    actual : scalar
        The object to check.
    desired : scalar
        The expected object.
    significant : int, optional
        Desired precision, default is 7.
    err_msg : str, optional
        The error message to be printed in case of failure.
    verbose : bool, optional
        If True, the conflicting values are appended to the error message.

    Raises
    ------
    AssertionError
      If actual and desired are not equal up to specified precision.

    See Also
    --------
    assert_allclose: Compare two array_like objects for equality with desired
                     relative and/or absolute precision.
    assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal

    Examples
    --------
    >>> np.testing.assert_approx_equal(0.12345677777777e-20, 0.1234567e-20)
    >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345671e-20,
                                       significant=8)
    >>> np.testing.assert_approx_equal(0.12345670e-20, 0.12345672e-20,
                                       significant=8)
    ...
    <type 'exceptions.AssertionError'>:
    Items are not equal to 8 significant digits:
     ACTUAL: 1.234567e-021
     DESIRED: 1.2345672000000001e-021

    the evaluated condition that raises the exception is

    >>> abs(0.12345670e-20/1e-21 - 0.12345672e-20/1e-21) >= 10**-(8-1)
    True

    TrNrQ)rRg�?�
gz-Items are not equal to %d significant digits:)r�r%g$@r=)�numpy�map�floatrPr�ZpowerZfloorZlog10�ZeroDivisionErrorrrSrNrDrCrv)r�r�Zsignificantr�r%rF�npZscaleZ
sc_desiredZ	sc_actualr@r:r:r;rFs@9"




"�c	!sXd}	ddlm}
m}m}m}
m}|
�ddd��|
�ddd��dd�}dd	�}d������fdd�	}�y��jd
kp��jd
kp��j�jk}|s�t��g�d�j�jf��d�d�}t|��|���r�|���r�d}}|�r|��|��}}|
|��p|
|�}|�r|||d
d�|�rz|��|��}}|
|��p>|
|�}|�rz|�|
k�|
kdd�|�|k�|kdd�|�r�|�r��||B��||B�n6|�r��|��|�n|�rڈ|��|��j	dk�rtdSn�|���rt|���rt|�rt�j
j�j
jk�rtt��t��}}|
|��s>|
|��rL|||dd�|
|��s`|
|��rt�|��|�|���}t
|t��r�|}dg}n|��}|��}|��}|�s�dd|�d�t|�}t��g�d|f��d�d�}|�s�t|��WnRtk
�rRddl}|��} d| �f�t��g���d�d�}t|��YnXdS)NTr)rrGrT�any�infF)�copy�subokcSs|jjdkS)Nz?bhilqpBHILQPefdgFDG)r��char)rLr:r:r;�isnumber�sz&assert_array_compare.<locals>.isnumbercSs|jjdkS)NZMm)r�r�)rLr:r:r;�istime�sz$assert_array_compare.<locals>.istime�nancsPyt||�Wn<tk
rJt��g�d|��d�d�}t|��YnXdS)zTHandling nan/inf: check that x and y have the nan/inf at the same
        locations.z
x and y %s location mismatch:)rL�y)r%r�r�r�N)rrDr)Zx_idZy_id�hasvalr@)r�r�r�r%rLr�r:r;�chk_same_position�s

z/assert_array_compare.<locals>.chk_same_positionr:z
(shapes %s, %s mismatch))rLr�)r%r�r�r�)r�z+infz-infZNaTrxgY@r=z
(mismatch %s%%)zerror during assertion:

%s

%s)r�)rHrrGrTr�r��shaperrD�sizer�rJrrI�boolZravel�all�tolistr�r[r��	traceback�
format_exc)!Z
comparisonrLr�r�r%r�r��	equal_nan�	equal_infrFrrGrTr�r�r�r�r�Zcondr@Zhas_nanZhas_infZx_isnanZy_isnanZx_isinfZy_isinfZx_isnatZy_isnatrEZreduced�matchr�Zefmtr:)r�r�r�r%rLr�r;�assert_array_compare�s� 










r�cCsd}ttj||||dd�dS)a,
    Raises an AssertionError if two array_like objects are not equal.

    Given two array_like objects, check that the shape is equal and all
    elements of these objects are equal. An exception is raised at
    shape mismatch or conflicting values. In contrast to the standard usage
    in numpy, NaNs are compared like numbers, no assertion is raised if
    both objects have NaNs in the same positions.

    The usual caution for verifying equality with floating point numbers is
    advised.

    Parameters
    ----------
    x : array_like
        The actual object to check.
    y : array_like
        The desired, expected object.
    err_msg : str, optional
        The error message to be printed in case of failure.
    verbose : bool, optional
        If True, the conflicting values are appended to the error message.

    Raises
    ------
    AssertionError
        If actual and desired objects are not equal.

    See Also
    --------
    assert_allclose: Compare two array_like objects for equality with desired
                     relative and/or absolute precision.
    assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal

    Examples
    --------
    The first assert does not raise an exception:

    >>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
    ...                               [np.exp(0),2.33333, np.nan])

    Assert fails with numerical inprecision with floats:

    >>> np.testing.assert_array_equal([1.0,np.pi,np.nan],
    ...                               [1, np.sqrt(np.pi)**2, np.nan])
    ...
    <type 'exceptions.ValueError'>:
    AssertionError:
    Arrays are not equal
    <BLANKLINE>
    (mismatch 50.0%)
     x: array([ 1.        ,  3.14159265,         NaN])
     y: array([ 1.        ,  3.14159265,         NaN])

    Use `assert_allclose` or one of the nulp (number of floating point values)
    functions for these cases instead:

    >>> np.testing.assert_allclose([1.0,np.pi,np.nan],
    ...                            [1, np.sqrt(np.pi)**2, np.nan],
    ...                            rtol=1e-10, atol=0)

    TzArrays are not equal)r�r%r�N)r��operator�__eq__)rLr�r�r%rFr:r:r;rs?c	snd}ddlm}m�m�m�m�ddlm�ddlm	��������fdd�}t
|||||d��d	�d
S)a�	
    Raises an AssertionError if two objects are not equal up to desired
    precision.

    .. note:: It is recommended to use one of `assert_allclose`,
              `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
              instead of this function for more consistent floating point
              comparisons.

    The test verifies identical shapes and that the elements of ``actual`` and
    ``desired`` satisfy.

        ``abs(desired-actual) < 1.5 * 10**(-decimal)``

    That is a looser test than originally documented, but agrees with what the
    actual implementation did up to rounding vagaries. An exception is raised
    at shape mismatch or conflicting values. In contrast to the standard usage
    in numpy, NaNs are compared like numbers, no assertion is raised if both
    objects have NaNs in the same positions.

    Parameters
    ----------
    x : array_like
        The actual object to check.
    y : array_like
        The desired, expected object.
    decimal : int, optional
        Desired precision, default is 6.
    err_msg : str, optional
      The error message to be printed in case of failure.
    verbose : bool, optional
        If True, the conflicting values are appended to the error message.

    Raises
    ------
    AssertionError
        If actual and desired are not equal up to specified precision.

    See Also
    --------
    assert_allclose: Compare two array_like objects for equality with desired
                     relative and/or absolute precision.
    assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal

    Examples
    --------
    the first assert does not raise an exception

    >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan],
                                             [1.0,2.333,np.nan])

    >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan],
    ...                                      [1.0,2.33339,np.nan], decimal=5)
    ...
    <type 'exceptions.AssertionError'>:
    AssertionError:
    Arrays are not almost equal
    <BLANKLINE>
    (mismatch 50.0%)
     x: array([ 1.     ,  2.33333,      NaN])
     y: array([ 1.     ,  2.33339,      NaN])

    >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan],
    ...                                      [1.0,2.33333, 5], decimal=5)
    <type 'exceptions.ValueError'>:
    ValueError:
    Arrays are not almost equal
     x: array([ 1.     ,  2.33333,      NaN])
     y: array([ 1.     ,  2.33333,  5.     ])

    Tr)�around�number�float_�result_typer)�
issubdtype)r�c	s�yt�t|��s�t|��rrt|�}t|�}||k��s:dS|j|jkrRdkr^nn||kS||}||}Wnttfk
r�YnX�|d�}�||ddd�}t||�}�|j��s�|���}|dd�kS)NFr=g�?T)r�r�r�g�?g$@)rUr�r�rCrvr�r�Zastype)rLr�ZxinfidZyinfidr��z)rr�r�r��npanyr�r�r:r;�compare�s$


z*assert_array_almost_equal.<locals>.comparez*Arrays are not almost equal to %d decimals)r�r%r�r�N)rHr�r�r�r�rZnumpy.core.numerictypesr�Znumpy.core.fromnumericr�r�)rLr�r�r�r%rFr�r�r:)rr�r�r�r�r�r�r;rYsHc	Cs d}ttj||||ddd�dS)aF
    Raises an AssertionError if two array_like objects are not ordered by less
    than.

    Given two array_like objects, check that the shape is equal and all
    elements of the first object are strictly smaller than those of the
    second object. An exception is raised at shape mismatch or incorrectly
    ordered values. Shape mismatch does not raise if an object has zero
    dimension. In contrast to the standard usage in numpy, NaNs are
    compared, no assertion is raised if both objects have NaNs in the same
    positions.



    Parameters
    ----------
    x : array_like
      The smaller object to check.
    y : array_like
      The larger object to compare.
    err_msg : string
      The error message to be printed in case of failure.
    verbose : bool
        If True, the conflicting values are appended to the error message.

    Raises
    ------
    AssertionError
      If actual and desired objects are not equal.

    See Also
    --------
    assert_array_equal: tests objects for equality
    assert_array_almost_equal: test objects for equality up to precision



    Examples
    --------
    >>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1.1, 2.0, np.nan])
    >>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1, 2.0, np.nan])
    ...
    <type 'exceptions.ValueError'>:
    Arrays are not less-ordered
    (mismatch 50.0%)
     x: array([  1.,   1.,  NaN])
     y: array([  1.,   2.,  NaN])

    >>> np.testing.assert_array_less([1.0, 4.0], 3)
    ...
    <type 'exceptions.ValueError'>:
    Arrays are not less-ordered
    (mismatch 50.0%)
     x: array([ 1.,  4.])
     y: array(3)

    >>> np.testing.assert_array_less([1.0, 2.0, 3.0], [4])
    ...
    <type 'exceptions.ValueError'>:
    Arrays are not less-ordered
    (shapes (3,), (1,) mismatch)
     x: array([ 1.,  2.,  3.])
     y: array([4])

    TzArrays are not less-orderedF)r�r%r�r�N)r�r��__lt__)rLr�r�r%rFr:r:r;r�s
BcCst||�dS)N)�exec)Zastrr�r:r:r;r$scCs�d}ddl}t|t�s&ttt|����t|t�s@ttt|����t�d|d|tj�r\dSt	|�
��|�d�|�d���}g}x�|�rn|�
d�}|�d�r�q�|�d��r`|g}|�
d�}|�d	�r�|�|�|�
d�}|�d
�s�tt|���|�|�|�r,|�
d�}	|	�d	��r |�|	�n|�d|	�t�d|dd�d|dd���rTq�|�|�q�tt|���q�W|�szdSdd
�|���}
||k�r�t|
��dS)a�
    Test if two strings are equal.

    If the given strings are equal, `assert_string_equal` does nothing.
    If they are not equal, an AssertionError is raised, and the diff
    between the strings is shown.

    Parameters
    ----------
    actual : str
        The string to test for equality against the expected string.
    desired : str
        The expected string.

    Examples
    --------
    >>> np.testing.assert_string_equal('abc', 'abc')
    >>> np.testing.assert_string_equal('abc', 'abcd')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ...
    AssertionError: Differences in strings:
    - abc+ abcd?    +

    TrNz\Az\Zr=z  z- z? z+ �zDifferences in strings:
%srB)�difflibrI�strrDr�rJ�rer��Mr�ZDifferr�r��pop�
startswithrz�insert�extendr��rstrip)r�r�rFr��diffZ	diff_listZd1ruZd2Zd3r@r:r:r;rsL

 








&

cs�ddlm}ddl}|dkr0t�d�}|jd}tj�tj�	|��d}|||�}|�
��|�}|jdd�}g�|r��fdd	�}	nd}	x|D]}
|j
|
|	d
�q�W|jdkr�|r�tdd�����dS)
aT
    Run doctests found in the given file.

    By default `rundocs` raises an AssertionError on failure.

    Parameters
    ----------
    filename : str
        The path to the file for which the doctests are run.
    raise_on_error : bool
        Whether to raise an AssertionError when a doctest fails. Default is
        True.

    Notes
    -----
    The doctests can be run by the user/developer by adding the ``doctests``
    argument to the ``test()`` call. For example, to run all tests (including
    doctests) for `numpy.lib`:

    >>> np.lib.test(doctests=True) #doctest: +SKIP
    r)�npy_load_moduleNr=�__file__F)r%cs
��|�S)N)rz)�s)r@r:r;�<lambda>{�zrundocs.<locals>.<lambda>)�outzSome doctests failed:
%sr)Znumpy.compatr��doctest�sys�	_getframe�	f_globals�osrh�splitext�basenameZ
DocTestFinderr�Z
DocTestRunner�runZfailuresrDr�)�filenameZraise_on_errorr�r�r^�name�mZtestsZrunnerr�Ztestr:)r@r;r#Xs"



cOst�}|jj||�S)N)rA�toolsr!)r\�kwargsr>r:r:r;r!�scOsd}t�}|jj||�S)a�
    assert_raises(exception_class, callable, *args, **kwargs)
    assert_raises(exception_class)

    Fail unless an exception of class exception_class is thrown
    by callable when invoked with arguments args and keyword
    arguments kwargs. If a different type of exception is
    thrown, it will not be caught, and the test case will be
    deemed to have suffered an error, exactly as for an
    unexpected exception.

    Alternatively, `assert_raises` can be used as a context manager:

    >>> from numpy.testing import assert_raises
    >>> with assert_raises(ZeroDivisionError):
    ...     1 / 0

    is equivalent to

    >>> def div(x, y):
    ...     return x / y
    >>> assert_raises(ZeroDivisionError, div, 1, 0)

    T)rAr�r)r\r�rFr>r:r:r;r�scOs:d}t�}tjjdkr |jj}n|jj}|||f|�|�S)aY
    assert_raises_regex(exception_class, expected_regexp, callable, *args,
                        **kwargs)
    assert_raises_regex(exception_class, expected_regexp)

    Fail unless an exception of class exception_class and with message that
    matches expected_regexp is thrown by callable when invoked with arguments
    args and keyword arguments kwargs.

    Alternatively, can be used as a context manager like `assert_raises`.

    Name of this function adheres to Python 3.2+ reference, but should work in
    all versions down to 2.6.

    Notes
    -----
    .. versionadded:: 1.9.0

    Tr)rAr��version_info�majorr�r)Zassert_raises_regexp)Zexception_classZexpected_regexpr\r�rFr>�funcnamer:r:r;r)�s
c	s�|dkrt�dtj�}n
t�|�}|j}ddlm��fdd�|��D�}xd|D]\}yt|d�rj|j	}n|j
}Wntk
r�wRYnX|�|�rR|�
d�sRt||||��qRWdS)	a
    Apply a decorator to all methods in a class matching a regular expression.

    The given decorator is applied to all public methods of `cls` that are
    matched by the regular expression `testmatch`
    (``testmatch.search(methodname)``). Methods that are private, i.e. start
    with an underscore, are ignored.

    Parameters
    ----------
    cls : class
        Class whose methods to decorate.
    decorator : function
        Decorator to apply to methods
    testmatch : compiled regexp or str, optional
        The regular expression. Default value is None, in which case the
        nose default (``re.compile(r'(?:^|[\b_\.%s-])[Tt]est' % os.sep)``)
        is used.
        If `testmatch` is a string, it is compiled to a regular expression
        first.

    Nz(?:^|[\\b_\\.%s-])[Tt]estr)�
isfunctioncsg|]}�|�r|�qSr:r:)�.0�_m)r�r:r;�
<listcomp>�sz$decorate_methods.<locals>.<listcomp>�compat_func_name�_)r��compiler��sep�__dict__�inspectr��values�hasattrr�r6�AttributeError�searchr��setattr)�clsZ	decoratorZ	testmatchZcls_attr�methodsZfunctionr�r:)r�r;r�s 



r=c	Csft�d�}|j|j}}t|d|d�}d}t�}x ||krR|d7}t|||�q4Wt�|}d|S)aE
    Return elapsed time for executing code in the namespace of the caller.

    The supplied code string is compiled with the Python builtin ``compile``.
    The precision of the timing is 10 milli-seconds. If the code will execute
    fast on this timescale, it can be executed many times to get reasonable
    timing accuracy.

    Parameters
    ----------
    code_str : str
        The code to be timed.
    times : int, optional
        The number of times the code is executed. Default is 1. The code is
        only compiled once.
    label : str, optional
        A label to identify `code_str` with. This is passed into ``compile``
        as the second argument (for run-time error messages).

    Returns
    -------
    elapsed : float
        Total elapsed time in seconds for executing `code_str` `times` times.

    Examples
    --------
    >>> etime = np.testing.measure('for i in range(1000): np.sqrt(i**2)',
    ...                            times=times)
    >>> print("Time for a single execution : ", etime / times, "s")
    Time for a single execution :  0.005 s

    r=zTest name: %s r�rg{�G�z�?)r�r��f_localsr�r�rr�)	Zcode_str�timesZlabel�frameZlocsZglobs�coder_�elapsedr:r:r;r&�s!


cCshtsdSddl}|�d��dd�}|}d}t�|�}xtd�D]}|||�}q>Wtt�|�|k�~dS)zg
    Check that ufuncs don't mishandle refcount of object `1`.
    Used in a few regression tests.
    TrNi'rxr=�)r4r�rZreshaper�r<rZr')�opr��b�cr_Zrc�j�dr:r:r;�_assert_valid_refcount(s
r�H�����z>c
	s^d}ddl�����fdd�}��|���|�}}d��f}	t|||t|�||	�d�dS)aq
    Raises an AssertionError if two objects are not equal up to desired
    tolerance.

    The test is equivalent to ``allclose(actual, desired, rtol, atol)``.
    It compares the difference between `actual` and `desired` to
    ``atol + rtol * abs(desired)``.

    .. versionadded:: 1.5.0

    Parameters
    ----------
    actual : array_like
        Array obtained.
    desired : array_like
        Array desired.
    rtol : float, optional
        Relative tolerance.
    atol : float, optional
        Absolute tolerance.
    equal_nan : bool, optional.
        If True, NaNs will compare equal.
    err_msg : str, optional
        The error message to be printed in case of failure.
    verbose : bool, optional
        If True, the conflicting values are appended to the error message.

    Raises
    ------
    AssertionError
        If actual and desired are not equal up to specified precision.

    See Also
    --------
    assert_array_almost_equal_nulp, assert_array_max_ulp

    Examples
    --------
    >>> x = [1e-5, 1e-3, 1e-1]
    >>> y = np.arccos(np.cos(x))
    >>> assert_allclose(x, y, rtol=1e-5, atol=0)

    TrNcs�jjj||���d�S)N)�rtol�atolr�)ZcoreZnumericZisclose)rLr�)rr�r�rr:r;r�lsz assert_allclose.<locals>.comparez'Not equal to tolerance rtol=%g, atol=%g)r�r%r�r�)r�Z
asanyarrayr�r�)
r�r�rrr�r�r%rFr�r�r:)rr�r�rr;r-<s-c
Cs�d}ddl}|�|�}|�|�}||�|�||k||��}|�|�||�|k�s�|�|�sh|�|�rrd|}n|�t||��}	d||	f}t|��dS)a�
    Compare two arrays relatively to their spacing.

    This is a relatively robust method to compare two arrays whose amplitude
    is variable.

    Parameters
    ----------
    x, y : array_like
        Input arrays.
    nulp : int, optional
        The maximum number of unit in the last place for tolerance (see Notes).
        Default is 1.

    Returns
    -------
    None

    Raises
    ------
    AssertionError
        If the spacing between `x` and `y` for one or more elements is larger
        than `nulp`.

    See Also
    --------
    assert_array_max_ulp : Check that all items of arrays differ in at most
        N Units in the Last Place.
    spacing : Return the distance between x and the nearest adjacent number.

    Notes
    -----
    An assertion is raised if the following condition is not met::

        abs(x - y) <= nulps * spacing(maximum(abs(x), abs(y)))

    Examples
    --------
    >>> x = np.array([1., 1e-10, 1e-20])
    >>> eps = np.finfo(x.dtype).eps
    >>> np.testing.assert_array_almost_equal_nulp(x, x*eps/2 + x)

    >>> np.testing.assert_array_almost_equal_nulp(x, x*eps + x)
    Traceback (most recent call last):
      ...
    AssertionError: X and Y are not equal to 1 ULP (max is 2)

    TrNzX and Y are not equal to %d ULPz+X and Y are not equal to %d ULP (max is %g))	r�r�Zspacing�wherer�r��max�	nulp_diffrD)
rLr�ZnulprFr�ZaxZay�refr@Zmax_nulpr:r:r;r(vs1


cCs6d}ddl}t|||�}|�||k�s2td|��|S)a�
    Check that all items of arrays differ in at most N Units in the Last Place.

    Parameters
    ----------
    a, b : array_like
        Input arrays to be compared.
    maxulp : int, optional
        The maximum number of units in the last place that elements of `a` and
        `b` can differ. Default is 1.
    dtype : dtype, optional
        Data-type to convert `a` and `b` to if given. Default is None.

    Returns
    -------
    ret : ndarray
        Array containing number of representable floating point numbers between
        items in `a` and `b`.

    Raises
    ------
    AssertionError
        If one or more elements differ by more than `maxulp`.

    See Also
    --------
    assert_array_almost_equal_nulp : Compare two arrays relatively to their
        spacing.

    Examples
    --------
    >>> a = np.linspace(0., 1., 100)
    >>> res = np.testing.assert_array_max_ulp(a, np.arcsin(np.sin(a)))

    TrNz(Arrays are not almost equal up to %g ULP)r�rr�rD)r�rZmaxulpr�rFr�Zretr:r:r;r*�s$cs�ddl�|r*�j||d�}�j||d�}n��|�}��|�}��||�}��|�s^��|�rftd���j||d�}�j||d�}|j|jks�td|j|jf���fdd�}t|�}t|�}||||�S)a�For each item in x and y, return the number of representable floating
    points between them.

    Parameters
    ----------
    x : array_like
        first input array
    y : array_like
        second input array
    dtype : dtype, optional
        Data-type to convert `x` and `y` to if given. Default is None.

    Returns
    -------
    nulp : array_like
        number of representable floating point numbers between each item in x
        and y.

    Examples
    --------
    # By definition, epsilon is the smallest number such as 1 + eps != 1, so
    # there should be exactly one ULP between 1 and 1 + eps
    >>> nulp_diff(1, 1 + np.finfo(x.dtype).eps)
    1.0
    rN)r�z'_nulp not implemented for complex arrayz+x and y do not have the same shape: %s - %scs�j|||d�}��|�S)N)r�)rr�)�rx�ry�vdtr�)r�r:r;�_diffsznulp_diff.<locals>._diff)r�rZcommon_typer�rvr�r��integer_repr)rLr�r��trrrr:)r�r;r�s$

rcCsB|�|�}|jdks.|||dk||dk<n|dkr>||}|S)Nr=r)Zviewr�)rLr�comprr:r:r;�
_integer_reprs

rcCsZddl}|j|jkr(t||j|�d��S|j|jkrHt||j|�d��Std|j��dS)zQReturn the signed-magnitude interpretation of the binary representation of
    x.rNi�l����zUnsupported dtype %s)r�r�r
rZint32rXZint64r�)rLr�r:r:r;r'src@s&eZdZdZdZddd�Zdd�ZdS)	�WarningMessagez�
    Holds the result of a single showwarning() call.

    Deprecated in 1.8.0

    Notes
    -----
    `WarningMessage` is copied from the Python 2.6 warnings module,
    so it can be used in NumPy with older Python versions.

    )rV�categoryr��lineno�file�lineNc	Cs>t�}x|jD]}t||||�qW|r4|j|_nd|_dS)N)�locals�_WARNING_DETAILSrr6�_category_name)	�selfrVr r�r!r"r#Zlocal_values�attrr:r:r;�__init__Fs
zWarningMessage.__init__cCsd|j|j|j|j|jfS)NzD{message : %r, category : %r, filename : %r, lineno : %s, line : %r})rVr&r�r!r#)r'r:r:r;�__str__PszWarningMessage.__str__)NN)r6r7r8r9r%r)r*r:r:r:r;r5s

	rc@s*eZdZdZd
dd�Zdd�Zdd	�ZdS)�WarningManagera�
    A context manager that copies and restores the warnings filter upon
    exiting the context.

    The 'record' argument specifies whether warnings should be captured by a
    custom implementation of ``warnings.showwarning()`` and be appended to a
    list returned by the context manager. Otherwise None is returned by the
    context manager. The objects appended to the list are arguments whose
    attributes mirror the arguments to ``showwarning()``.

    The 'module' argument is to specify an alternative module to the module
    named 'warnings' and imported under that name. This argument is only useful
    when testing the warnings module itself.

    Deprecated in 1.8.0

    Notes
    -----
    `WarningManager` is a copy of the ``catch_warnings`` context manager
    from the Python 2.6 warnings module, with slight modifications.
    It is copied so it can be used in NumPy with older Python versions.

    FNcCs,||_|dkrtjd|_n||_d|_dS)N�warningsF)�_recordr��modules�_module�_entered)r'�record�moduler:r:r;r)os
zWarningManager.__init__csh|jrtd|��d|_|jj|_|jdd�|j_|jj|_|jr`g��fdd�}||j_�SdSdS)NzCannot enter %r twiceTcs��t||��dS)N)rzr)r\r�)�logr:r;�showwarning�sz-WarningManager.__enter__.<locals>.showwarning)r0�RuntimeErrorr/�filters�_filtersr4�_showwarningr-)r'r4r:)r3r;�	__enter__ws

zWarningManager.__enter__cCs*|jstd|��|j|j_|j|j_dS)Nz%Cannot exit %r without entering first)r0r5r7r/r6r8r4)r'r:r:r;�__exit__�s
zWarningManager.__exit__)FN)r6r7r8r9r)r9r:r:r:r:r;r+Vs
r+c	csVd}t��B}|�|�}dVt|�dksH|dk	r8d|nd}td|��WdQRXdS)NTrz when calling %srBzNo warning raised)r5r1r[rD)�
warning_classr�rFZsupru�name_strr:r:r;�_assert_warns_context�s
r=c	OsD|st|�S|d}|dd�}t||jd��|||�SQRXdS)a�
    Fail unless the given callable throws the specified warning.

    A warning of class warning_class should be thrown by the callable when
    invoked with arguments args and keyword arguments kwargs.
    If a different type of warning is thrown, it will not be caught.

    If called with all arguments other than the warning class omitted, may be
    used as a context manager:

        with assert_warns(SomeWarning):
            do_something()

    The ability to be used as a context manager is new in NumPy v1.11.0.

    .. versionadded:: 1.4.0

    Parameters
    ----------
    warning_class : class
        The class defining the warning that `func` is expected to throw.
    func : callable
        The callable to test.
    \*args : Arguments
        Arguments passed to `func`.
    \*\*kwargs : Kwargs
        Keyword arguments passed to `func`.

    Returns
    -------
    The value returned by `func`.

    rr=N)r�)r=r6)r;r\r��funcr:r:r;r+�s"c	cs`d}tjdd��F}t�d�dVt|�dkrR|dk	r>d|nd}td||f��WdQRXdS)NT)r1�alwaysrz when calling %srBzGot warnings%s: %s)r,�catch_warnings�simplefilterr[rD)r�rFrur<r:r:r;�_assert_no_warnings_context�s
rBc	Os@|s
t�S|d}|dd�}t|jd��|||�SQRXdS)a:
    Fail if the given callable produces any warnings.

    If called with all arguments omitted, may be used as a context manager:

        with assert_no_warnings():
            do_something()

    The ability to be used as a context manager is new in NumPy v1.11.0.

    .. versionadded:: 1.7.0

    Parameters
    ----------
    func : callable
        The callable to test.
    \*args : Arguments
        Arguments passed to `func`.
    \*\*kwargs : Kwargs
        Keyword arguments passed to `func`.

    Returns
    -------
    The value returned by `func`.

    rr=N)r�)rBr6)r\r�r>r:r:r;r,�s�binary�c
#s�d}d}�x�td�D�]���x�t�dt�d|��D�]��|dk�r|���fdd�}t�f�d��d	�}||�|����d
ffV|�}|||����dffV|dd	�|�d	d
�|�d��d�d
ffV|d	d
�|�dd	�|��d�d�d
ffV|�d	d
�|�dd	�|��d�d�dffV|�dd	�|�d	d
�|�d��d�dffV|dkr6���fdd�}���fdd�}	t�f�d��d	�}||�|	�|�����d
ffV|�}|||	�|�����dffV|	�}||�||�����dffV|dd	�|�d	d
�|	�d	d
�|�d���d�d
ffV|d	d
�|�dd	�|	�d	d
�|��d��d�d
ffV|d	d
�|�d	d
�|	�dd	�|���d�d�d
ffV|�dd	�|�d	d
�|	�d	d
�|�d���d�dffV|�d	d
�|�dd	�|	�d	d
�|��d��d�dffV|�d	d
�|�d	d
�|	�dd	�|���d�d�dffVq6WqWd	S)a�
    generator producing data with different alignment and offsets
    to test simd vectorization

    Parameters
    ----------
    dtype : dtype
        data type to produce
    type : string
        'unary': create data for unary operations, creates one input
                 and output array
        'binary': create data for unary operations, creates two input
                 and output array
    max_size : integer
        maximum size of data to produce

    Returns
    -------
    if type is 'unary' yields one output, one input array and a message
    containing information on the data
    if type is 'binary' yields one output array, two input array and a message
    containing information on the data

    z,unary offset=(%d, %d), size=%d, dtype=%r, %sz1binary offset=(%d, %d, %d), size=%d, dtype=%r, %srr�Zunarycst��d��d�S)N)r�)rr:)r��or�r:r;r�r�z%_gen_alignment_data.<locals>.<lambda>)r�Nzout of placezin placer=raZaliasedrCcst��d��d�S)N)r�)rr:)r�rEr�r:r;r� r�cst��d��d�S)N)r�)rr:)r�rEr�r:r;r�!r�z	in place1z	in place2)rZrr)
r�rJZmax_sizeZufmtZbfmtZinpr�rZinp1Zinp2r:)r�rEr�r;�_gen_alignment_data�sT"


$$$&&&rFc@seZdZdZdS)r.z/Ignoring this exception due to disabled featureN)r6r7r8r9r:r:r:r;r.9sc	os&t||�}z
|VWdt�|�XdS)z�Context manager to provide a temporary test folder.

    All arguments are passed as this to the underlying tempfile.mkdtemp
    function.

    N)r�shutilZrmtree)r\r�Ztmpdirr:r:r;r2=s

c	os4t||�\}}t�|�z
|VWdt�|�XdS)a�Context manager for temporary files.

    Context manager that returns the path to a closed temporary file. Its
    parameters are the same as for tempfile.mkstemp and are passed directly
    to that function. The underlying file is removed when the context is
    exited, so it should be closed at that time.

    Windows does not allow a temporary file to be opened if it is already
    open, so the underlying file must be closed after opening before it
    can be opened again.

    N)rr�rr�remove)r\r��fdrhr:r:r;r1Ls


cs>eZdZdZdZd
�fdd�	Z�fdd�Z�fdd	�Z�ZS)r/a  Context manager that resets warning registry for catching warnings

    Warnings can be slippery, because, whenever a warning is triggered, Python
    adds a ``__warningregistry__`` member to the *calling* module.  This makes
    it impossible to retrigger the warning in this module, whatever you put in
    the warnings filters.  This context manager accepts a sequence of `modules`
    as a keyword argument to its constructor and:

    * stores and removes any ``__warningregistry__`` entries in given `modules`
      on entry;
    * resets ``__warningregistry__`` to its previous state on exit.

    This makes it possible to trigger any warning afresh inside the context
    manager without disturbing the state of warnings outside.

    For compatibility with Python 3.0, please consider all arguments to be
    keyword-only.

    Parameters
    ----------
    record : bool, optional
        Specifies whether warnings should be captured by a custom
        implementation of ``warnings.showwarning()`` and be appended to a list
        returned by the context manager. Otherwise None is returned by the
        context manager. The objects appended to the list are arguments whose
        attributes mirror the arguments to ``showwarning()``.
    modules : sequence, optional
        Sequence of modules for which to reset warnings registry on entry and
        restore on exit. To work correctly, all 'ignore' filters should
        filter by one of these modules.

    Examples
    --------
    >>> import warnings
    >>> with clear_and_catch_warnings(modules=[np.core.fromnumeric]):
    ...     warnings.simplefilter('always')
    ...     warnings.filterwarnings('ignore', module='np.core.fromnumeric')
    ...     # do something that raises a warning but ignore those in
    ...     # np.core.fromnumeric
    r:Fcs.t|��|j�|_i|_tt|�j|d�dS)N)r1)�set�union�
class_modulesr.�_warnreg_copies�superr/r))r'r1r.)�	__class__r:r;r)�sz!clear_and_catch_warnings.__init__csDx4|jD]*}t|d�r|j}|��|j|<|��qWtt|���S)N�__warningregistry__)	r.r�rPr�rM�clearrNr/r9)r'�modZmod_reg)rOr:r;r9�s
z"clear_and_catch_warnings.__enter__csTtt|�j|�x>|jD]4}t|d�r0|j��||jkr|j�|j|�qWdS)NrP)	rNr/r:r.r�rPrQrM�update)r'�exc_inforR)rOr:r;r:�s


z!clear_and_catch_warnings.__exit__)Fr:)	r6r7r8r9rLr)r9r:�
__classcell__r:r:)rOr;r/bs
(c@steZdZdZddd�Zdd�Zeddd	fd
d�Zeddfdd
�Zeddfdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)r5a�
    Context manager and decorator doing much the same as
    ``warnings.catch_warnings``.

    However, it also provides a filter mechanism to work around
    http://bugs.python.org/issue4180.

    This bug causes Python before 3.4 to not reliably show warnings again
    after they have been ignored once (even within catch_warnings). It
    means that no "ignore" filter can be used easily, since following
    tests might need to see the warning. Additionally it allows easier
    specificity for testing warnings and can be nested.

    Parameters
    ----------
    forwarding_rule : str, optional
        One of "always", "once", "module", or "location". Analogous to
        the usual warnings module filter mode, it is useful to reduce
        noise mostly on the outmost level. Unsuppressed and unrecorded
        warnings will be forwarded based on this rule. Defaults to "always".
        "location" is equivalent to the warnings "default", match by exact
        location the warning warning originated from.

    Notes
    -----
    Filters added inside the context manager will be discarded again
    when leaving it. Upon entering all filters defined outside a
    context will be applied automatically.

    When a recording filter is added, matching warnings are stored in the
    ``log`` attribute as well as in the list returned by ``record``.

    If filters are added and the ``module`` keyword is given, the
    warning registry of this module will additionally be cleared when
    applying it, entering the context, or exiting it. This could cause
    warnings to appear a second time after leaving the context if they
    were configured to be printed once (default) and were already
    printed before the context was entered.

    Nesting this context manager will work as expected when the
    forwarding rule is "always" (default). Unfiltered and unrecorded
    warnings will be passed out and be matched by the outer level.
    On the outmost level they will be printed (or caught by another
    warnings context). The forwarding rule argument can modify this
    behaviour.

    Like ``catch_warnings`` this context manager is not threadsafe.

    Examples
    --------
    >>> with suppress_warnings() as sup:
    ...     sup.filter(DeprecationWarning, "Some text")
    ...     sup.filter(module=np.ma.core)
    ...     log = sup.record(FutureWarning, "Does this occur?")
    ...     command_giving_warnings()
    ...     # The FutureWarning was given once, the filtered warnings were
    ...     # ignored. All other warnings abide outside settings (may be
    ...     # printed/error)
    ...     assert_(len(log) == 1)
    ...     assert_(len(sup.log) == 1)  # also stored in log attribute

    Or as a decorator:

    >>> sup = suppress_warnings()
    >>> sup.filter(module=np.ma.core)  # module must match exact
    >>> @sup
    >>> def some_function():
    ...     # do something which causes a warning in np.ma.core
    ...     pass
    r?cCs&d|_g|_|dkrtd��||_dS)NF>r2r?�location�oncezunsupported forwarding rule.)r0�
_suppressionsr��_forwarding_rule)r'Zforwarding_ruler:r:r;r)�s
zsuppress_warnings.__init__cCs>ttd�rt��dSx"|jD]}t|d�r|j��qWdS)N�_filters_mutatedrP)r�r,rZ�_tmp_modulesrPrQ)r'r2r:r:r;�_clear_registries�s

z#suppress_warnings._clear_registriesrBNFcCs�|r
g}nd}|jr�|dkr.tjd||d�n8|j�dd�d}tjd|||d�|j�|�|��|j�	||t
�|t
j�||f�n |j
�	||t
�|t
j�||f�|S)Nr?)r rV�.z\.�$)r rVr2)r0r,�filterwarningsr6�replacer[�addr\�_tmp_suppressionsrzr�r��IrX)r'r rVr2r1�module_regexr:r:r;�_filters$zsuppress_warnings._filtercCs|j|||dd�dS)a�
        Add a new suppressing filter or apply it if the state is entered.

        Parameters
        ----------
        category : class, optional
            Warning class to filter
        message : string, optional
            Regular expression matching the warning message.
        module : module, optional
            Module to filter for. Note that the module (and its file)
            must match exactly and cannot be a submodule. This may make
            it unreliable for external modules.

        Notes
        -----
        When added within a context, filters are only added inside
        the context and will be forgotten when the context is exited.
        F)r rVr2r1N)re)r'r rVr2r:r:r;�filters
zsuppress_warnings.filtercCs|j|||dd�S)ai
        Append a new recording filter or apply it if the state is entered.

        All warnings matching will be appended to the ``log`` attribute.

        Parameters
        ----------
        category : class, optional
            Warning class to filter
        message : string, optional
            Regular expression matching the warning message.
        module : module, optional
            Module to filter for. Note that the module (and its file)
            must match exactly and cannot be a submodule. This may make
            it unreliable for external modules.

        Returns
        -------
        log : list
            A list which will be filled with all matched warnings.

        Notes
        -----
        When added within a context, filters are only added inside
        the context and will be forgotten when the context is exited.
        T)r rVr2r1)re)r'r rVr2r:r:r;r10s
zsuppress_warnings.recordcCs�|jrtd��tj|_tj|_|jdd�t_d|_g|_t�|_	t�|_
g|_xt|jD]j\}}}}}|dk	rx|dd�=|dkr�tj
d||d�qX|j�dd�d}tj
d|||d�|j	�|�qXW|jt_|��|S)	Nz%cannot enter suppress_warnings twice.Tr?)r rVr]z\.r^)r rVr2)r0r5r,r4�
_orig_showr6r7rbrJr[�
_forwardedr3rXr_r6r`rar8r\)r'�catZmessr�rRr3rdr:r:r;r9Ns0
zsuppress_warnings.__enter__cGs*|jt_|jt_|��d|_|`|`dS)NF)rgr,r4r7r6r\r0)r'rTr:r:r;r:nszsuppress_warnings.__exit__cOs�|�dd�}x�|j|jddd�D]�\}}	}
}}t||�r$|
�|jd�dk	r$|dkr�|dk	r�t||||f|�}
|j�|
�|�|
�dS|j	�
|�r$|dk	r�t||||f|�}
|j�|
�|�|
�dSq$W|jdk�r|dk�r|j||||f|�|�n
|�
|�dS|jdk�r&|j|f}n4|jdk�r@|j||f}n|jdk�rZ|j|||f}||jk�rjdS|j�|�|dk�r�|j||||f|�|�n
|�
|�dS)N�use_warnmsgrarr?rWr2rV)r�rXrb�
issubclassr�r\rr3rzr�r�rYrgZ
_orig_showmsgrhra)r'rVr r�r!r\r�rjrir��patternrRZrecr@Z	signaturer:r:r;r8vsL$







zsuppress_warnings._showwarningcst����fdd��}|S)z_
        Function decorator to apply certain suppressions to a whole
        function.
        c	s���||�SQRXdS)Nr:)r\r�)r>r'r:r;�new_func�sz,suppress_warnings.__call__.<locals>.new_func)r)r'r>rmr:)r>r'r;�__call__�szsuppress_warnings.__call__)r?)r6r7r8r9r)r\�Warningrerfr1r9r:r8rnr:r:r:r;r5�sF

 4)rB)NraNN)rjr)r|Tr}r~)rBT)r�rBT)r�rBT)rBTrBr�TT)rBT)r�rBT)rBT)NT)N)r=N)rrTrBT)r=)r=N)N)N)N)]r9Z
__future__rrrr�r�r�r�r,�	functoolsrrrG�
contextlibZtempfilerrZ
unittest.caser	rHr
rrr
rrrZnumpy.lib.utilsrr��ior�__all__r�r0ZKnownFailureTestr%r.r3�getattrr4rAr'rNrSrUr"r�rir�platform�getpidrrrr rrr�rrrr$rr#r!rr)rr&rr-r(r*rrrrdrr+�contextmanagerr=r+rBr,rFr.r2r1r@r/r5r:r:r:r;�<module>s�$







)
z
b
k
D
l
IF
. 
/
0
9
?
-
6!9
+
$EA

Zerion Mini Shell 1.0