Open mtfishman opened 3 years ago
Also works fine with Julia 1.6:
julia> versioninfo()
Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) E-2176M CPU @ 2.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = vim
(@v1.6) pkg> st LightGraphs
Status `~/.julia/environments/v1.6/Project.toml`
[093fc24a] LightGraphs v1.3.5
julia> using LightGraphs
julia> g = Graph(Edge.([1 => 2, 2 => 3]))
{3, 2} undirected simple Int64 graph
julia> adjacency_matrix(g)
3×3 SparseArrays.SparseMatrixCSC{Int64, Int64} with 4 stored entries:
⋅ 1 ⋅
1 ⋅ 1
⋅ 1 ⋅
julia> add_edge!(g, 1 => 1)
true
julia> adjacency_matrix(g)
3×3 SparseArrays.SparseMatrixCSC{Int64, Int64} with 5 stored entries:
2 1 ⋅
1 ⋅ 1
⋅ 1 ⋅
so maybe an issue with SparseArrays
?
It looks like the error in Julia 1.7 is caused by stricter checks in the SparseMatrixCSC
constructor introduced in this PR: https://github.com/JuliaLang/julia/pull/40523
However, my guess is that it is more an issue on the LightGraphs
side on how it is using the constructor here: https://github.com/JuliaGraphs/LightGraphs.jl/blob/b210395e8cbd109dc04c286f8af0c267cad47a85/src/linalg/spectral.jl#L53-L72 in the case of self-loops when the graph is undirected.
Adding a line like:
if !(T <: Bool) && !is_directed(g)
nz -= 1
end
after line 57 seems to help. I think the issue is that the original definition of nz
is double counting the self-loops as nonzero values in the sparse matrix, which is being caught in the updated SparseMatrixCSC
constructor.
Description of bug
adjacency_matrix
fails forSimpleGraph
with self-loops in Julia 1.7.How to reproduce
It seems to work fine for directed graphs: