File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -865,20 +865,21 @@ def remove_nodes(self, nodes: List[Node]):
865865 # nodes of this graph together with the edges between them.
866866 def subgraph (self , nodes : List [Node ]):
867867 subgraph = GeneralGraph (nodes )
868-
868+
869869 graph = self .graph
870-
870+
871+ nodes_to_delete = []
872+
871873 for i in range (self .num_vars ):
872874 if not (self .nodes [i ] in nodes ):
873- graph = np .delete (graph , i , axis = 0 )
874-
875- for i in range (self .num_vars ):
876- if not (self .nodes [i ] in nodes ):
877- graph = np .delete (graph , i , axis = 1 )
878-
875+ nodes_to_delete .append (i )
876+
877+ graph = np .delete (graph , nodes_to_delete , axis = 0 )
878+ graph = np .delete (graph , nodes_to_delete , axis = 1 )
879+
879880 subgraph .graph = graph
880881 subgraph .reconstitute_dpath (subgraph .get_graph_edges ())
881-
882+
882883 return subgraph
883884
884885 # Returns a string representation of the graph.
You can’t perform that action at this time.
0 commit comments