L i.ddlmZddlmZddlZddlmZmZddlmZddl m Z eZ gdZ GddZ Gd d ejZGd d ejZGd deZeZGddZy)) annotationsN)MappingMutableMapping)ref)Tensor) TensorWeakRef WeakIdRefWeakIdKeyDictionaryWeakTensorKeyDictionaryceZdZdZdZdZy)_IterationGuardc$t||_yN)r weakcontainer)selfrs V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/utils/weak.py__init__z_IterationGuard.__init__s /c`|j}||jj||Sr)r _iteratingadd)rws r __enter__z_IterationGuard.__enter__#s,     = LL  T " rc|j}|1|j}|j||s|jyyyr)rrremove_commit_removals)retbrss r__exit__z_IterationGuard.__exit__)sB     = A HHTN""$ rN)__name__ __module__ __qualname__rrr!rrr r s 0 %rr c<eZdZdgZdfd ZfdZdZdZxZS)r _idcFt||_t| ||yr)idr'superrrkeycallback __class__s rrzWeakIdRef.__init__Ns c7 h'rc\t|}t|dr|j|SN _fix_weakrefr*__call__hasattrr1rrr.s rr3zWeakIdRef.__call__W) G   1n % NN rc|jSrr'rs r__hash__zWeakIdRef.__hash__^ xxrc6|}|}||||uS||uSrr%rotherars r__eq__zWeakIdRef.__eq__as. F G =Q]6Mu}rr r"r#r$ __slots__rr3r;rA __classcell__r.s@rr r KsI(rr c<eZdZdgZdfd ZfdZdZdZxZS) _WeakHashRefr'cFt||_t| ||yr)hashr'r*rr+s rrz_WeakHashRef.__init__zs 9 h'rc\t|}t|dr|j|Sr0r2r5s rr3z_WeakHashRef.__call__r7rc|jSrr9r:s rr;z_WeakHashRef.__hash__r<rc\|}|}||t|t|k(S||uSr)rIr>s rrAz_WeakHashRef.__eq__s8 F G =Q]7d1g% %u}rrrBrEs@rrGrGwsI(rrGceZdZdefdZdZdZdZdZdZ dZ d Z d Z e Z d Zdd Zd ZdZdZeZdZdZdZdZddZddZdZdZdZdZy)r Nci|_||_t|fd}||_g|_t |_d|_||j|yy)Nc|}|7|jr|jj|y |j|=yy#t$rYywxYwr)r_pending_removalsappenddataKeyError)kselfrefrs rrz,WeakIdKeyDictionary.__init__..removesS9D??**11!4 IIaL  $s A A AF) rRref_typer_removerPsetr _dirty_lenupdate)rdictrVrs rrzWeakIdKeyDictionary.__init__sT   !$i  !#%   KK  rc|jj}|j} |} ||= #t$rYywxYw#t$rYwxYwr)rPpoprR IndexErrorrS)rr]dr,s rrz$WeakIdKeyDictionary._commit_removalsse $$(( II e cF     s1A == A  A c||j}|jDcgc] }||vs| c}|_d|_ycc}wNF)rRrPrY)rr_rTs r_scrub_removalsz#WeakIdKeyDictionary._scrub_removalss7 II-1-C-C!NqAv!!N"Os 99cJd|_|j|j|=yNT)rYrRrVrr,s r __delitem__zWeakIdKeyDictionary.__delitem__s IIdmmC( )rc>|j|j|Sr)rRrVres r __getitem__zWeakIdKeyDictionary.__getitem__syys+,,rc|jr|jr|jt|jt|jz Sr)rYrPrblenrRr:s r__len__zWeakIdKeyDictionary.__len__s= ??t55  "499~D$:$: ;;;rcPd|jjdt|ddS)N)r.r"r)r:s r__repr__zWeakIdKeyDictionary.__repr__s(4>>**+44}A>>rcV||j|j||j<yr)rRrVrW)rr,values r __setitem__zWeakIdKeyDictionary.__setitem__s6; $--T\\23rct}t|5|jjD]\}}|}||||< ddd|S#1swY|SxYwr)r r rRitems)rnewr,rqos rcopyzWeakIdKeyDictionary.copysc!# T " #"iioo/ # UE="CF # #   #  s*AAAcddlm}|j}t|5|jj D]\}}|}||||||< ddd|S#1swY|SxYw)Nr)deepcopy)rwryr.r rRrt)rmemoryrur,rqrvs r __deepcopy__z WeakIdKeyDictionary.__deepcopy__sq!nn T " 3"iioo/ 3 UE=%eT2CF 3 3   3  s*A& A&&A0cX|jj|j||Sr)rRgetrVrr,defaults rr}zWeakIdKeyDictionary.gets yy}}T]]3/99rc` |j|}||jvS#t$rYywxYwra)rV TypeErrorrR)rr,wrs r __contains__z WeakIdKeyDictionary.__contains__s9 s#BTYY  s ! --c#Kt|5|jjD]\}}|}|||f dddy#1swYyxYwwrr rRrt)rrrqr,s rrtzWeakIdKeyDictionary.itemssV T " %!YY__. % Ed?u*$ % % % %s! A*A A  A AAc#Kt|5|jD]}|}| | dddy#1swYyxYwwr)r rR)rrobjs rkeyszWeakIdKeyDictionary.keyssF T " ii d?I    s A88 AAAc#Kt|5|jjD]\}}|| dddy#1swYyxYwwrr)rrrqs rvalueszWeakIdKeyDictionary.values sM T " !YY__. E4#K    s A(AA AA Ac,t|jS)azReturn a list of weak references to the keys. The references are not guaranteed to be 'live' at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the keys around longer than needed. )listrRr:s rkeyrefszWeakIdKeyDictionary.keyrefssDIIrchd|_ |jj\}}|}|||fS+rd)rYrRpopitem)rr,rqrvs rrzWeakIdKeyDictionary.popitems<**,JCA}%x rchd|_|jj|j|g|Srd)rYrRr]rV)rr,argss rr]zWeakIdKeyDictionary.pop's,tyy}}T]]3/7$77rcn|jj|j||j|Sr)rR setdefaultrVrWr~s rrzWeakIdKeyDictionary.setdefault+s-yy## MM#t|| ,g  rc |j}|Tt|dsti|}|jD]$\}}|||j ||j <&t |r|j|yy)Nrt)rRr4typertrVrWrjrZ)rr[kwargsr_r,rqs rrZzWeakIdKeyDictionary.update0st II  4)tBx~"jjl < U6;$--T\\23 < v; KK  rc(|j||Sr)rZ)rr?s r__ior__zWeakIdKeyDictionary.__ior__:s E rct|tjr#|j}|j ||St Sr) isinstance_collections_abcrrwrZNotImplementedrr?cs r__or__zWeakIdKeyDictionary.__or__>s4 e-55 6 A HHUOHrct|tjr4|j}|j ||j ||St Sr)rrrr.rZrrs r__ror__zWeakIdKeyDictionary.__ror__Es@ e-55 6 A HHUO HHTNHrct|tstS|jDcic]\}}t ||c}}|jDcic]\}}t ||c}}k(Scc}}wcc}}wr)rrrrtr))rr?rTvs rrAzWeakIdKeyDictionary.__eq__Osi%)! !%)ZZ\2TQ1q2!&7 ABqE1H7   27 s A2A8r)r"r#r$r rrrbrfrhrkrorrrw__copy__r{r}rrtr__iter__rrrr]rrZrrrrAr%rrr r s 90$ *-<?<H :%H  8   rr c*eZdZUdZded<ddZdZy)rzuWrapper around a weak ref of a Tensor that handles the _fix_weakref() call required when unwrapping a Tensor weakref.zWeakRef[Tensor]rc\t|tsJtj||_yr)rrweakrefr)rtensors rrzTensorWeakRef.__init__`s"&&)));;v&rcr|j}||St|tsJ|j|Sr)rrrr1)routs rr3zTensorWeakRef.__call__ds8hhj ;J#v&&&  rN)rr)r"r#r$__doc____annotations__rr3r%rrrr[s 'rr) __future__rcollections.abcabcrrrrrtorchrWeakRef__all__r r rGr r rr%rrrss"*3  %%d' 'X7;;D{ .{ ~.r