L i)dZddlZddlZddlZddlZddlZddlZddlZejZ Gdde Z Gdde Z Gdde Z Gd d e Zd d Zy) zb Fast cryptographic hash of Python objects, with a special case for fast hashing of numpy arrays. NceZdZdZdZy)_ConsistentSetz\Class used to ensure the hash of Sets is preserved whatever the order of its items. c t||_y#ttjf$rtd|D|_YywxYw)Nc32K|]}t|ywNhash).0es T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/joblib/hashing.py z*_ConsistentSet.__init__..%s$CT!W$Cs)sorted _sequence TypeErrordecimalInvalidOperation)self set_sequences r __init__z_ConsistentSet.__init__sF E $L1DN7334 E$$Cl$CDDN Es0AAN__name__ __module__ __qualname____doc__rr rrs  ErrceZdZdZdZy)_MyHashz5Class used to hash objects that won't normally picklec||_yr)args)rr s r rz_MyHash.__init__+s  rNrrrr rr(s ?rrceZdZdZd dZd dZdZdZdejfdZ e jjZ e e ee<e e ee<e e ee <e e eej$<dZd Zee ee<y) HasherzA subclass of pickler, to do cryptographic hashing, rather than pickling. This is used to produce a unique hash of the given Python object that is not necessarily cryptographically secure. ctj|_d}tj ||j|t j |d|_y)N)protocolF)usedforsecurity)ioBytesIOstreamPicklerrhashlibnew_hash)r hash_namer%s r rzHasher.__init__5sAjjl t{{X>[[EB rc: |j||jj }|j j||r|j jSy#tj$r"}|xjd|d|fz c_d}~wwxYw)NzPicklingError while hashing z: ) dumppickle PicklingErrorr r)getvaluer-update hexdigest)robj return_digestr dumpss r r z Hasher.hash>s  IIcN $$& % ::'') )  ##  FFsAFH HF  sA%%B8BBct|tjtijfrt |dr|j j}n |j}|j}t|tturt||j}n2| t||}n#|jj}t|||}tj||y)N__func__) isinstancetypes MethodTypetypepophasattrr:r__self__r1r __class__r*save)rr6 func_nameinstclss r rCz Hasher.saveIs cE,,d266l; <sJ'LL11 LL <.s!A41a47A,!As)r*_batch_setitemsiterrr)ritemsr s r r]zHasher._batch_setitemssc   # #D$ve}*= E E   # #d6!A5!AAB EI  s),9A('A(cBtj|t|yr)r*rCr)r set_itemss r save_setzHasher.save_sets T>)45r)md5)T)rrrrrr rCrJstructrMrPr*dispatchcopyr>lenobjectr1r0r]rbsetrrr r"r"/s C * &#%)v{{/*$$&H%HT#Y(HT&\)HT']"-HT&++  6%HT#%[rr"ceZdZdZddZdZy) NumpyHasherz1Special case the hasher for when numpy is loaded.c||_tj||ddl}||_t |dr|j |_yt|_y)z Parameters ---------- hash_name: string The hash algorithm to be used coerce_mmap: boolean Make no difference between np.memmap and np.ndarray objects. r.rN getbuffer) coerce_mmapr"rnumpynpr@rn _getbuffer memoryview)rr.rorqs r rzNumpyHasher.__init__sB' 2 2{ # llDO(DOrct||jjrF|jjs/|j dk(r|j }nL|jjr|}n3|jjr |j}n|j }|jj|j|j|jj|j r7t||jj"r|jj}n |j$}|d|j|j |j&ff}nyt||jjrY|jjdj)d|jjt+j,|yt.j1||y)zSubclass the save method, to hash ndarray subclass, rather than pickling them. Off course, this is a total abuse of the Pickler class. rHASHED _HASHED_DTYPEzutf-8N)r;rqndarraydtype hasobjectshapeflattenflags c_contiguous f_contiguousTr-r4rrviewuint8romemmaprBstridesencoder1r8r"rC)rr6obj_c_contiguousklasss r rCzNumpyHasher.savesX c477?? +CII4G4GyyB$';;= ''#& ''#&55 $';;= JJ  doo.>.C.CDGGMM.RS T JsDGGNN$C  8SYY 3;;GHC TWW]] + JJ  o44W= > JJ  fll3/ 0  D#rNrcF)rrrrrrCrrr rkrks;)*>rrkcd}||vrtdj||dtjvrt ||}n t |}|j |S)aIQuick calculation of a hash to identify uniquely Python objects containing numpy arrays. Parameters ---------- hash_name: 'md5' or 'sha1' Hashing algorithm used. sha1 is supposedly safer, but md5 is faster. coerce_mmap: boolean Make no difference between np.memmap and np.ndarray )rcsha1zAValid options for 'hash_name' are {}. Got hash_name={!r} instead.rp)r.rorm) ValueErrorformatrRrSrkr"r )r6r.rovalid_hash_nameshashers r r r sf'(( O V V )   #++ykJ), ;;s rr)rrr+r'r1rdrRr<_Picklerr*rhrrr"rkr rrr rsg //EVE&fl%Wl%^V&Vrr