Skip to content

Commit

Permalink
Consistently skip self edges when constructing Metis.Graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jan 19, 2023
1 parent 560a056 commit 905ab8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions ext/GraphsCommon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function graph(G)
for j in 1:N
ne = 0
for i in outneighbors(G, j)
i == j && continue # skip self edges
ne += 1
adjncy_i += 1
adjncy[adjncy_i] = i
Expand Down
13 changes: 6 additions & 7 deletions src/Metis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ function graph(G::SparseMatrixCSC; weights::Bool=false, check_hermitian::Bool=tr
n_rows = 0
for k in G.colptr[j] : (G.colptr[j+1] - 1)
i = G.rowval[k]
if i != j # don't include diagonal elements
n_rows += 1
adjncy_i += 1
adjncy[adjncy_i] = i
if weights
adjwgt[adjncy_i] = G.nzval[k]
end
i == j && continue # skip self edges
n_rows += 1
adjncy_i += 1
adjncy[adjncy_i] = i
if weights
adjwgt[adjncy_i] = G.nzval[k]
end
end
xadj[j+1] = xadj[j] + n_rows
Expand Down

0 comments on commit 905ab8b

Please sign in to comment.