Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/joblib/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/joblib/test/__pycache__/test_pool.cpython-35.pyc



���W>�@s�ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddl	m
Z
mZddl	mZdd	l	m
Z
dd
l	mZddl	mZddlmZedk	r&dd
lmZddlmZddlmZddlmZdadd�Zdd�Zdd�Zdd�Zeee�Zdd�Zdd�Ze
eedd����Ze
eedd ����Z e
eed!d"����Z!e
eed#d$����Z"e
eed%d&����Z#e
eed'd(����Z$e
eed)d*����Z%e
eed+d,����Z&d-d.�Z'e
eed/d0����Z(dS)1�N)�
with_setup)�assert_equal)�
assert_raises)�assert_false)�assert_true)�
with_numpy�np)�setup_autokill)�teardown_autokill)�with_multiprocessing)�with_dev_shm)�mp)�
MemmapingPool)�has_shareable_memory)�ArrayMemmapReducer)�
reduce_memmapcCsttdd�dS)N�timeouti,)r	�__name__�rr�F/opt/alt/python35/lib/python3.5/site-packages/joblib/test/test_pool.py�setup_modulesrcCstt�dS)N)r
rrrrr�teardown_modulesrcCstjdd�adS)N�prefixZjoblib_test_pool_)�tempfile�mkdtemp�TEMP_FOLDERrrrr�setup_temp_folder#srcCs#tdk	rtjt�dadS)N)r�shutil�rmtreerrrr�teardown_temp_folder(s
rcCs*|\}}}tjj|||�dS)z�Dummy helper function to be executed in subprocesses

    Check that the provided array has the expected values in the provided
    range.

    N)r�testing�assert_array_equal)�args�data�position�expectedrrr�check_array2sr&cCsM|\}}}t|||�||d9<tjj||d|�dS)z�Dummy helper function to be executed in subprocesses


    Check that the input array has the right values in the provided range
    and perform an inplace modification to double the values in the range by
    two.

    �N)rrr r!)r"r#r$r%rrr�inplace_double=s	r(cs�tjj}tjjtd�}tj|dtjdddd�}dtj	|j
dd|j�|d	d	�<|j�tj|dtjdddd
dddd�}tj	d�j
|j
�|d	d	�<|dd�dd�dd�f}tj|�}|j}td	td���fdd�}dd�}||�}	tt|	��tt|	tj��||	|�||�}
tt|
��||
|�||�}tt|tj��tt|��|||�||�}tt|tj��tt|��|||�|d
}
tt|
��||
�}tt|��tt|tj��|||d
�tj|
�}tt|��||�}tt|tj��tt|��|||�d	S)z9Check that it is possible to reduce a memmap backed arrayz	test.mmap�dtype�shapei��modezw+g�?rN���zr+�order�F�offset�<�r'�ccs�|�\}}||�S)Nr)�x�consr")�reducerrr�reconstruct_arraynsz;test_memmap_based_array_reducing.<locals>.reconstruct_arraycSst|�\}}||�S)N)r)r5r6r"rrr�reconstruct_memmaprsz<test_memmap_based_array_reducing.<locals>.reconstruct_memmapg�)r,r-r.���r:)rr r!�os�path�joinr�memmap�float64�aranger*r)�flush�reshape�asarray�Trrr�
isinstancer�ndarray)r!�filename�buffer�a�br4�dr8r9�a_reconstructed�b_reconstructed�c_reconstructed�d_reconstructed�a3Za3_reconstructedZb3Zb3_reconstructedr)r7r� test_memmap_based_array_reducingLsR$-
%%	




rQc
	Cs�tjj}tjjtd�}tj|dtjdddd�}tj	d�j
|j�|dd�<|d	d
�}|dd�dd
�f}|dd�dd�dd�d	f}|ddd
�}dd�}||�}tt
|��tt|tj��|||�||�}	tt
|	��||	|�||�}
tt
|
��||
|�||�}tt
|��|||�||�}tt
|��|||�dS)Nz	test.mmapr)r*�d�r,r+zw+r�
r-r3r.cSs"t|�\}}||�}|S)N)r)r5r6r"�resrrrr9�szEtest_high_dimension_memmap_array_reducing.<locals>.reconstruct_memmap)rRrSrSr,i�i�Wi�)rr r!r;r<r=rr>r?r@rBr*rrrE)
r!rGrIrJr4rK�er9rLrMrNrOZe_reconstructedrrr�)test_high_dimension_memmap_array_reducing�s4	%(



rWcs2tjj}tjjtd�}tj|�tdddd|�}z�tjjtd�}tj	|dtj
dddd���jd
�|jt
�fdd�t�jd�D��|�dtj�j��tj	|dtj
dddd��|jt
�fdd�t�jd�D��ttj|�g�|�dtj�j��|�dtj�j��tj	|dtj
dddddd��tt|jt�fdd�t�jd�D��tttf|jt
�fdd�t�jd�D��Wd|j�~XdS)z@Check that subprocess can access and update shared memory memmap�poolrT�
max_nbytesr'�temp_folderz	test.mmapr)r*r,r-r+zw+g�?cs?g|]5}t�jd�D]}�||fdf�qqS)r3g�?)�ranger*)�.0�i�j)rIrr�
<listcomp>�s	z)test_pool_with_memmap.<locals>.<listcomp>rr4cs?g|]5}t�jd�D]}�||fdf�qqS)r3g@)r[r*)r\r]r^)rJrrr_�s	�rr1r.csg|]}�|df�qS)g@r)r\r])r4rrr_�s	csg|]}�|df�qS)g@r)r\r])r4rrr_�s	N)r,r-)r-r,)rT�)rr r!r;r<r=r�makedirsrr>�float32�fill�mapr(r[r*�onesr�listdirr�AssertionErrorr&�RuntimeError�
ValueError�	terminate)r!�pool_temp_folder�prGr)rIrJr4r�test_pool_with_memmap�s2
$
$!	'+
rncs]tjj}tjjtd�}tj|�tdddd|�}ztjjtd�}tj	|dtj
dddd���jd
�tj���t
t�tj	��tt���|jt��fdd�t�jd�D��|�dtj�j��|�dtj�j��ttj|�g�Wd|j�~XdS)z?Check that subprocess can access and update shared memory arrayrXrTrYr'rZz	test.mmapr)r*r,r-r+zw+g�?cs?g|]5}t�jd�D]}�||fdf�qqS)r3g�?)r[r*)r\r]r^)rI�a_viewrrr_s	z4test_pool_with_memmap_array_view.<locals>.<listcomp>rN)r,r-)rr r!r;r<r=rrbrr>rcrdrCrrErrrer(r[r*rfrrgrk)r!rlrmrGr)rIror� test_pool_with_memmap_array_views$
$

rpcs�ttjt�g�tddddt�}zvttjt�g�ttjj|j��t	j
ddt	j��t�jd�|j
t�fdd	�t�jd
�D��ttjt�g�t	j
ddt	j��t�jd�|j
t�fd
d	�t�jd
�D��ttjj|j��tj|j�}tt|�d�t	jdgddd�}|j
t|g�}t|d
�Wd|j�ttjj|j��~XdS)z0Check that large arrays are not copied in memoryr,rY�(rZr-r)racsg|]}�|df�qS)g�?r)r\r])�smallrrr_=s	z8test_memmaping_pool_for_large_arrays.<locals>.<listcomp>rrRi csg|]}�|df�qS)g�?r)r\r])�largerrr_Es	r3�abc�objectN)rr;rgrrrr<�exists�_temp_folderrrfrc�nbytesrer&r[r*r?r�isdir�len�arrayrrk)rmZdumped_filenames�objects�resultsr)rsrrr�$test_memmaping_pool_for_large_arrays*s*00
r~cs�tddddt�}z�ttjt�g�tjddtj��t�jd�|j	t
�fdd	�t�jd
�D��ttjt�g�Wd|j
�~XdS)z1Check that large arrays memmaping can be disabledr,rYNrZrRr)i csg|]}�|df�qS)g�?r)r\r])rsrrr_is	zAtest_memmaping_pool_for_large_arrays_disabled.<locals>.<listcomp>r)rrrr;rgrrfr?rxrer&r[r*rk)rmr)rsr�-test_memmaping_pool_for_large_arrays_disabledZs0
rcCs3tddd�}z�|j}d}t|j|��ttjj|��tjddtj	�}t
|jd�|jt
|gd�t
ttj|��d�tjddtj	�d	}t
|jd�|jt
|gd�t
ttj|��d	�Wd
|j�~Xttjj|��d
S)z4Check that MemmapingPool uses /dev/shm when possibler,rYrTz/dev/shm/joblib_memmaping_pool_rRr)i r3r'N)rrwr�
startswithr;r<rvrrfr?rrxre�idrzrgrkr)rmrlZ
folder_prefixrIrJrrr�test_memmaping_on_dev_shmts"	 
r�c
Cs�tjj}tddddt�}zN|jtjdd�}|j�}tt	|��||tjd��Wd|j
�~XdS)	z:Check that large arrays are not copied in memory in returnr,rYrTrZr"��N)r�)rr r!rr�apply_asyncrf�getrrrk)r!rmrUrsrrr�.test_memmaping_pool_for_large_arrays_in_return�s	
r�cCstt|��||S)z4Multiplication function to be executed by subprocess)rr)rIZn_timesrrr�_worker_multiply�sr�cCs�tjj}tddddt�}z�tjtjd�jd
�dd	�d
d
�d
d�d
d
�f}|jt	d|df�j
�}tt|��||d|�Wd
|j
�~Xd
S)z�Check that memmaps with a bad buffer are returned as regular arrays

    Unary operations and ufuncs on memmap instances return a new memmap
    instance with an in-memory buffer (probably a numpy bug).
    r,rYrTrZip��r'r/r0Nr3r")r�r'r,)rr r!rrrCr@rBr�r�r�rrrk)r!rmrIrJrrr�6test_workaround_against_bad_memmap_with_copied_buffers�s	(!
r�))r;rr�
nose.toolsrrrrrZjoblib.test.commonrrr	r
rrZjoblib._multiprocessing_helpersr
Zjoblib.poolrrrrrrrrrZwith_temp_folderr&r(rQrWrnrpr~rr�r�r�r�rrrr�<module>slQ,4%.&