Description
Description of bug
The eigenvector_centrality function has erratic behavior
How to reproduce
This will trow an error at every n attempts:
julia>using TextGraphs , Graphs
julia>poem = "Nunca a alheia vontade, inda que grata,\nCumpras por própria. Manda no que fazes,\nNem de ti mesmo servo.\nNinguém te dá quem és. Nada te mude.\nTeu íntimo destino involuntário\nCumpre alto. Sê teu filho."
julia>Graphs.eigenvector_centrality(naive_graph(poema))
It seems to do with LinAlg.jl::eigs.
ERROR: BoundsError: attempt to access 0-element Vector{Float64} at index [1]
Stacktrace:
[1] getindex
@ ./array.jl:861 [inlined]
[2] eigs(A::SparseArrays.SparseMatrixCSC{Int64, Int64}; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:which, :nev), Tuple{ArnoldiMethod.LM, Int64}}})
@ Graphs.LinAlg ~/.julia/packages/Graphs/6MoQZ/src/linalg/LinAlg.jl:60
[3] eigenvector_centrality(g::MetaGraphs.MetaDiGraph{Int64, Float64})
@ Graphs ~/.julia/packages/Graphs/6MoQZ/src/centrality/eigenvector.jl:27
[4] top-level scope
Expected behavior
The function should return eigenvector centralities, as it does often.
Nonetheless, once in every n executions (~3), it returns the error above.
Actual behavior
The output is erratic. Once in every n executions (~3), it returns the error above.
Code demonstrating bug
Above
Version information
Julia Version 1.7.2 Commit bf53498635 (2022-02-06 15:21 UTC) Platform Info: OS: Linux (x86_64-pc-linux-gnu) CPU: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-12.0.1 (ORCJIT, tigerlake) Environment: JULIA_EDITOR = code JULIA_NUM_THREADS =
(pkg> status Graphs Project TextGraphs v0.1.5 Status
~/.../TextGraphs.jl/Project.toml [86223c79] Graphs v1.7.2
Additional context
It seems that the bug is related with LinAlg.jl::eigs:
Why does it
function eigs(A; kwargs...)
schr =partialschur(A; kwargs...)
vals, vectors = partialeigen(schr[1])
reved = (kwargs[:which] == LR() || kwargs[:which] == LM())
k::Int = get(kwargs, :nev, length(vals))
k = min(k, length(vals))
perm = collect(1:k)
if vals[1] isa(Real)
perm = sortperm(vals, rev=reved)
perm = perm[1:k]
end
λ = vals[perm]
Q = vectors[:, perm]
return λ, Q
end