-
Notifications
You must be signed in to change notification settings - Fork 22
Why G.weights is the transpose of adjacent_matrix(G) #65
Comments
Hi @ChasingZenith! Thanks for your post. It's perfectly acceptable to ask questions in the issues list. The reason we use the transpose is because the backing store for SimpleWeightedGraphs is a CSC sparse matrix, and that means that it's column-major. Consider a Because the sparse matrix is column-major, this means that the fastest access is when you iterate over columns of the matrix. Therefore, having the outneighbors of a given vertex Does this answer your question? |
Your answer is very illustrating. But please give me some time to digest what you have to say. What I am not familiar is CSC sparse matrices. I have read the sparse array page on Julia's documentation. It seems that we should at least obey some rule to make use of CSC format, otherwise the code will become slow. And in fact after reading that still I don't know how to use CSC sparse matrices. I think that the functions and algorithms provided in this packages can make full use of how On user side, should users always take care of the back storing scheme used in this package and optimize the code? What this package suppose users to do? for example:
A * v #slower ?
v'*(B) # faster ? B is computed in advanced Many question is asked in this comment. If there is any website that can give clues, please tell me. |
Sparse Matrices are laid out in memory as three vectors: a vector of row indices, a vector of column pointers, and a vector of nonzero values. What this means is that the column pointers point to offsets in the row indices where new columns start. What this further means is that most adjacent values in the vector of row indices are values that are in the same column. From a cache optimization perspective, iterating over columns is much faster as it's two adjacent lookups from the column pointer vector, along with a series of adjacent lookups from the row index vector.
You should never access a field of a graph directly. The portable way of accessing the weights is
I don't know. That's a question best asked of the SparseArrays folks. |
Thank you. |
I closed this issues several days ago. Today, I notice that even if you say we should obey the philosophy of never accessing a field of graph directly, but the example in README only mention |
If you'd like to make a PR with your proposed changes, I'd be thrilled to review it. |
I’ll have a try. |
I just wondering why do we design this.
when I add an edge
G.weights
isSorry if it is not proper to ask question by raising issues.
The text was updated successfully, but these errors were encountered: