
     Ti8                    \   S r SSKJr  SS/rSSKrSSKrSSKJrJr  SSK	J
r
Jr  SSKrSSKJrJr  \" S	5      r\R                   " \5      r " S
 S\R&                  S   5      r " S S\5      r " S S\5      r " S S\R.                  \S4   5      r " S S\R.                  \S4   5      rg)zTracked containers for graph.    )annotationsGraphInputsGraphOutputsN)IterableSequence)SupportsIndexTypeVar)_core
_protocolsTc                     ^  \ rS rSrSrSSU 4S jjjrSS jrSS jrSS jrSU 4S jjr	SU 4S jjr
SU 4S	 jjrSSU 4S
 jjjrSU 4S jjrSU 4S jjrSS jrSU 4S jjrS rS r\r\r\r\r\rSrU =r$ )_GraphIO   z"The inputs and outputs of a Graph.c                   > Xl         [        R                  " 5       U l        Ub%  [	        U5      nU H  nU R                  U5        M     [        TU ]  U5        U R                  5         g N)	_graphcollectionsCounter_ref_countertuple
_set_graphsuper__init___check_invariance)selfgraphinitlistvalue	__class__s       X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx_ir/_graph_containers.pyr   _GraphIO.__init__   sZ     ?J>Q>Q>SXH!& ""     c                    [         e)"Check the invariance of the graph.NotImplementedErrorr   s    r    r   _GraphIO._check_invariance.       !!r"   c                    [         e)Set the graph for the value.r%   r   r   s     r    r   _GraphIO._set_graph2   r)   r"   c                    [         e)Unset the graph for the value.r%   r,   s     r    _maybe_unset_graph_GraphIO._maybe_unset_graph6   r)   r"   c                f   > U R                  U5        [        TU ]	  U5        U R                  5         g)zAdd a new input to the graph.N)r   r   appendr   r   itemr   s     r    r3   _GraphIO.append:   s)     	t r"   c                n   > [        U5      nU H  nU R                  U5        M     [        TU ]  U5        g)z%Extend the list of inputs or outputs.N)r   r   r   extend)r   otherr5   r   s      r    r8   _GraphIO.extendA   s.    eDOOD! ur"   c                f   > [         TU ]  X5        U R                  U5        U R                  5         g)z$Insert an input/output to the graph.N)r   insertr   r   )r   ir5   r   s      r    r<   _GraphIO.insertH   s'    q r"   c                h   > [         TU ]  U5      nU R                  U5        U R                  5         U$ )&Remove an input/output from the graph.)r   popr0   r   )r   r=   r   r   s      r    rA   _GraphIO.popN   s/    A& r"   c                f   > [         TU ]  U5        U R                  U5        U R                  5         g)r@   N)r   remover0   r   r4   s     r    rD   _GraphIO.removeU   s)    t% r"   c                j   > U R                    H  nU R                  U5        M     [        TU ]  5         g)zClear the list.N)datar0   r   clear)r   r   r   s     r    rH   _GraphIO.clear[   s(    YYE##E* r"   c                6    U R                   R                  5       $ )z"Return a shallow copy of the list.)rG   copyr'   s    r    rK   _GraphIO.copya   s     yy~~r"   c                (  > [        U[        5      (       av  [        U[        5      (       aa  U R                  U    H  nU R	                  U5        M     U H  nU R                  U5        M     [        TU ]  X5        U R                  5         g[        U[        5      (       aO  U R	                  U R                  U   5        U R                  U5        [        TU ]  X5        U R                  5         g[        S[        U5       S[        U5       35      e)z$Replace an input/output to the node.NzInvalid types for __setitem__: z and )
isinstancer   slicerG   r0   r   r   __setitem__r   r   	TypeErrortype)r   r=   r5   r   r   s       r    rP   _GraphIO.__setitem__f   s    dH%%*Q*>*>1''. && G(""$=))##DIIaL1OOD!G(""$9$q'%T
|TUUr"   c                     U R                   U   $ )z#Get an input/output from the graph.)rG   )r   r=   s     r    __getitem___GraphIO.__getitem__{   s    yy|r"   c                    [        S5      e)zUnimplemented method.zMethod is not supported)RuntimeError)r   _args_kwargss      r    _unimplemented_GraphIO._unimplemented   s    455r"   )r   r   r   r   z_core.GraphreturnNoner   _core.Valuer_   r`   )r5   rb   r_   r`   )r=   intr5   rb   r_   r`   ))r=   rc   r_   rb   )r_   zlist[_core.Value])__name__
__module____qualname____firstlineno____doc__r   r   r   r0   r3   r8   r<   rA   rD   rH   rK   rP   rU   r[   __add____radd____iadd____mul____rmul____static_attributes____classcell__r   s   @r    r   r      sr    ,! ! """!! ! 
V*6 GHHGHr"   r   rb   c                  6    \ rS rSrSrSS jrS	S jrS	S jrSrg)
r      zThe inputs of a Graph.c                    [         R                  (       d  gU R                   H8  nUR                  U R                  L a  M  [	        SU SU R                  < 35      e   g)r$   NInvariance error: Value 'z ' is not an input of the graph: onnx_irDEBUGrG   r   
ValueErrorr,   s     r    r   GraphInputs._check_invariance   sS    }}YYE||t{{*+E72RSWS^S^Rab  r"   c                   UR                   b(  UR                   U R                   La  [        SU S35      eUR                  5       b  [        SU S35      eU R                  U==   S-  ss'   SUl        U R                   Ul         g)r+   NValue 'z^' is already owned by a different graph. Please remove the value from the previous graph firstzf' is produced by a node and cannot be an input to the graph. Please create new Values for graph inputs   T)r   ry   producerr   _is_graph_inputr,   s     r    r   GraphInputs._set_graph   s    <<#DKK(G% ~  >>'%  !G  H  	% A%  ${{r"   c                    UR                   U R                   L d   S5       eU R                  U==   S-  ss'   U R                  U   S:  a  gSUl        UR                  5       (       a  gSUl         gr/   'Bug: value does not belong to the graphr}   r   NF)r   r   r   _owned_by_graphr,   s     r    r0   GraphInputs._maybe_unset_graph   sk    ||t{{*U,UU*% A% U#a' %  ""r"    Nr^   ra   	re   rf   rg   rh   ri   r   r   r0   ro   r   r"   r    r   r      s     	#r"   c                  6    \ rS rSrSrSS jrS	S jrS	S jrSrg)
r      zThe outputs of a Graph.c                    [         R                  (       d  gU R                   H8  nUR                  U R                  L a  M  [	        SU SU R                  < 35      e   g)r$   Nru   z!' is not an output of the graph: rv   r,   s     r    r   GraphOutputs._check_invariance   sS    }}YYE||t{{*+E72STXT_T_Sbc  r"   c                    UR                   b(  UR                   U R                   La  [        SU S35      eU R                  U==   S-  ss'   SUl        U R                   Ul         g)r+   Nr|   zb' is already an output of a different graph. Please remove the value from the previous graph firstr}   T)r   ry   r   _is_graph_outputr,   s     r    r   GraphOutputs._set_graph   sf    <<#DKK(G%  !C  D  	% A% !%{{r"   c                    UR                   U R                   L d   S5       eU R                  U==   S-  ss'   U R                  U   S:  a  gSUl        UR                  5       (       a  gSUl         gr   )r   r   r   r   r,   s     r    r0   GraphOutputs._maybe_unset_graph   sk    ||t{{*U,UU*% A% U#a'!&  ""r"   r   Nr^   ra   r   r   r"   r    r   r      s    !	#r"   c                  r   ^  \ rS rSrSrS
SU 4S jjjrSS jrSS jrSU 4S jjrSU 4S jjr	SS jr
S	rU =r$ )GraphInitializers   zUThe initializers of a Graph as ``dict[str, Value]`` with additional mutation methods.c                  > 0 nUb  UR                  U5        U(       a  UR                  U5        Xl        UR                  5        H  nU R                  U5        M     [        TU ]  U5        g r   )updater   valuesr   r   r   )r   r   dictkwargsrG   r   r   s         r    r   GraphInitializers.__init__   sY    KKKK[[]EOOE" # 	r"   c                    UR                   b(  UR                   U R                   La  [        SU S35      eSUl        U R                   Ul         g)r+   Nr|   zg' is already an initializer of a different graph. Please remove the value from the previous graph firstT)r   ry   _is_initializerr,   s     r    r   GraphInitializers._set_graph   sP    <<#DKK(G%  !H  I  !%{{r"   c                    UR                   U R                   L d   S5       eSUl        UR                  5       (       a  gSUl         g)r/   r   FN)r   r   r   r,   s     r    r0   $GraphInitializers._maybe_unset_graph   s?    ||t{{*U,UU* %  ""r"   c                |  > [        U[        R                  5      (       d  [        S[	        U5       35      e[        U[
        5      (       d  [        S[	        U5       35      eUS:X  a  [        S5      eUR                  (       d  [        R                  SX!5        Xl        O+XR                  :w  a  [        SU SUR                   S35      eUR                  5       b  [        S
U S35      eXR                  ;   a   U R                  U   nU R                  U5        U R                  U5        [        TU ]=  X5        g	)z!Set an initializer for the graph.z"value must be a Value object, not z!Value name must be a string, not  z$Value name cannot be an empty stringz1Value %s does not have a name, setting it to '%s'zKey 'z(' does not match the name of the value 'z('. Please use the value.name as the key.Nr|   z9' is produced by a node and cannot be a graph initializer)rN   r
   ValuerQ   rR   strry   nameloggerinfor~   rG   r0   r   r   rP   )r   keyr   	old_valuer   s       r    rP   GraphInitializers.__setitem__   s   %--@eNOO#s##?S	{KLL"9CDDzzKKKUXJJJuDUZZLPxy  >>'% YZ  ))		#I##I. 	C'r"   c                d   > U R                   U   nU R                  U5        [        TU ]  U5        g)z%Delete an initializer from the graph.N)rG   r0   r   __delitem__r   r   r   r   s      r    r   GraphInitializers.__delitem__  s-    		# 	&C r"   c                     XUR                   '   g)z Add an initializer to the graph.Nr   r,   s     r    addGraphInitializers.add        UZZr"   )r   r   r]   ra   )r   r   r   rb   r_   r`   )r   r   r_   r`   )re   rf   rg   rh   ri   r   r   r0   rP   r   r   ro   rp   rq   s   @r    r   r      s.    _ #(8!! !r"   r   c                     ^  \ rS rSrSr      SU 4S jjrSU 4S jjrSS jrSSS jjrSSS jjr	SSS jjr
SSS	 jjrSSS
 jjrSSS jjrSSS jjrSSS jjr S     SS jjrSSS jjrSrU =r$ )
Attributesi%  zOThe attributes of a Node as ``dict[str, Attr]`` with additional access methods.c                p   > X l         [        TU ]	  U Vs0 s H  o3R                  U_M     sn5        g s  snf r   )_ownerr   r   r   )r   attrsownerattrr   s       r    r   Attributes.__init__(  s/     e<ed))T/e<=<s   3c                   > [        U5      [        La  [        S[        U5       35      e[        U[        R
                  5      (       d  [        S[        U5       35      e[        TU ]  X5        g)zSet an attribute for the node.zKey must be a string, not zValue must be an Attr, not N)rR   r   rQ   rN   r
   Attrr   rP   r   s      r    rP   Attributes.__setitem__.  s[    9C8cDEE%,,9$u+GHHC'r"   c                     XUR                   '   g)zAdd an attribute to the node.Nr   r,   s     r    r   Attributes.add6  r   r"   c                4    X;   a  X   R                  5       $ U$ )z'Get the integer value of the attribute.)as_intr   r   defaults      r    get_intAttributes.get_int:  s    ;9##%%r"   c                4    X;   a  X   R                  5       $ U$ )z%Get the float value of the attribute.)as_floatr   s      r    	get_floatAttributes.get_float@      ;9%%''r"   c                4    X;   a  X   R                  5       $ U$ )z&Get the string value of the attribute.)	as_stringr   s      r    
get_stringAttributes.get_stringF      ;9&&((r"   c                4    X;   a  X   R                  5       $ U$ )z&Get the tensor value of the attribute.)	as_tensorr   s      r    
get_tensorAttributes.get_tensorL  r   r"   c                4    X;   a  X   R                  5       $ U$ )z%Get the graph value of the attribute.)as_graphr   s      r    	get_graphAttributes.get_graphR  r   r"   c                4    X;   a  X   R                  5       $ U$ )z0Get the Sequence of integers from the attribute.)as_intsr   s      r    get_intsAttributes.get_intsX  s    ;9$$&&r"   c                4    X;   a  X   R                  5       $ U$ )z.Get the Sequence of floats from the attribute.)	as_floatsr   s      r    
get_floatsAttributes.get_floats^  r   r"   c                4    X;   a  X   R                  5       $ U$ )z/Get the Sequence of strings from the attribute.)
as_stringsr   s      r    get_stringsAttributes.get_stringsd  s    ;9''))r"   c                4    X;   a  X   R                  5       $ U$ )z/Get the Sequence of tensors from the attribute.)
as_tensorsr   s      r    get_tensorsAttributes.get_tensorsj  s     ;9''))r"   c                4    X;   a  X   R                  5       $ U$ )z.Get the Sequence of graphs from the attribute.)	as_graphsr   s      r    
get_graphsAttributes.get_graphst  r   r"   )r   )r   zIterable[_core.Attr]r   z_core.Node | _core.Functionr_   r`   )r   r   r   
_core.Attrr_   r`   )r   r   r_   r`   r   )r   r   r   r   r_   zint | T)r   r   r   r   r_   z	float | T)r   r   r   r   r_   zstr | T)r   r   r   r   r_   z_protocols.TensorProtocol | T)r   r   r   r   r_   z_core.Graph | T)r   r   r   r   r_   zSequence[int] | T)r   r   r   r   r_   zSequence[float] | T)r   r   r   r   r_   zSequence[str] | T)r   r   r   r   r_   z'Sequence[_protocols.TensorProtocol] | T)r   r   r   r   r_   zSequence[_core.Graph] | T)re   rf   rg   rh   ri   r   rP   r   r   r   r   r   r   r   r   r   r   r   ro   rp   rq   s   @r    r   r   %  s    Y>)>2M>	>(!   
1	 r"   r   r   )ri   
__future__r   __all__r   loggingcollections.abcr   r   typingr   r	   rw   r
   r   r   	getLoggerre   r   UserListr   r   r   UserDictr   r   r   r   r"   r    <module>r      s    $ # 
   . )  %CL			8	$l{##M2 l^'( 'T#8 #LH!,,S--?@ H!VS%%c<&78 Sr"   