
     Ti                        S r SSKJr  S/rSSKJrJr  SSKJrJ	r	  SSK
Jr  SSKJrJr  \	\R                  \R                   \R"                  4   r " S S\\R&                     \\R&                     5      rg	)
z&Utilities for traversing the IR graph.    )annotationsRecursiveGraphIterator)Iterator
Reversible)CallableUnion)Self)_core_enumsc                  x    \ rS rSrSSSSS.         SS jjrSS jrSS jr    SS jrSS	 jrSS
 jr	Sr
g)r      NF	recursivereverseenter_graph
exit_graphc               l    Xl         X l        X0l        U R                  U5      U l        X@l        XPl        g)aC  Iterate over the nodes in the graph, recursively visiting subgraphs.

This iterator allows for traversing the nodes of a graph and its subgraphs
in a depth-first manner. It supports optional callbacks for entering and exiting
subgraphs, as well as a callback `recursive` to determine whether to visit subgraphs
contained within nodes.

.. versionadded:: 0.1.6
    Added the `enter_graph` and `exit_graph` callbacks.

Args:
    graph_like: The graph to traverse.
    recursive: A callback that determines whether to recursively visit the subgraphs
        contained in a node. If not provided, all nodes in subgraphs are visited.
    reverse: Whether to iterate in reverse order.
    enter_graph: An optional callback that is called when entering a subgraph.
    exit_graph: An optional callback that is called when exiting a subgraph.
N)_graph
_recursive_reverse_recursive_node_iter	_iterator_enter_graph_exit_graph)self
graph_liker   r   r   r   s         P/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx_ir/traversal.py__init__RecursiveGraphIterator.__init__   s1    6 !#22:>'%    c                F    U R                  U R                  5      U l        U $ N)r   r   r   r   s    r   __iter__RecursiveGraphIterator.__iter__8   s    224;;?r    c                ,    [        U R                  5      $ r"   )nextr   r#   s    r   __next__RecursiveGraphIterator.__next__<   s    DNN##r    c              #  \  #    U R                   (       a  [        U5      OUnU R                  b  U R                  U5        U HE  nUv   U R                  b  U R                  U5      (       d  M,  U R	                  U5       S h  vN   MG     U R
                  b  U R                  U5        g g  N(7fr"   )r   reversedr   r   _iterate_subgraphsr   )r   graphiterablenodes       r   r   +RecursiveGraphIterator._recursive_node_iter?   s      '+mm8E?(e$DJ*4??43H3H..t444	  'U# ( 5s   A?B,B*)B,c           
   #    #    UR                   R                  5        GH  n[        U[        R                  5      (       d  M%  UR
                  [        R                  R                  :X  a  U R                  b  U R                  UR                  5        [        UR                  U R                  U R                  U R                  U R                  S9 S h  vN   U R                  b  U R                  UR                  5        M  M  UR
                  [        R                  R                  :X  d  GM  U R                  (       a  [!        UR                  5      OUR                  nU H~  nU R                  b  U R                  U5        [        UU R                  U R                  U R                  U R                  S9 S h  vN   U R                  c  Mm  U R                  U5        M     GM     g  GN N17fNr   )
attributesvalues
isinstancer
   Attrtyper   AttributeTypeGRAPHr   valuer   r   r   r   GRAPHSr+   )r   r/   attrgraphsr-   s        r   r,   )RecursiveGraphIterator._iterate_subgraphsP   su    OO**,DdEJJ//yyF00666$$0%%djj11JJ"oo MM $ 1 1#//   ##/$$TZZ0 0f2299915$**-DJJ#E((4))%05"&// $$($5$5#'#3#3    ''3((/ $# -s2   CG1G,AG10BG1=G/>G1G1/G1c                    [        U R                  U R                  U R                  (       + U R                  U R
                  S9$ r2   )r   r   r   r   r   r   r#   s    r   __reversed__#RecursiveGraphIterator.__reversed__o   s9    %KKoo%))''
 	
r    )r   r   r   r   r   r   )
r   	GraphLiker   z#Callable[[_core.Node], bool] | Noner   boolr   "Callable[[GraphLike], None] | Noner   rD   )returnr	   )rE   
_core.Node)r-   z._core.Graph | _core.Function | _core.GraphViewrE   Iterator[_core.Node])r/   rF   )rE   rG   )__name__
__module____qualname____firstlineno__r   r$   r(   r   r,   r@   __static_attributes__ r    r   r   r      so    
 :>:>9= & & 7	 &
  & 8 & 7 &D$$C$	$"0>
r    N)__doc__
__future__r   __all__collections.abcr   r   typingr   r   typing_extensionsr	   onnx_irr
   r   GraphFunction	GraphViewrB   Noder   rM   r    r   <module>rY      sf    - "  1 " " !%++u~~u>?	a
Xejj1:ejj3I a
r    