Hi Tamas,
I'm glad to share with you the good news that I get the issue solved !
I translate my code almost line by line from R to Python and it runs super fast: it took less than 5 minutes to sample motifs in a graph with over one million nodes.
However, the R code still runs very slowly, under Windows, Mac and Linux server environments.
I am curious about the reason behind this phenomenon, so I list the different parts between two code here:
In Python:
(1) I use neighbors method to check the neighbors:
neighbors_node1 = graph.neighbors( motif_current[0] )
node_selected = neighbors_node1[ idx_NextMotif ]
(2) to check whether the selected node is one of the neighbors of the node in current motif:
CheckMotif = node_selected in graph.neighbors( motif_current[1] )
(3) to form a new motif:
motif_next = [ motif_current[0], node_selected ]
In R:
(1) I apply ego to get the neighbors since ego runs faster than neigbhors:
neighbors_motif_current <- ego( g_OriginGraph, 1, motif_current )
neighbors_node1 <- neighbors_motif_current[[1]]
(2) to check whether the selected node is one of the neighbors of the node in current motif:
node_selected <- neighbors_node1[idx_NextMotif]
CheckMotif <- are_adjacent( g_OriginGraph, node_selected, motif_current[2] )
(3) to form a new motif:
motif_next <- c( motif_current[1], node_selected )
The above three parts are the only differences between the R and Python code, so I am wondering if the indexing of R slows down the code, or using c() to create a vector? This really confuses me a lot.