diff options
author | Andrew Eckart <andrew.g.eckart@gmail.com> | 2021-08-28 12:58:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-28 10:58:10 -0700 |
commit | 7090340356943548ea5c7691ed2a676a63a1ed46 (patch) | |
tree | f2fcb17f2f5fafec364a61ca41dd45da3d0d3ca8 /networkx | |
parent | f27522c9717ea5455d4634f9ed71d3f5e48e5528 (diff) | |
download | networkx-7090340356943548ea5c7691ed2a676a63a1ed46.tar.gz |
Store `G.adj` as a local variable to speed up `complement_edges(G)` (#5032)
Diffstat (limited to 'networkx')
-rw-r--r-- | networkx/algorithms/connectivity/edge_augmentation.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/networkx/algorithms/connectivity/edge_augmentation.py b/networkx/algorithms/connectivity/edge_augmentation.py index dc8b8607..2939d3bc 100644 --- a/networkx/algorithms/connectivity/edge_augmentation.py +++ b/networkx/algorithms/connectivity/edge_augmentation.py @@ -1124,15 +1124,16 @@ def complement_edges(G): >>> sorted(complement_edges(G)) [] """ + G_adj = G._adj # Store as a variable to eliminate attribute lookup if G.is_directed(): for u, v in it.combinations(G.nodes(), 2): - if v not in G.adj[u]: + if v not in G_adj[u]: yield (u, v) - if u not in G.adj[v]: + if u not in G_adj[v]: yield (v, u) else: for u, v in it.combinations(G.nodes(), 2): - if v not in G.adj[u]: + if v not in G_adj[u]: yield (u, v) |