
    JTh                     $    S SK Jr   " S S5      rg)    )dequec                       \ rS rSrSrS rS rS rS rS r	\
S 5       r\
S	 5       rS
 rS rS\S\\   4S jrS\S\\   4S jrS\S\4S jrS\S\\   4S jrS\4S jrSrg)DiGraph   zReally simple unweighted directed graph data structure to track dependencies.

The API is pretty much the same as networkx so if you add something just
copy their API.
c                 J    0 U l         0 U l        0 U l        0 U l        SU l        g )Nr   )_node_succ_pred_node_order_insertion_idxselfs    N/var/www/auris/envauris/lib/python3.13/site-packages/torch/package/_digraph.py__init__DiGraph.__init__   s+    
 

     c                    XR                   ;  a[  X R                   U'   0 U R                  U'   0 U R                  U'   U R                  U R                  U'   U =R                  S-  sl        gU R                   U   R                  U5        g)zAdd a node to the graph.

Args:
    n: the node. Can we any object that is a valid dict key.
    **kwargs: any attributes you want to attach to the node.
   N)r   r	   r
   r   r   update)r   nkwargss      r   add_nodeDiGraph.add_node   sp     JJ"JJqMDJJqMDJJqM"&"5"5DQ1$JJqM  (r   c                     U R                  U5        U R                  U5        SU R                  U   U'   SU R                  U   U'   g)zrAdd an edge to graph between nodes ``u`` and ``v``

``u`` and ``v`` will be created if they do not already exist.
TN)r   r	   r
   )r   uvs      r   add_edgeDiGraph.add_edge*   sB     	aa  

1a

1ar   c                 x     [        U R                  U   5      $ ! [         a  n[        SU S35      UeSnAff = f)z.Returns an iterator over successor nodes of n.	The node  is not in the digraph.N)iterr	   KeyError
ValueErrorr   r   es      r   
successorsDiGraph.successors7   D    	L

1&& 	Ly+BCD!K	L    
949c                 x     [        U R                  U   5      $ ! [         a  n[        SU S35      UeSnAff = f)z1Returns an iterator over predecessors nodes of n.r    r!   N)r"   r
   r#   r$   r%   s      r   predecessorsDiGraph.predecessors>   r)   r*   c              #   n   #    U R                   R                  5        H  u  pU H  nX4v   M
     M     g7f)z6Returns an iterator over all edges (u, v) in the graphN)r	   items)r   r   r'   succs       r   edgesDiGraph.edgesE   s1      "ZZ--/MA"g # 0s   35c                     U R                   $ )z6Returns a dictionary of all nodes to their attributes.)r   r   s    r   nodesDiGraph.nodesL   s     zzr   c                 ,    [        U R                  5      $ )zIterate over the nodes.)r"   r   r   s    r   __iter__DiGraph.__iter__Q   s    DJJr   c                 @     XR                   ;   $ ! [         a     gf = f)z>Returns True if ``n`` is a node in the graph, False otherwise.F)r   	TypeError)r   r   s     r   __contains__DiGraph.__contains__U   s%    	

?" 		s    
srcreturnc                    [        U5      n[        U5      n[        U5      S:  ab  UR                  5       nU R	                  U5       H,  nXR;  d  M
  UR                  U5        UR                  U5        M.     [        U5      S:  a  Mb  U$ )z2Returns a set of nodes that are reachable from srcr   )setr   lenpopleftr'   addappendr   r=   resultworking_setcurr   s         r   forward_transitive_closure"DiGraph.forward_transitive_closure\   sx     SCj+"%%'C__S)?JJqM&&q) * +" r   c                    [        U5      n[        U5      n[        U5      S:  ab  UR                  5       nU R	                  U5       H,  nXR;  d  M
  UR                  U5        UR                  U5        M.     [        U5      S:  a  Mb  U$ )zGReturns a set of nodes that are reachable from src in reverse directionr   )r@   r   rA   rB   r,   rC   rD   rE   s         r   backward_transitive_closure#DiGraph.backward_transitive_closurei   sz     SCj+"%%'C&&s+?JJqM&&q) , +" r   dstc                 ^   [        5       nU R                  U5      nX$;  a  U$ [        U5      n[        U5      S:  ab  UR	                  5       nU R                  U5       H,  nXt;   d  M
  UR                  Xv5        UR                  U5        M.     [        U5      S:  a  Mb  UR                  5       $ )zAReturns a subgraph rooted at src that shows all the paths to dst.r   )	r   rI   r   rA   rB   r,   r   rD   to_dot)r   r=   rN   result_graphforward_reachable_from_srcrG   rH   r   s           r   	all_pathsDiGraph.all_pathsv   s     y%)%D%DS%I"0
 Cj+"%%'C&&s+2 ))!1&&q)	 , +" ""$$r   c                 "   / nU(       as  UR                  U5        U R                  U   R                  5       nSu  pU H2  nU R                  R	                  US5      nUc    OUb  Xd:  d  M.  UnUnM4     U(       a  Ms  [        [        U5      5      $ )z_Returns a list of nodes that show the first path that resulted in dst being added to the graph.) NN)rD   r
   keysr   getlistreversed)r   rN   path
candidatesmin_idx	candidateidxs          r   
first_pathDiGraph.first_path   s    KKC--/J#LC'	&&**9d;;?cm!G#C (	 c HTN##r   c                 R    SR                  S U R                   5       5      nSU S3$ )z^Returns the dot representation of the graph.

Returns:
    A dot representation of the graph.

c              3   8   #    U  H  u  pS U SU S3v   M     g7f)"z" -> "z";N ).0fts      r   	<genexpr>!DiGraph.to_dot.<locals>.<genexpr>   s!     DAaSqc,s   z,digraph G {
rankdir = LR;
node [shape=box];
z
}
)joinr1   )r   r1   s     r   rP   DiGraph.to_dot   s7     		DDD  	 	r   )r   r   r   r
   r	   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r'   r,   propertyr1   r4   r7   r;   strr@   rI   rL   rS   rY   r`   rP   __static_attributes__rf   r   r   r   r      s     )  LL     c c#h s s3x %S %s %0$c $d3i $$ r   r   N)collectionsr   r   rf   r   r   <module>rw      s    h hr   