+
    &jBB                       ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t
 ^ RIHtHt ^ RIHt ^ RIHt ^ RIHtHtHtHt ^ RIHtHt ^ R	IHt ]'       d   ^ R
IHt ^ RIHtH t H!t!H"t" ]! ]#4      PI                  4       PJ                  t&]&PJ                  t' ! R R]4      t(Rt)R R lt*]! R4      t+]! R4      t,R R lt-R R lt.]P^                  R R l4       t0]Pb                  R R l4       t2R R lt3 ! R R4      t4R-R R  llt5R.R! R" llt6R# R$ lt7R% R& lt8R' R( lt9 ! R) R*4      t: ! R+ R,]]+,          4      t;R# )/    )annotationsN)is_dataclass)autoEnum)Pathpformat)AnyGenericTYPE_CHECKINGTypeVar)assert_neverSelf)CodeTemplate)	Namespace)CallableIterableIteratorSequencec                  j    ] tR t^%t]! 4       t]! 4       t]! 4       t]! 4       t]! 4       t	]! 4       t
RtR# )Target N)__name__
__module____qualname____firstlineno__r   
DEFINITIONDECLARATIONREGISTRATIONANONYMOUS_DEFINITIONNAMESPACED_DEFINITIONNAMESPACED_DECLARATION__static_attributes__r       f/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torchgen/utils.pyr   r   %   s/    J&K6L6 F!Vr$   r   z(^|\W){}($|\W)c                    V ^8  d   QhRRRR/# )   schemastrreturnztuple[str, list[str]]r   )formats   "r%   __annotate__r,   8   s     $ $c $&; $r$   c                    \         P                  ! R V 4      pVf   \        RV  24      hVP                  4       w  r#pW$P	                  R4      3# )z(\w+)(\.\w+)?\((.*)\)zUnsupported function schema: , )rematchRuntimeErrorgroupssplit)r(   mname_paramss   &    r%   split_name_paramsr8   8   sL    
)62Ay:6(CDDhhjODVd###r$   TSc               $    V ^8  d   QhRRRRRR/# )r'   funczCallable[[T], S | None]xsIterable[T]r*   Iterator[S]r   )r+   s   "r%   r,   r,   H   s"      *   r$   c              #  D   "   V F  pV ! V4      pVf   K  Vx  K  	  R # 5iNr   )r<   r=   xrs   &&  r%   mapMayberD   H   s"     G=G s    
 c               $    V ^8  d   QhRRRRRR/# )r'   r<   zCallable[[T], Sequence[S]]r=   r>   r*   r?   r   )r+   s   "r%   r,   r,   P   s"      . K K r$   c              #  D   "   V F  pV ! V4       R j  xL
  K  	  R #  L
5irA   r   )r<   r=   rB   s   && r%   	concatMaprG   P   s     7 s     c                    V ^8  d   QhRRRR/# )r'   msg_fnzCallable[[], str]r*   zIterator[None]r   )r+   s   "r%   r,   r,   Y   s     	 	% 	. 	r$   c              #    "    R x  R #   \          dq   pT ! 4       p\        P                  ! TR4      pTP                  '       d   TP                  ^ ,           RT 2MTpT3TP                  R,          ,           Tn        h R p?ii ; i5i)Nz  
   NN)	Exceptiontextwrapindentargs)rI   emsgs   &  r%   contextrT   X   sn      hooc4('(vvv2cU#3!&&*$s%   B
 BBA+B  BBc                    V ^8  d   QhRRRR/# )r'   template_fnr)   r*   r   r   )r+   s   "r%   r,   r,   f   s     / / / /r$   c                .    \         P                  ! V 4      # rA   )r   	from_file)rV   s   &r%   _read_templaterY   e   s    !!+..r$   c                    V ^8  d   QhRRRR/# )r'   sr)   r*   intr   )r+   s   "r%   r,   r,   k   s     4 4# 4# 4r$   c                    \         P                  ! V P                  R 4      RR7      P                  4       p\        P                  VRR7      # )latin1F)usedforsecuritylittle)	byteorder)hashlibsha1encodedigestr\   
from_bytes)r[   rc   s   & r%   string_stable_hashrg   k   s7    <<*EBIIKD>>$(>33r$   c                      ] tR t^stR R lt]R R l4       tR R ltR R ltR	 R
 lt	R R lt
RR/R R lltRR/R R lltR R ltR R ltRtR# )FileManagerc               (    V ^8  d   QhRRRRRRRR/# )r'   install_dir
str | Pathtemplate_dirdry_runboolr*   Noner   )r+   s   "r%   r,   FileManager.__annotate__t   s2     	 		 !	 		
 
	r$   c                	p    \        V4      V n        \        V4      V n        \        4       V n        W0n        R # rA   )r   rk   rm   setfilesrn   )selfrk   rm   rn   s   &&&&r%   __init__FileManager.__init__t   s,      , . #
r$   c                   V ^8  d   QhRR/# )r'   r*   zfrozenset[str]r   )r+   s   "r%   r,   rq      s     C C> Cr$   c                	p    \        V P                   Uu0 uF  qP                  4       kK  	  up4      # u upi rA   )	frozensetrt   as_posix)ru   files   & r%   	filenamesFileManager.filenames   s'    djjAjd--/jABBAs   3c               $    V ^8  d   QhRRRRRR/# )r'   filenamerl   contentsr)   r*   rp   r   )r+   s   "r%   r,   rq      s!     
8 
8* 
8 
8 
8r$   c                	    \        V4      pR p VP                  RR7      pW$8w  d3   VP                  P	                  RRR7       VP                  VRR7       R # R #   \         d     LGi ; i)Nzutf-8)encodingT)parentsexist_ok)r   	read_textOSErrorparentmkdir
write_text)ru   r   r   r|   old_contentss   &&&  r%   _write_if_changedFileManager._write_if_changed   sm    H~#'	>>7>;L #KKdT:OOHwO7 $  		s   A A)(A)c               $    V ^8  d   QhRRRRRR/# )r'   rV   rl   env_callable"Callable[[], str | dict[str, Any]]r*   r)   r   )r+   s   "r%   r,   rq      s(     3 33 93 
	3r$   c                	6   \        V4      P                  4       '       d   \        R V 24      hV P                  V,          pV! 4       p\	        V\
        4      '       d   RV9  d   \        R,          p \        \        P                  R,          P                  ;'       g    T4      P                  4       p VP                  \        4      P                  4       p/ VCRRRV RV 2,           /Cp\%        V4      pVP'                  V4      p	\(        P*                  ! RRV	\(        P,                  R	7      # \	        V\.        4      '       d   V# \1        V4       R
#   \        \        3 d    TP                  4       p Li ; i  \          d    TP"                  p Li ; i)ztemplate_fn must be relative: generated_commentzgen.py__main__@zgenerated by z from z
                (""")\n+             # match triple quotes
                (
                    (\s*@.+\n)*     # match decorators if any
                    \s*(class|def)  # match class/function definition
                )
                z\g<1>\n\n\g<2>)flagsN)r   is_absoluteAssertionErrorrm   
isinstancedictTORCHGEN_ROOTsysmodules__file__absoluteKeyErrorAttributeErrorrelative_to	REPO_ROOTr{   
ValueErrorr5   rY   
substituter/   subVERBOSEr)   r   )
ru   rV   r   template_pathenvgenerator_default	generatorgenerator_pathtemplatesubstitute_outs
   &&&       r%   substitute_with_template$FileManager.substitute_with_template   s~   
 ((** #A+!OPP))K7nc4  "#-$1H$<!= $J/88MM<M!hj 4%.%:%:9%E%N%N%PN'n-=VK=QQ &m4H%005N 66 "jj  c3JSG !.1 = 1 : : <I=
 " 4%.^^N4s*   3,E  E 6#E> !E;:E;>FFc               (    V ^8  d   QhRRRRRRRR/# )r'   r   rl   rV   r   r   r*   rp   r   )r+   s   "r%   r,   rq      s8     K KK  K 9	K
 
Kr$   c                	n   \        V4      pVP                  4       '       d   \        R V 24      hV P                  V,          pW@P                  9   d   \        RV 24      hV P                  P                  V4       V P                  '       g(   V P                  VVR7      pV P                  WER7       R# R# )filename must be relative: zduplicate file write )rV   r   )r   r   N)	r   r   r   rk   rt   addrn   r   r   )ru   r   rV   r   r|   r   s   &&&&  r%   write_with_templateFileManager.write_with_template   s     >!! #>xj!IJJ(*:: #8!?@@

t|||!::') ; N ""D"J r$   c               $    V ^8  d   QhRRRRRR/# )r'   r   rl   r   r   r*   rp   r   )r+   s   "r%   r,   rq      s-     C CC 9C 
	Cr$   c                	*    V P                  WV4       R # rA   )r   )ru   r   r   s   &&&r%   writeFileManager.write   s    
 	  \Br$   base_envNc               8    V ^8  d   QhRRRRRRRRR	R
RRRRRR/# )r'   r   rl   itemsr>   key_fnCallable[[T], str]r   #Callable[[T], dict[str, list[str]]]
num_shardsr\   r   dict[str, Any] | Nonesharded_keysset[str]r*   rp   r   )r+   s   "r%   r,   rq      sZ     
 

 

 #
 :
 
 (
 
 

r$   c               	8    V P                  VVVVVVVVR 7       R# ))r   r   r   r   r   N)write_sharded_with_template)ru   r   r   r   r   r   r   r   s   &&&$$$$$r%   write_shardedFileManager.write_sharded   s/     	((%!% 	) 		
r$   c               <    V ^8  d   QhRRRRRRRRRR	R
RRRRRRR/	# )r'   r   rl   rV   r   r>   r   r   r   r   r   r\   r   r   r   r   r*   rp   r   )r+   s   "r%   r,   rq      so     =X =X=X  =X 	=X #=X :=X =X (=X =X 
=Xr$   c               	  aa \        V4      p	V	P                  4       '       d   \        R V 24      hRR/p
\        V4       Uu. uF
  pRRV 2/NK  	  ppV
.V,           pVe   V F  oSP	                  V4       K  	  S F\  pV FS  oVS9   dE   \        SV,          \        4      '       g   \        R4      hSV,          P                  4       SV&   KN  . SV&   KU  	  K^  	  R V3R llpV P                  '       d   R	pV F>  pV! V4      p\        V4      V,          pV! V4      pV! VV,          V4       V! V
V4       K@  	  V F@  oSR,          pV P                  V	P                  V	P                   V 24      VV3R l4       KB  	  V P                  P                  V P                  V	P                  V	P                   R24      ,          4       R# u upi )
r   shard_id
Everythingr6   Nz'sharded keys in base_env must be a listc               $    V ^8  d   QhRRRRRR/# )r'   intozdict[str, list[str]]from_r*   rp   r   )r+   s   "r%   r,   =FileManager.write_sharded_with_template.<locals>.__annotate__  s$     	 	0 	9M 	RV 	r$   c                   < VP                  4        F.  w  r#VS9  d   \        R V 24      hW;;,          V,          uu&   K0  	  R# )zundeclared sharded key N)r   r   )r   r   kvr   s   &&  r%   	merge_env:FileManager.write_sharded_with_template.<locals>.merge_env  s;    L((+B1#)FGG1 &r$   c                    < S # rA   r   )shards   r%   <lambda>9FileManager.write_sharded_with_template.<locals>.<lambda>/  s    r$   r   )r   r   r   rangeupdater   listcopyrn   rg   r   	with_stemstemrt   discardrk   )ru   r   rV   r   r   r   r   r   r   r|   
everythingishards
all_shardskeyr   itemsidr   r   r   s   &&&&$$$$d           @r%   r   'FileManager.write_sharded_with_template   s    H~ #>xj!IJJ&0,%?
+0+<(
+<aZ1QC!+< 	 (
 !\F*
#X& $  C#%<%eCj$77,-VWW!&s!2E#J!#E#J $  	 	 <<<ED,C$S)J6Ct$CfSk3'j#&   EZ(H$$$))XJ78   	

4++dnn		{*=U.VVW[(
s   Gc               $    V ^8  d   QhRRRRRR/# )r'   variable_namer)   r   rl   r*   rp   r   )r+   s   "r%   r,   rq   5  s!     2 23 2* 2 2r$   c                    RP                  RV.R \        V P                  4       4       ORN54      pV P                  W#4       R# )zSWrite a file containing the list of all outputs which are generated by this script.rK   zset(c              3  J   "   T F  pR VP                  4        R2x  K  	  R# 5i)z    ""N)r{   ).0r|   s   & r%   	<genexpr>,FileManager.write_outputs.<locals>.<genexpr><  s"     L9KE$--/*!,9Ks   !#)N)joinsortedrt   r   )ru   r   r   contents   &&& r%   write_outputsFileManager.write_outputs5  sN    )) M

9KL	
 
 	x1r$   c                   V ^8  d   QhRR/# r'   r*   r)   r   )r+   s   "r%   r,   rq   B  s     M M3 Mr$   c                    \         P                  P                  V P                  \         P                  P	                  \
        4      4      # )z
This needs to be deterministic. The template dir is an absolute path
that varies across builds. So, just use the path relative to this file,
which will point to the codegen source but will be stable.
)ospathrelpathrm   dirnamer   ru   s   &r%   template_dir_for_comments%FileManager.template_dir_for_commentsB  s,     wwt00"''//(2KLLr$   )rn   rt   rk   rm   )r   r   r   r   rv   propertyr}   r   r   r   r   r   r   r   r   r#   r   r$   r%   ri   ri   s   sf    	 C C
83jK(C
 +/
,=X +/=X~2M Mr$   ri   c               $    V ^8  d   QhRRRRRR/# )r'   optionsr   rk   zstr | Path | Noner*   ri   r   )r+   s   "r%   r,   r,   L  s&     
 

"
 
r$   c                    \         P                  P                  V P                  R 4      pV'       d   TMV P                  p\        VVV P                  R7      # )	templates)rk   rm   rn   )r   r   r   source_pathrk   ri   rn   )r  rk   rm   s   && r%   make_file_managerr  L  sG     77<< 3 3[AL!,+'2E2EK! r$   c               (    V ^8  d   QhRRRRRRRR/# )r'   objr
   rP   r\   widthr*   r)   r   )r+   s   "r%   r,   r,   Z  s0     ' '	'' ' 		'r$   c                    \        WV4      # rA   r   )r  rP   r	  s   &&&r%   dataclass_reprr  Z  s    
 3&&r$   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r'   attrzdict[Any, Any]rP   r\   r	  curr_indentr*   r)   r   )r+   s   "r%   r,   r,   b  sA     D D
DD D 	D
 	Dr$   c           
     $   W1^,           ,          p. pV P                  4        F^  w  rV\        V4      p\        V4      '       d   \        WaW#\	        V4      ,           4      M
\        V4      pVP                  V RV 24       K`  	  \        WAW#RR4      # )   z: {})r   reprr   r	   lenappend_format)	r  rP   r	  r  	dict_reprr   r   k_reprv_strs	   &&&&     r%   _format_dictr  b  s     A:KI

a A AuCK&?@a 	
 	F82eW-.  9e#sCCr$   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r'   r  z&list[Any] | set[Any] | tuple[Any, ...]rP   r\   r	  r  r*   r)   r   )r+   s   "r%   r,   r,   v  sA     F F
0FF F 	F
 	Fr$   c           	         W1^,           ,          pV  Uu. uF+  p\        V4      '       d   \        WAW#4      M
\        V4      NK-  	  pp\        V \        4      '       d   RMRw  rg\        WQW#Wg4      # u upi )rM   )[])(r   )r   r	   r  r   r   r  )r  rP   r	  r  l	list_reprstartends   &&&&    r%   _format_listr$  v  su     A:K A 3?q//5.tAwN    *$55:JE9e%EEs   1A0c               4    V ^8  d   QhRRRRRRRRRRR	RR
R/# )r'   
fields_strz	list[str]rP   r\   r	  r  r"  r)   r#  r*   r   )r+   s   "r%   r,   r,     sN     - --- - 	-
 - 
- 	-r$   c                    R R rv\        \        V 4      4      V8  d   RpRV,          pRV,          pRV V 2P                  V 4      p	V V V	 V 2# ) rK    r.   )r  r  r   )
r&  rP   r	  r  r"  r#  	delimitercurr_indent_str
indent_strbodys
   &&&&&&    r%   r  r    sh     "$R
4
%	+vJ	{?+,11*=DWZLse,,r$   c                      ] tR tRtRtRR R llt]RR R ll4       t]R R l4       t	]R	 R
 l4       t
]R R l4       tRR R lltRtR# )NamespaceHelperi  zA helper for constructing the namespace open and close strings for a nested set of namespaces.

e.g. for namespace_str torch::lazy,

prologue:
namespace torch {
namespace lazy {

epilogue:
} // namespace lazy
} // namespace torch
c               (    V ^8  d   QhRRRRRRRR/# )r'   namespace_strr)   entity_name	max_levelr\   r*   rp   r   )r+   s   "r%   r,   NamespaceHelper.__annotate__  s2     ( (( ( 	(
 
(r$   c                	\   VP                  R 4      p\        V4      V8  d   \        RV RV R24      hWn        RP	                  V Uu. uF	  pRV R2NK  	  up4      V n        RP	                  \        V4       Uu. uF  pRV 2NK
  	  up4      V n        W@n        W n	        R# u upi u upi )	::z"Codegen doesn't support more than z# level(s) of custom namespace. Got .rK   z
namespace z {z} // namespace N)
r3   r  r   cpp_namespace_r   	prologue_reversed	epilogue_namespaces_entity_name_)ru   r1  r2  r3  cpp_namespacesns   &&&&  r%   rv   NamespaceHelper.__init__  s     ',,T2~* 4YK @))6q:  ,#PAj3$7#PQ-5n-EF-Es#-EF
 *' $QFs   	B$<B)c               $    V ^8  d   QhRRRRRR/# )r'   namespaced_entityr)   r3  r\   r*   r/  r   )r+   s   "r%   r,   r4    s&     
 


 

r$   c                x    V P                  R4      pVR,          pRP                  VRR 4      p\        WCVR7      # )za
Generate helper from nested namespaces as long as class/function name. E.g.: "torch::lazy::add"
r6  N)r1  r2  r3  )r3   r   r/  )rB  r3  namesr2  r1  s   &&   r%   from_namespaced_entity&NamespaceHelper.from_namespaced_entity  sC     "''-Bi		%*-'I
 	
r$   c                   V ^8  d   QhRR/# r   r   )r+   s   "r%   r,   r4          # r$   c                	    V P                   # rA   )r9  r   s   &r%   prologueNamespaceHelper.prologue      ~~r$   c                   V ^8  d   QhRR/# r   r   )r+   s   "r%   r,   r4    rI  r$   c                	    V P                   # rA   )r;  r   s   &r%   epilogueNamespaceHelper.epilogue  rM  r$   c                   V ^8  d   QhRR/# r   r   )r+   s   "r%   r,   r4    s     ! !S !r$   c                	    V P                   # rA   )r=  r   s   &r%   r2  NamespaceHelper.entity_name  s       r$   c                    V ^8  d   QhRRRR/# )r'   defaultr)   r*   r   )r+   s   "r%   r,   r4    s     G G Gc Gr$   c                B    V P                   '       d   V P                   # T# )z
Return the namespace string from joining all the namespaces by "::" (hence no leading "::").
Return default if namespace string is empty.
)r8  )ru   rV  s   &&r%   get_cpp_namespace!NamespaceHelper.get_cpp_namespace  s     
 '+&9&9&9t""FwFr$   )r8  r=  r;  r<  r9  N)r(  r'   )r'   )r(  )r   r   r   r   __doc__rv   staticmethodrF  r   rK  rP  r2  rX  r#   r   r$   r%   r/  r/    sh    (* 
 
     ! !G Gr$   r/  c                      ] tR tRt$ R]R&   RR R lltR R ltR	 R
 ltR R ltR R lt	R R lt
]R R l4       tR R ltR R ltR R ltRtR# )
OrderedSeti  zdict[T, None]storageNc                    V ^8  d   QhRRRR/# )r'   iterablezIterable[T] | Noner*   rp   r   )r+   s   "r%   r,   OrderedSet.__annotate__  s     3 3!3 3t 3r$   c                	T    Vf
   / V n         R # \        P                  V4      V n         R # rA   )r^  r   fromkeys)ru   r`  s   &&r%   rv   OrderedSet.__init__  s    DL==2DLr$   c                    V ^8  d   QhRRRR/# )r'   r   r9   r*   ro   r   )r+   s   "r%   r,   ra    s     $ $ $t $r$   c                	    WP                   9   # rA   r^  ru   r   s   &&r%   __contains__OrderedSet.__contains__  s    ||##r$   c                   V ^8  d   QhRR/# )r'   r*   zIterator[T]r   )r+   s   "r%   r,   ra    s     ) )+ )r$   c                	H    \        V P                  P                  4       4      # rA   )iterr^  keysr   s   &r%   __iter__OrderedSet.__iter__  s    DLL%%'((r$   c                    V ^8  d   QhRRRR/# )r'   r   OrderedSet[T]r*   rp   r   )r+   s   "r%   r,   ra    s     + +M +d +r$   c                	P    V P                   P                  VP                   4       R # rA   )r^  r   )ru   r   s   &&r%   r   OrderedSet.update  s    EMM*r$   c                    V ^8  d   QhRRRR/# )r'   r   r9   r*   rp   r   )r+   s   "r%   r,   ra    s     " " "d "r$   c                	$    R V P                   V&   R # rA   rg  rh  s   &&r%   r   OrderedSet.add  s    !Tr$   c                   V ^8  d   QhRR/# )r'   r*   rr  r   )r+   s   "r%   r,   ra    s      m r$   c                	X    \        4       pV P                  P                  4       Vn        V# rA   )r]  r^  r   )ru   rets   & r%   r   OrderedSet.copy  s"    '\ll'')
r$   c                    V ^8  d   QhRRRR/# )r'   rQ   rr  r*   r   )r+   s   "r%   r,   ra    s      ] } r$   c                 	v    V ^ ,          P                  4       pV R,           F  pVP                  V4       K  	  V# )r   rL   )r   r   )rQ   rz  r[   s   *  r%   unionOrderedSet.union  s1    1gllnbAJJqM 
r$   c                    V ^8  d   QhRRRR/# )r'   otherrr  r*   r   )r+   s   "r%   r,   ra     s     - -M -m -r$   c                	,    \         P                  W4      # rA   )r]  r~  ru   r  s   &&r%   __or__OrderedSet.__or__   s    ,,r$   c                    V ^8  d   QhRRRR/# )r'   r  rr  r*   r   r   )r+   s   "r%   r,   ra    s      ] t r$   c                	(    V P                  V4       V # rA   )r   r  s   &&r%   __ior__OrderedSet.__ior__  s    Er$   c                    V ^8  d   QhRRRR/# )r'   r  objectr*   ro   r   )r+   s   "r%   r,   ra    s     5 5F 5t 5r$   c                	    \        V\        4      '       d   V P                  VP                  8H  # \        V P                  P	                  4       4      V8H  # rA   )r   r]  r^  rs   rn  r  s   &&r%   __eq__OrderedSet.__eq__  s?    eZ((<<5==00t||((*+u44r$   rg  rA   )r   r   r   r   __annotations__rv   ri  ro  r   r   r   r[  r~  r  r  r  r#   r   r$   r%   r]  r]    sN    3$)+"
  -5 5r$   r]  rA   )r   P   )<
__future__r   
contextlib	functoolsrb   r   r/   r   rO   dataclassesr   enumr   r   pathlibr   pprintr	   typingr
   r   r   r   typing_extensionsr   r   torchgen.code_templater   argparser   collections.abcr   r   r   r   r   r   r   r   r   r   IDENT_REGEXr8   r9   r:   rD   rG   contextmanagerrT   cacherY   rg   ri   r  r  r  r$  r  r/  r]  r   r$   r%   <module>r     s   "    	 	 
  $    7 7 0 / "FF X'')00  	
$T 
$  $ CLCL 	 	 / /
4UM UMr
'D(F-&DG DGN,5 ,5r$   