Skip to content

Commit c331620

Browse files
committed
re-order checks
1 parent c53dec9 commit c331620

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
88
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
99
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
1010
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
11-
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1211
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
12+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1313
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1414
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1515
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -19,7 +19,7 @@ VertexSafeGraphs = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f"
1919

2020
[compat]
2121
Adapt = "1"
22-
ArrayInterface = "1.1, 2.0"
22+
ArrayInterface = "2"
2323
Compat = "2.2, 3"
2424
DataStructures = "0.17"
2525
FiniteDiff = "2"

src/coloring/matrix2graph.jl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,37 @@ and 2 vertices are connected with an edge only if
77
the two columns are mutually orthogonal.
88
"""
99
function matrix2graph(sparse_matrix::SparseMatrixCSC{<:Number, Int}, partition_by_rows::Bool)
10-
dropzeros(sparse_matrix)
11-
(rows_index, cols_index, val) = findnz(sparse_matrix)
10+
11+
dropzeros!(sparse_matrix)
12+
(rows_index, cols_index, _) = findnz(sparse_matrix)
1213

1314
ncols = size(sparse_matrix, 2)
1415
nrows = size(sparse_matrix, 1)
1516

1617
num_vtx = partition_by_rows ? nrows : ncols
1718

1819
inner = SimpleGraph(num_vtx)
19-
graph = VSafeGraph(inner)
2020

2121
if partition_by_rows
22-
for i = 1:length(rows_index)
22+
@inbounds for i in eachindex(rows_index)
2323
cur_row = rows_index[i]
24-
for j = 1:(i-1)
24+
for j in 1:(i-1)
2525
next_row = rows_index[j]
26-
if cur_row != next_row
27-
if cols_index[i] == cols_index[j]
28-
add_edge!(graph, cur_row, next_row)
29-
end
26+
if cols_index[i] == cols_index[j] && cur_row != next_row
27+
add_edge!(inner, cur_row, next_row)
3028
end
3129
end
3230
end
3331
else
34-
for i = 1:length(cols_index)
32+
@inbounds for i in eachindex(cols_index)
3533
cur_col = cols_index[i]
36-
for j = 1:(i-1)
34+
for j in 1:(i-1)
3735
next_col = cols_index[j]
38-
if cur_col != next_col
39-
if rows_index[i] == rows_index[j]
40-
add_edge!(graph, cur_col, next_col)
41-
end
36+
if rows_index[i] == rows_index[j] && cur_col != next_col
37+
add_edge!(inner, cur_col, next_col)
4238
end
4339
end
4440
end
4541
end
46-
return graph
42+
return VSafeGraph(inner)
4743
end

0 commit comments

Comments
 (0)