L i=dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddlmZddlmZddlmZddlmZmZdd lmZmZmZmZd Zd Zd ZGd deZ GddeZ!dddddddddddgddgddiddiddidejDdgjFe$de$ddddddddidgZ%ede%ede%d Z&d!Z'ed"#ed$Z(d%Z)d&Z*eed'd(d)gd*Z+ed+Z,eed,d-d.gd/Z-eeej\d0k(d12d3Z/d4Z0d5Z1ed6Z2ed7Z3d8Z4d9Z5d:Z6d;Z7ed<Z8ed=d>d?d@e9dADcgc]"}ejtdBj$c}dCfdDgdEdFdGfgdHZ;edIZedLZ?dMZ@dNZAycc}w)Oz Test the hashing module. N)ProcessPoolExecutor)Decimal) filter_argshash)Memory)np with_numpy)fixture parametrizeraisesskipifc|SN)ss ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/joblib/test/test_hashing.pyunicoders Hct}tdD]A}tj}|||jtj|z Ct |S)zTime function func on *args.)listrangetimeappendmin)funcargstimes_t1s r time_funcr""sQ FE 1X' YY[ d  TYY[2%&' u:rcdt|g|}t|g|}dt||z ||zz z}|S)zKReturn the relative time between func1 and func2 applied on *args. ?)r"abs)func1func2r time_func1 time_func2 relative_diffs r relative_timer+,sF5(4(J5(4(J3zJ67: ;RSTM rceZdZdZy)Klassc|Srrselfxs rfzKlass.f7rN)__name__ __module__ __qualname__r2rrrr-r-6srr-ceZdZdZdZy)KlassWithCachedMethodc\t|}|j|j|_y)N)location)rcacher2)r0cachedirmems r__init__zKlassWithCachedMethod.__init__<s h'466"rc|Srrr/s rr2zKlassWithCachedMethod.f@r3rN)r4r5r6r>r2rrrr8r8;s #rr8g?@y??y@?abr@)r@r@rCr@)rCr@rF)rCr@dobj1obj2cHt|t|k(}||u}||k(sJy)z!Smoke test hash on various types.Nr)rHrIare_hashes_equalare_objs_identicals rtest_trivial_hashrMms0 DzT$Z/ 1 11 1rcltjtd}t|jt|jk(sJt j td}t j td}t|jt|jk7sJy)NrC ) ioStringIOrrflush collectionsdequerextend)rCa1a2s rtest_hash_methodsrYwsx GCL!A =DM )) )   59 %B   58 $B  ?d299o -- -rfunction)scopectjjd}|jd}|j }|j }|dxxdz cc<|||fS)NrrOrOr@)r random RandomState random_samplecopy)rndarr1arr2arr3s rthree_np_arraysrfsX ))   "C   X &D 99;D 99;DGqLG t rc|\}}}tj|dD];\}}t|t|k(}tj||k(}||k(r;Jt|t|j k7sJy)NrA)repeat) itertoolsproductrr allT)rfrcrdrerHrIrKare_arrays_equals rtest_hash_numpy_arraysrns&D$''B4 d:d366$$,/#33334 :dff %% %rc|\}}}||d}||d}||d}t|t|k(sJt|t|k7sJy)N)r@rAr)rfrcrdred1d2d3s rtest_hash_numpy_dict_of_arraysrssX&D$ d B d B d B 8tBx   8tBx  rdtypez datetime64[s]ztimedelta64[D]cttjd}tjdd|}t||k7sJy)NrOrrt)rr arange)rta_hasharrays rtest_numpy_datetime_arrayrzs: "))B- F IIa5 )E ;&  rcFtjtjdjddddddddf}tj|}t |t |k7sJtj |}t |t |k7sJy)Nip)rArF)orderr@)r asarrayrwreshapeascontiguousarrayrasfortranarray)rCrDcs rtest_hash_numpy_noncontiguousrs 299T?**<8DQAXNA QA 7d1g   !A 7d1g  r coerce_mmapTFcn|jdj} tj|dd}tj|}t ||t ||k(}||k(sJ dt vr~tjyy#dt vr~tjwwxYw)zECheck that memmap and arrays hash identically if coerce_mmap is True. memmap_tempr]zw+)shapemode)rmN) joinstrpathr memmaprrlocalsgccollect)tmpdirrfilenamerrCrKs rtest_hash_memmaprs{{=)11H  IIhhT : JJqM{;t ;@   ;... &(? JJL 3&(? JJL s AB$B4win32z5This test is not stable under windows for some reason)reasonctjjd}|jd}d}t |t |}|dksJdt ||z}t t |||f}dt||z ||zz z}|dksJy)aCheck the performance of hashing numpy arrays: In [22]: a = np.random.random(1000000) In [23]: %timeit hashlib.md5(a).hexdigest() 100 loops, best of 3: 20.7 ms per loop In [24]: %timeit hashlib.md5(pickle.dumps(a, protocol=2)).hexdigest() 1 loops, best of 3: 73.1 ms per loop In [25]: %timeit hashlib.md5(cPickle.dumps(a, protocol=2)).hexdigest() 10 loops, best of 3: 53.9 ms per loop In [26]: %timeit hash(a) 100 loops, best of 3: 20.8 ms per loop ri@BcZtjt|jSr)hashlibmd5 memoryview hexdigest)r1s rmd5_hashz-test_hash_numpy_performance..md5_hashs{{:a=)3355rg333333?rr$N)r r^r_r`r+rr"r%)rbrCrr* time_hashlib time_hashs rtest_hash_numpy_performancers, ))   "C '"A6"(D!4M 3  y1--L$Aq *I3y<78I >> > k* +t !#;<0   k* +t !;/0  rzto_hash,expected)zThis is a string to hash 71b3f47df22cb19431d85d92d0b230b2)u C'est lété 2d8d189e9b2b0b2e384d93c868c0e576))i@i1i3~ e205227dd82250871fa25aa0ec690aa3* a11ffad81f9682a7d901e6edc3d16c84{)irAr)abcdesadfas aeda150553d4bb5c69f0e69d51b0e2efc$t||k(sJyrr)to_hashexpecteds rtest_hashes_stay_the_samers& =H $$ $rctjjd}|jd}tj|}t |t |k7sJy)Nrr])r r^r_r`rr)rngarr_carr_fs rAtest_hashes_are_different_between_c_and_fortran_contiguous_arraysrsN ))   "C   h 'E   e $E ;$u+ %% %rc@ttjdyNrrr ryrrr test_0d_arrayrs!rcttjdttjdgk7sJyrrrrr)test_0d_and_1d_array_hashing_is_differentrs,  RXXqc] 3 33 3rcd}|}|}td}td} t||D]\}}|jt|j }|jt|j }||k(sJ|jt|j } || k(rJ |j |j y#|j |j wxYw)Nc tjjdjdddj dt fdt dDt dDcgc]"}jd j d $c}jd dj d jd d j djd j d gdtjddjdtjtjddjdtjddjdddddfg}|Scc}w)Nrir|2)highsizezz_test_hashes_stay_the_same_with_numpy_objects..create_objects_to_hash..s$?#))A,%%e,?s*-rrrrO)r)irdrvr]rA) r r^r_randintrtuplerrrwrr)r to_hash_listrs @rcreate_objects_to_hashzLtest_hashes_stay_the_same_with_numpy_objects..create_objects_to_hashs9ii##B' KKDrK 2 9 9% @ ?eAh? ?16q :ASYYq\  ' :yyA--e4KKK,33E:IIbM((/  IIc ' / / 9   bii59AA(K L IIc ' / / 9!RaR% @# &! ;s,'Fr@) max_workers)rzipsubmitrresultshutdown) rto_hash_list_oneto_hash_list_twoe1e2obj_1obj_2hash_1hash_2hash_3s r,test_hashes_stay_the_same_with_numpy_objectsrs">./-/  +B  +B  02BC $LE5YYtU+224FYYtU+224FV# ##YYtU+224FV# ## $    sB C6C"C=cd}ttj5}t|dddj dy#1swYxYw)Ncy)Nrrrrr non_picklablez2test_hashing_pickling_error..non_picklablesrzPicklingError while hashing)r r PicklingErrorrmatch)rexcinfos rtest_hashing_pickling_errorr sC $$ % ] MM/0s AA cvd}tt|5ddi}t|ddddy#1swYyxYw)Nz!Valid options for 'hash_name' are)r rrinvalid) hash_name)r ValueErrorr)msgdatas rtest_wrong_hash_namers9 -C  # &(u~ TY'(((s/8)B__doc__rTrrrQrirr^sysrconcurrent.futuresrdecimalrjoblib.func_inspectrjoblib.hashingr joblib.memoryrjoblib.test.commonr r joblib.testingr r r rrr"r+rr-r8rrr input_listrMrYrfrnrsrzrrplatformrrrrrrrrrrrRandomrrrrrr r)r s0rr s   2+ -?? F F     FFFJJ  fM N a!E# L VZ  VZ 2!!2. z  &   W(89:!; !    ]T5M*+ & LLG B  DP    6:( % %P H@E16q :A]V]]2  % % ' : . - 02TU  % % & &   4 4 B BJ1(e ;s 'G1