From c9f90cbf896b58a5716ee061e78de6abeb5f3d2f Mon Sep 17 00:00:00 2001
From: Yoann Dufresne <yoann.dufresne0@gmail.com>
Date: Wed, 29 Apr 2020 12:23:47 +0200
Subject: [PATCH] remove sum method to replace by a for: x2 speedup

---
 deconvolution/dgraph/CliqueDGFactory.py |  3 ++-
 experiments/clique_graph_eval.py        | 16 +++++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/deconvolution/dgraph/CliqueDGFactory.py b/deconvolution/dgraph/CliqueDGFactory.py
index c30309b..9fd0564 100644
--- a/deconvolution/dgraph/CliqueDGFactory.py
+++ b/deconvolution/dgraph/CliqueDGFactory.py
@@ -67,7 +67,8 @@ class CliqueDGFactory(AbstractDGFactory):
             observed_link = len(c1 & c2)  # Intersections of the nodes are glued links
             neighbor_intersection = clique_neighbors_set[c1_idx] & c2
             neighbors_multiset = clique_neighbors_multiset[c1_idx]
-            observed_link += sum(neighbors_multiset[x] for x in neighbor_intersection)  # Sum the links between the cliques
+            for x in neighbor_intersection:
+                observed_link += neighbors_multiset[x]  # Sum the links between the cliques
 
             # Awaited links
             d_approx = max(len(c1), len(c2))
diff --git a/experiments/clique_graph_eval.py b/experiments/clique_graph_eval.py
index f9697a1..3b85627 100644
--- a/experiments/clique_graph_eval.py
+++ b/experiments/clique_graph_eval.py
@@ -10,6 +10,8 @@ from deconvolution.dgraph.CliqueDGFactory import CliqueDGFactory
 def parse_arguments():
     parser = argparse.ArgumentParser(description="Tests on graph barcode")
     parser.add_argument('barcode_graph', help='The barcode graph file. Must be a gexf formatted file.')
+    parser.add_argument('--threads', '-t', type=int, help="Number of threads to use (Set 1 for profiling)")
+    parser.add_argument('--verbose', '-v', action='store_true', help="Set the verbose flag")
 
     args = parser.parse_args()
     return args
@@ -77,10 +79,10 @@ def analyse_clique_graph(barcode_graph):
     return continuous, len(clique_graph.nodes())
 
 
-def analyse_d_graphs(barcode_graph):
+def analyse_d_graphs(barcode_graph, threads=8, verbose=False):
     # Generate udgs
     factory = CliqueDGFactory(barcode_graph, 1)
-    udg_per_node = factory.generate_all_dgraphs(threads=1)
+    udg_per_node = factory.generate_all_dgraphs(threads=threads, verbose=verbose)
     # Remove duplicate udgs
     udgs = {}
     for udg_node_lst in udg_per_node.values():
@@ -100,12 +102,12 @@ def analyse_d_graphs(barcode_graph):
 def main():
     args = parse_arguments()
     g = nx.read_gexf(args.barcode_graph)
+    # prev_time = time.time()
+    # continuous, total = analyse_clique_graph(g)
+    # print("cliques", time.time() - prev_time)
+    # print(continuous, "/", total)
     prev_time = time.time()
-    continuous, total = analyse_clique_graph(g)
-    print("cliques", time.time() - prev_time)
-    print(continuous, "/", total)
-    prev_time = time.time()
-    continuous, total = analyse_d_graphs(g)
+    continuous, total = analyse_d_graphs(g, threads=args.threads, verbose=args.verbose)
     print("udgs", time.time() - prev_time)
     print(continuous, "/", total)
 
-- 
GitLab