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__/timer_comparison.cpython-36.pyc
3

���hr<�@s�ddlZddlmZddlZddlmZddljjZddl	m
Z
ejdd�ejZGdd�d�Z
ed	kr�d
ZdeZd\ZZxxed
d�D]jZdeZejee�jeed�Zeje�Zededd�eede��ededed
f�q�WdS)�N)�reduce)�float_)�
build_err_msg�ignore)�allc@sxeZdZdd�Zddd�Zddd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS) �ModuleTestercCs
||_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j	|_	t
|_
|j|_|j|_|j
|_
|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_y|j|_Wntk
r�|jj|_YnXg|_dS)N)�module�allequal�arange�array�concatenate�count�equal�filled�getmaskZgetmaskarray�id�inner�	make_mask�masked�masked_array�
masked_values�mask_or�nomask�ones�outer�repeat�resize�sort�take�	transpose�zerosZMaskType�umath�AttributeError�coreZ	testnames)�selfr�r%�:/tmp/pip-build-5_djhm0z/numpy/numpy/ma/timer_comparison.py�__init__s@zModuleTester.__init__�TcCs,|j|�}|j|�}|j|j|�|j|��}	|j|j||	d�|�}|j|j||	d�|�}|jjdkr�|jt�}t|t	j
�r�|jdkr�d|t	j|�<nt	j|�r�d}|jjdkr�|jt�}t|t	j
�r�|jdkr�d|t	j|�<nt	j|�r�d}�y|j
fk�p|j
fk�p|j
|j
k}
|
�sLt||g|d|j
|j
f|d
d�}|
�sLt|��|||�}|	|jk	�rv|�rv|j||	d�}t|t��r�|}
dg}
n|j�}
|
j�}
|
j�}
|
�s�d	d
|
jd�t|
�}t||g|d|f|dd�}|
�s�t|��Wn2tk
�r&t||g||dd�}t|��YnXdS)zZ
        Assert that a comparison of two masked arrays is satisfied elementwise.

        )�mask�O�rz
(shapes %s, %s mismatch)�x�y)�header�names�dgY@z
(mismatch %s%%)N)r,r-)r,r-)r,r-)rrrr�dtype�char�astyper�
isinstance�npZndarray�size�isnan�shaper�AssertionErrorr�boolZravelr�tolistr
�len�
ValueError)r$Z
comparisonr,r-�err_msgr.Z
fill_value�xfZyf�mZcond�msg�valZreduced�matchr%r%r&�assert_array_compare3s^





$


z!ModuleTester.assert_array_comparecCs|j|j|||dd�dS)zH
        Checks the elementwise equality of two masked arrays.

        zArrays are not equal)r>r.N)rDr)r$r,r-r>r%r%r&�assert_array_equalkszModuleTester.assert_array_equalc
Cs\tjddddtddddddddg�}ddddddddddddg}|j||d	�}|dd
S)
z!
        Tests creation

        g�?g@g@g@g$@g@r+r)r)Ng�g$�)r5r�pir)r$r,r@�xmr%r%r&�test_0ss&zModuleTester.test_0c	
Csftjddddtddddddddg�}tjddddddddddddg�}dd	d	d	d	d	dd	d	d	d	d	g}d	d	dd	d	ddd	d	d	d	dg}|j||d
�}|j||d
�}tj|d|�}|jd�||jd	�j�s�t�|j	}|j
tdd
�|�ks�t�|j|�t
|�tdd
�|�k�st�xRdD]J}||_	||_	||_	||_	||_	|j|�t
|�tdd
�|�k�st��qWdS)z!
        Tests creation

        g�?g@g@g@g$@g@gr+r)r)g@��x�DcSs||S)Nr%)r,r-r%r%r&�<lambda>�sz%ModuleTester.test_1.<locals>.<lambda>cSs||S)Nr%)r,r-r%r%r&rI�s����cSs||S)Nr%)r,r-r%r%r&rI�sNg�g$�g�g�g$��rJrK�rLrM)rNrO)r5rrFr�whereZset_fill_valuer�anyr9r8r6rr
r<)	r$r,r-�m1�m2rGZymr?�sr%r%r&�test_1}s&&"
&
zModuleTester.test_1c	Cs�tjddddg�}|j|ddddgd�}|j|ddddgd�}|j|�}t|�t|�t|d�t|d�kstt�|d|dks�t�d|d<d|d<|j||�d|dd�<d|dd�<|j|d<|j|dd�<||d	d	�<|j|d<|jddddgddddg�|d	d	�<|jddddgddddg�|d	d	�<tj	d
�d}|j
|d�}|jdd
ddgt�}tjdd
ddgt�}|d|d|dd�jdk�s�t�dddddg}|j
|�}|j
|�}||k�s�t�|j
|dd�}||k	�s�t�d	S)z2
        Tests conversions and indexing.

        r+rMrJrKr)r)�	�cN�g�?g@Zhello)�copy)r)r5r�str�repr�typer9rErrr
r�objectr8r)	r$Zx1Zx2Zx3�x4�nr@rS�m3r%r%r&�test_2�s@


$$

zModuleTester.test_2c
Cs�|jd�}|j|d<|j|d	�}|j|j||g�|�s:t�|j|j|�ddddddddg�s`t�|j|d
dd�}|j|ddddddddg�|j|ddd�}|j||�s�t�|jddd�}|j||�s�t�|jdd�}|j||�s�t�dS)z&
        Tests resize/repeat

        rJrM�rr+)�axisrKN)rb)rMrMrMrM)rMrMrMrM)	r
rrr	rr9rrrE)r$r^Zy4Zy5Zy6Zy7Zy8r%r%r&�test_3�s

&zModuleTester.test_3cCsN|jd�}tjd�}|j|dd�<|jddd�}|jddd�}|jtj|d�|j|d
��s^t�|jtj|dd�|j|dd��s�t�|jtj|j	|d�|j	|d��|j||��s�t�|jtj
|j	|d�|j	|d��|j
||��s�t�|jd	dd
ddgt�}|j|d<|j|dddg�}|dd	k�s&t�|ddk�s8t�|ddk�sJt�dS)zB
        Test of take, transpose, inner, outer products.

        �rXrLrMrKrJrr+�abc�defN)rMrr+)rMrr+)rMrr+)rMrr+)
r
r5r�reshaper	rr9rrrrrr])r$r,r-�tr%r%r&�test_4�s"

 $
zModuleTester.test_4cCs|jd�}|jd�}|jd�}|j|d<|d7}|j||d�sDt�|d7}|j||d�s`t�|jd�}|jd�}|j|d<|d8}|j||d�s�t�|d8}|j||d�s�t�|jd�d}|jd�d}|j|d<|d9}|j||d�s�t�|d9}|j||d��st�|jd�d}|jd�d}|j|d<|d}|j||��sVt�|d}|j||��spt�|jd�d}|jd�d}|j|d<|d}|j||d��s�t�||jd�}|j||jd��|jd�jt�}|jd�}|j|d<|d7}|j||d��st�dS)z*
        Tests inplace w/ scalar

        �
rMr+g�?g@N)rk)r
rr	r9rErr3r)r$r,r-rGr%r%r&�test_5�sR











zModuleTester.test_5cCs6|jdtd�}|jd�}|jdtd�}|j|d<|j}|jdtd�}|j|d<||7}||7}|j|||�srt�|j|||�s�t�|j|j|j||j��s�t�|jdtd�}|jdtd�}|j|d<|j}|jdtd�}|j|d<||8}||8}|j|||��st�|j|||��s"t�|j|j|j||j���s@t�|jdtd�}|jdtd�}|j|d<|j}|jdtd�}|j|d<||9}||9}|j|||��s�t�|j|||��s�t�|j|j|j||j���s�t�|jdtd�}|jdtd�}|j|d<|j}|jdtd�}|j|d	<||}||}dS)
z)
        Tests inplace w/ array

        rk)r1rMr+N���rmrmrm)r
rrr)r	r9r)r$r,r-rGr@�ar%r%r&�test_6 sT








zModuleTester.test_6c
Cs�|jddd
tdgdddgdgdd�|jdddtdgdddgdgdd�f}x�dD]�}yt|j|�}Wntk
r�tt|�}YnXt|j|�}|d|j�}||�}||�}|j|j	d�|j	d�|�|j|j
|j
�q^WdS)zTests ufuncg�?rr+rMrL)r)�sqrt�log�log10�exp�	conjugateNrmrm)rprqrrrsrt)rrF�getattrr!r"�fromnumericrZninrErZ_mask)r$�d�fZufZmf�args�ur�mrr%r%r&�test_7Ss*.
zModuleTester.test_7cCs(|jddddgddddgd�}|jd|j|dd��|jd|j|ddddgd	��|j|ddddgdd
�\}}|jd|�|dks�t�|j|dd�<|j|dd�|jks�t�|jddddgddddgd�}|jdd�}|j|dd�df<|j|j|dd�ddg�|j|dd�d|jk�s t�|jddg|j|dd��|j|ddd
�\}}|j|ddg�ddddddg}ddddddgddddddgg}|jd�}|j|j|dd�d�|j|j|d|d�d�|j|jd�d|jd�g�}|j|j|d�tjj	tjd��dd�|j|j|dd�tjd�dd�|j|j|dd�|j|dd�|j|dd�dg�|j|j|d|d	�d�|j|j|d|d�ddddddg�|j|j|dd�|j|dd�|j|dd�dg�|j
d�}ddddddg}	ddddddgddddddgg}
|jd�}ddddddg}|j|j|j||�dd�d�|j|j|j||	�dd�d�|j|j|j||�dd�d�|j|j
|j|j||�dd��d�|j||
�}
|j|j|
d�d�|j|j|
dd�ddddddg�|j|j|
dd�ddg�|j|j|
d|d�ddddddg�dS)Ngg�?g@g@r+r)r))rc)�weights)r}�returnedg@rM)rcr~rLg@)rcr}g(@g4@g@g$@g�X@g@g@g������
@g������
@)rrEZaverager9rrhr
r5�addrr rrr
)r$Zott�resultZwtsZw1Zw2r,r-rRrSr`Zm4Zm5�zr%r%r&�test_99usT 
*$2$2
 
$"zModuleTester.test_99cCs*|jd�}|j|dd�<|jddd�}dS)NrerXrLrMrKrJ)r
rrh)r$r,r%r%r&�test_A�s
zModuleTester.test_AN)r(r(T)r()�__name__�
__module__�__qualname__r'rDrErHrUrardrjrlror|r�r�r%r%r%r&rs"
7

*43"-r�__main__zNfrom __main__ import ModuleTester 
import numpy
tester = ModuleTester(module)
zimport numpy.ma.core as module
rkr+rbztester.test_%i()z#%i�2�.zModuleTester.test_%i.__doc__zcore_current : %.3f - %.3f)rkrk)Ztimeit�	functoolsrZnumpyr5rZnumpy.core.fromnumericr#rvZ
numpy.testingrZseterrrFrr�Z
setup_baseZ	setup_curZnrepeatZnloop�range�i�func�Timerr�curr�print�evalr%r%r%r&�<module>s,