Skip to content

Commit 088816c

Browse files
committed
add count for self-loop
1 parent 26163d4 commit 088816c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/simpleweightedgraph.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ mutable struct SimpleWeightedGraph{T<:Integer, U<:Real} <: AbstractSimpleWeighte
1818

1919
end
2020

21-
ne(g::SimpleWeightedGraph) = (nnz(g.weights) + count(diag(g.weights) .!= 0)) ÷ 2
21+
ne(g::SimpleWeightedGraph) = (nnz(g.weights) + nselfloop(g)) ÷ 2
22+
23+
function nselfloop(g::SimpleWeightedGraph)
24+
n = 0
25+
for i in axes(g.weights, 1)
26+
n += g.weights[i, i] != 0
27+
end
28+
return n
29+
end
2230

2331
SimpleWeightedGraph{T}(adjmx::SparseMatrixCSC{U, T}) where {T <: Integer, U <: Real} =
2432
SimpleWeightedGraph{T, U}(adjmx)

0 commit comments

Comments
 (0)