I want to get the unweighted adjacency matrix from a weighted graph. I thought that weighs gives the weighted adjacency matrix and adjacency_matrix gives the unweighted adjacency matrix. I found out this is not true:

Is there a function that will give me the unweighted adjacency matrix?

You can get the unweighted (Float64 ones) adjacency matrix just by coercing the weighted AM to 1s:

am = min.(adjacency_matrix(gw), 1.0)

For some reason this gives me the transposed adjacency matrix! What is happening here? Is this how this should work?

This is probably a bug. We’ve done some (in retrospect) silly things in an effort to improve performance of AM generation and this looks indicative of one of those things.

The bug is in the construction of the DiGraph from the SimpleWeightedDiGraph:

Awesome. I’ll try to remember to file a bug report for the constructor issue. For now, if you need to do this, just create it using the adjacency matrix:

Out of curiosity, is there any particular reason it was decided that adjacency_matrix and weights should return the same matrix? I mean what is the point of weights if it was decided that adjacency_matrix will return the weighted adjacency matrix?

In the case of SimpleWeightedGraphs, it was primarily because this is an O(1) operation that does not allocate, and it met the needs of the author/user at the time.

I mean what is the point of weights if it was decided that adjacency_matrix will return the weighted adjacency matrix?

I’m not sure that the fact that two functions return the same result in a particular implementation of a graph structure is a valid criticism. For SimpleGraphs 1:nv(g) and vertices(g) return the same thing, but we encourage their use in different scenarios. weights is not necessarily guaranteed to return a “real” matrix (look at DefaultDistance in SimpleGraphs for the example); just something that can be indexed into to retrieve a weight value.