CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_hashing.cpython-310.pyc94 linesDownload Raw Back to __pycache__
1o

2��Yi�=�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl3mZddlm
Z
ddlmZddlmZddlmZddlmZmZdd	lmZmZmZmZd4d�Zdd
�Zdd�ZGdd�de�Z Gdd�de�Z!dddddddddddgddgddiddiddidej"dgj#e$d�e$d�ddd�ddddid �gZ%ed!e%�ed"e%�d#d$���Z&d%d&�Z'ed'd(�ed)d*���Z(d+d,�Z)d-d.�Z*eed/d0d1g�d2d3���Z+ed4d5��Z,eed6d7d8g�d9d:���Z-eeej.d;kd<d=�d>d?���Z/d@dA�Z0dBdC�Z1edDdE��Z2edFdG��Z3dHdI�Z4dJdK�Z5dLdM�Z6dNdO�Z7edPdQ��Z8edRdSdTdUdVdW�e9dX�D�dYfdZgd[�d\�d]fg�d^d_��Z:ed`da��Z;edbdc��Z<eddde��Z=edfdg��Z>dhdi�Z?djdk�Z@dS)lz5Test the hashing module.6�N)�ProcessPoolExecutor)�Decimal)�filter_args��hash)�Memory)�np�7with_numpy)�fixture�parametrize�raises�skipifcCs|S�N�)�srr��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\joblib/test/test_hashing.py�unicode�rcGs>t�}td�D]}t��}||�|�t��|�qt|�S)zTime function func on *args.�)�list�range�time�append�min)�func�args�times�_�t1rrr�	time_func"srcGs<t|g|�R�}t|g|�R�}dt||�||}|S)zKReturn the relative time between func1 and func2 applied on8    *args.9    ��?)r�abs)Zfunc1Zfunc2rZ10time_func1Z11time_func2�
relative_diffrrr�
relative_time,sr#c@seZdZdd�ZdS)�KlasscC�|Srr��self�xrrr�f7rzKlass.fN)�__name__�12__module__�__qualname__r)rrrrr$6sr$c@seZdZdd�Zdd�ZdS)�KlassWithCachedMethodcCst|d�}|�|j�|_dS)N)�location)r�cacher))r'ZcachedirZmemrrr�__init__<s13zKlassWithCachedMethod.__init__cCr%rrr&rrrr)@rzKlassWithCachedMethod.fN)r*r+r,r0r)rrrrr-;sr-��g�?�@y�?�?y@�?�a�b�r1)r1r1�r4r1)r4r1r7)r4r1�d�obj1�obj2cCs(t|�t|�k}||u}||ksJ�dS)z!Smoke test hash on various types.Nr)r9r:�are_hashes_equalZare_objs_identicalrrr�test_trivial_hashmsr<cCs^t�td��}t|j�t|j�ksJ�t�td��}t�td��}t|j�t|j�ks-J�dS)Nr4�14�	)	�io�StringIOrr�flush�collections�dequer�extend)r4Za1Za2rrr�test_hash_methodsws15rE�function)�scopecCs@tj�d�}|�d�}|��}|��}|dd7<|||fS)Nr�r=r=r1)r�random�RandomState�
random_sample�copy)�rnd�arr1�arr2�arr3rrr�three_np_arrays�s1617rQcCsf|\}}}tj|dd�D]\}}t|�t|�k}t�||k�}||ks%J�qt|�t|j�ks1J�dS)Nr2)�repeat)�	itertools�productrr�all�T)rQrNrOrPr9r:r;Zare_arrays_equalrrr�test_hash_numpy_arrays�s18rWcCsT|\}}}||d�}||d�}||d�}t|�t|�ksJ�t|�t|�ks(J�dS)N)r1r2r)rQrNrOrPZd1Zd2Zd3rrr�test_hash_numpy_dict_of_arrays�s19202122rX�dtypez
datetime64[s]ztimedelta64[D]cCs2tt�d��}tjdd|d�}t|�|ksJ�dS)Nr=r�rY)rr�arange)rYZa_hash�arrayrrr�test_numpy_datetime_array�sr]cCsptjt�d��d�dd�dd�dd�dd�f}t�|�}t|�t|�ks'J�t�|�}t|�t|�ks6J�dS)Nip)��r2r�F)�orderr1)r�asarrayr[�reshapeZascontiguousarrayr�asfortranarray)r4r5�crrr�test_hash_numpy_noncontiguous�s2302425re�coerce_mmapTFcCs�|�d�j}z.tj|ddd�}t�|�}t||d�t||d�k}||ks&J�Wdt�vr3~t��dSdSdt�vr@~t��ww)zECheck that memmap and arrays hash identically if coerce_mmap is True.Zmemmap_temprHzw+)�shape�mode)rf�mN)	�join�strpathrZmemmaprar�locals�gc�collect)�tmpdirrf�filenamerir4r;rrr�test_hash_memmap�s26�27�28�rq�win32z5This test is not stable under windows for some reason)�reasoncCs|tj�d�}|�d�}dd�}t|t|�}|dksJ�dt||�}tt|||f�}dt||�||}|dks<J�dS)	a�Check the performance of hashing numpy arrays:29 30    In [22]: a = np.random.random(1000000)31 32    In [23]: %timeit hashlib.md5(a).hexdigest()33    100 loops, best of 3: 20.7 ms per loop34 35    In [24]: %timeit hashlib.md5(pickle.dumps(a, protocol=2)).hexdigest()36    1 loops, best of 3: 73.1 ms per loop37 38    In [25]: %timeit hashlib.md5(cPickle.dumps(a, protocol=2)).hexdigest()39    10 loops, best of 3: 53.9 ms per loop40 41    In [26]: %timeit hash(a)42    100 loops, best of 3: 20.8 ms per loop43    ri@BcSst�t|����Sr)�hashlib�md5�44memoryview�	hexdigest)r(rrr�md5_hash�sz-test_hash_numpy_performance.<locals>.md5_hashg333333�?rr N)rrIrJrKr#rrr!)rMr4rxr"Ztime_hashlibZ	time_hashrrr�test_hash_numpy_performance�s45rycCs8t�}t�}tt|jgd��tt|jgd��ksJ�dS)z}Make sure that calling the same method on two different instances46    of the same class does resolve to the same hashes.47    r6N)r$rrr)�r4r5rrr�test_bound_methods_hash�s,r{cCsDt|j�}t|j�}tt|jjgd��tt|jjgd��ks J�dS)z�Make sure that calling the same _cached_ method on two different48    instances of the same class does resolve to the same hashes.49    r6N)r-rkrrr)r)ror4r5rrr�test_bound_cached_methods_hash�s505152�r|cCsPtjdd�td�D�td�}tjdd�td�D�td�}t|�t|�ks&J�dS)z;Make sure that ndarrays with dtype `object' hash correctly.cS�g|]}t�|��qSr�rr[��.0�irrr�53<listcomp>	�z*test_hash_object_dtype.<locals>.<listcomp>�rZcSr}rr~rrrrr�54r�N)rr\r�objectrrzrrr�test_hash_object_dtypesr�cCs,t�d�}t�d�}t|�t|�ksJ�dS)Nr3g@)r�float64rrzrrr�test_numpy_scalars5556r�cCspt|j�}dgdgdgdgdgdgdgdgdgdgdgdgdgd�
}|�|�}|�|�}t|�t|�ks6J�dS)N�!�
z#s12069__c_maps.nii.gzz#s12158__c_maps.nii.gzz#s12258__c_maps.nii.gzz#s12277__c_maps.nii.gzz#s12300__c_maps.nii.gzz#s12401__c_maps.nii.gzz#s12430__c_maps.nii.gzz#s13817__c_maps.nii.gzz#s13903__c_maps.nii.gzz#s13916__c_maps.nii.gzz#s13981__c_maps.nii.gzz#s13982__c_maps.nii.gzz#s13983__c_maps.nii.gz)r-rkr)r)ro�kr8r4r5rrr�test_dict_hashs$57�5859r�cCsBt|j�}tgd��}|�|�}|�|�}t|�t|�ksJ�dS)Nr�)r-rk�setr)r)ror�rr4r5rrr�
test_set_hash3s60�6162r�cCs8tttd�td�g��tttd�td�g��ksJ�dS)Nr�NaN)rr�rrrrr�test_set_decimal_hashPs�r�cCsDd}|di}|di}t�t�|��}t||g�t||g�ks J�dS)N�foo�bar)�pickle�loads�dumpsr)�stringr4r5rdrrr�test_stringXs63 r�cCsXt�d�}t�d�}||usJ�t|�t|�ksJ�t�t�|��}||us(J�t|�t|�ks2J�t||g�t||g�ks@J�t||g�t||g�ksNJ�t�dtjdfdtjdfg�}t�dtjdfdtjdfg�}t|�t|�ksvJ�t�t�|��}||us�J�t|�t|�ks�J�t||g�t||g�ks�J�t||g�t||g�ks�J�dS)NZf4�name�Zgrades)r2)rrYrr�r�r�Zstr_r�)Zdt1Zdt2Zdt1_roundtrippedZcomplex_dt1Zcomplex_dt2Zcomplex_dt1_roundtrippedrrr�test_numpy_dtype_picklingbs*64	6566��r�zto_hash,expected)zThis is a string to hashZ 71b3f47df22cb19431d85d92d0b230b2)uC'est létéZ 2d8d189e9b2b0b2e384d93c868c0e576))i@�i1�i3~��Z e205227dd82250871fa25aa0ec690aa3cCsg|]	}t�d����qS)�*)rI�Random�r�rrrrr��sr��Z a11ffad81f9682a7d901e6edc3d16c84�{)i����r2r)ZabcdeZsadfasZ aeda150553d4bb5c69f0e69d51b0e2efcCst|�|ksJ�dSrr)Zto_hash�expectedrrr�test_hashes_stay_the_same�sr�cCs8tj�d�}|�d�}t�|�}t|�t|�ksJ�dS)NrrH)rrIrJrKrcr)�rngZarr_cZarr_frrr�Atest_hashes_are_different_between_c_and_fortran_contiguous_arrays�s6768r�cCstt�d��dS�Nr�rrr\rrrr�
test_0d_array�sr�cCs&tt�d��tt�dg��ksJ�dSr�r�rrrr�)test_0d_and_1d_array_hashing_is_different�s&r�c69Cs�dd�}|�}|�}tdd�}tdd�}z9t||�D](\}}|�t|���}|�t|���}||ks4J�|�t|���}	||	ksBJ�qW|��|��dS|��|��w)Ncs�tj�d���jdddd��d�t�fdd�td	�D���fd70d�td	�D���dd	��d
��jddd��d���d��d
�gd�tjddd��	d�t�71tjddd��	d��tjddd��	d�dd�dd�fg}|S)Nr�i���r^�2)�high�sizez<i8c3s �|]}��d��d�VqdS)r�<f4N��randn�astyper��r�rr�	<genexpr>�s�z_test_hashes_stay_the_same_with_numpy_objects.<locals>.create_objects_to_hash.<locals>.<genexpr>r�csg|]72}��d��d��qS)rr�r�r�r�rrr��sz`test_hashes_stay_the_same_with_numpy_objects.<locals>.create_objects_to_hash.<locals>.<listcomp>rr�r=�)r�)i����r�drZrHr2)rrIrJ�randintr��tuplerr�r[rbrc)Zto_hash_listrr�r�create_objects_to_hash�s��	"�zLtest_hashes_stay_the_same_with_numpy_objects.<locals>.create_objects_to_hashr1)�max_workers)r�zipZsubmitr�result�shutdown)73r�Zto_hash_list_oneZto_hash_list_two�e1�e2Zobj_1Zobj_2Zhash_1Zhash_2Zhash_3rrr�,test_hashes_stay_the_same_with_numpy_objects�s"7475��76r�cCsHdd�}ttj��}t|�Wd�n1swY|�d�dS)NcSsdS)Nr�rrrrr�
non_picklable�rz2test_hashing_pickling_error.<locals>.non_picklablezPicklingError while hashing)rr��
PicklingErrorr�match)r��excinforrr�test_hashing_pickling_error�s7778�r�cCsJd}tt|d��ddi}t|dd�Wd�dS1swYdS)Nz!Valid options for 'hash_name' are)r�r�r��invalid)�	hash_name)r�79ValueErrorr)�msg�datarrr�test_wrong_hash_names80"�r�)A�__doc__rBrmrtr?rSr�rI�sysr�concurrent.futuresr�decimalrZjoblib.func_inspectrZjoblib.hashingrZ
joblib.memoryrZjoblib.test.commonrr	Zjoblib.testingr81rrr
rrr#r�r$r-rnrr�Z82input_listr<rErQrWrXr]rerq�platformryr{r|r�r�r�r�r�r�r�rr�r�r�r�r�r�r�rrrr�<module>s�8384
����&		85	�"	86	8788 89(���90
	91	929394E	
Aluode/PerceptionLabPortable · CoolFace