Skip to content

Commit 905ab8b

Browse files
committed
Consistently skip self edges when constructing Metis.Graph.
1 parent 560a056 commit 905ab8b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ext/GraphsCommon.jl

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function graph(G)
1515
for j in 1:N
1616
ne = 0
1717
for i in outneighbors(G, j)
18+
i == j && continue # skip self edges
1819
ne += 1
1920
adjncy_i += 1
2021
adjncy[adjncy_i] = i

src/Metis.jl

+6-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ function graph(G::SparseMatrixCSC; weights::Bool=false, check_hermitian::Bool=tr
5656
n_rows = 0
5757
for k in G.colptr[j] : (G.colptr[j+1] - 1)
5858
i = G.rowval[k]
59-
if i != j # don't include diagonal elements
60-
n_rows += 1
61-
adjncy_i += 1
62-
adjncy[adjncy_i] = i
63-
if weights
64-
adjwgt[adjncy_i] = G.nzval[k]
65-
end
59+
i == j && continue # skip self edges
60+
n_rows += 1
61+
adjncy_i += 1
62+
adjncy[adjncy_i] = i
63+
if weights
64+
adjwgt[adjncy_i] = G.nzval[k]
6665
end
6766
end
6867
xadj[j+1] = xadj[j] + n_rows

0 commit comments

Comments
 (0)