-
-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R Interface: slow creation of weighted graphs from adjacency matrices #192
Comments
(by gabor.csardi) thanks for the excellent bug report, I'll fix this asap. |
(by gabor.csardi) |
(by richie-bowman) On Tue, May 25, 2010 at 5:32 AM, Gábor Csárdi wrote:
|
Setup:
The C library has functions for creation of weighted and unweighted graphs from dense adjacency matrices.
Problem:
The R function "graph.adjacency.dense" in structure.generators.R does not use the much faster C version when provided a weighted graph, instead using a very slow double loop in R. (an unweighted graph is created very quickly)
In addition, in rinterface.c, while igraph_adjacency() is exported to R, the igraph_weighted_adjacency(...) function is not exported to R.
Supporting data point:average timings
On my machine, for a complete graph of 900 vertices:
Unweighted graph: ~ 0.9 seconds
Weighted graph: ~ 23.9 seconds
With fix # 2 below: ~ 1.4 seconds
Proposed fixes:
######################
edges <- as.vector(t(matrix(c((which(adjmatrix != 0) - 1) %% nrow(adjmatrix) + 1,(which(adjmatrix != 0) - 1) %/%nrow(adjmatrix) + 1),ncol = 2)) - 1)
weight <- as.vector(adjmatrix[adjmatrix!=0])
######################
Fix # 1 is preferred, and I'd submit a patch, but I don't have an appropriate compilation environment now. I am using # 2 instead, for now.
Richard Bowman
Doctoral Fellow
Pardee RAND Graduate School
Imported from Launchpad using lp2gh.
The text was updated successfully, but these errors were encountered: