Skip to content

re-order checks #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -19,7 +19,7 @@ VertexSafeGraphs = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f"

[compat]
Adapt = "1"
ArrayInterface = "1.1, 2.0"
ArrayInterface = "2"
Compat = "2.2, 3"
DataStructures = "0.17"
FiniteDiff = "2"
Expand Down
28 changes: 12 additions & 16 deletions src/coloring/matrix2graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,37 @@ and 2 vertices are connected with an edge only if
the two columns are mutually orthogonal.
"""
function matrix2graph(sparse_matrix::SparseMatrixCSC{<:Number, Int}, partition_by_rows::Bool)
dropzeros(sparse_matrix)
(rows_index, cols_index, val) = findnz(sparse_matrix)

dropzeros!(sparse_matrix)
(rows_index, cols_index, _) = findnz(sparse_matrix)

ncols = size(sparse_matrix, 2)
nrows = size(sparse_matrix, 1)

num_vtx = partition_by_rows ? nrows : ncols

inner = SimpleGraph(num_vtx)
graph = VSafeGraph(inner)

if partition_by_rows
for i = 1:length(rows_index)
@inbounds for i in eachindex(rows_index)
cur_row = rows_index[i]
for j = 1:(i-1)
for j in 1:(i-1)
next_row = rows_index[j]
if cur_row != next_row
if cols_index[i] == cols_index[j]
add_edge!(graph, cur_row, next_row)
end
if cols_index[i] == cols_index[j] && cur_row != next_row
add_edge!(inner, cur_row, next_row)
end
end
end
else
for i = 1:length(cols_index)
@inbounds for i in eachindex(cols_index)
cur_col = cols_index[i]
for j = 1:(i-1)
for j in 1:(i-1)
next_col = cols_index[j]
if cur_col != next_col
if rows_index[i] == rows_index[j]
add_edge!(graph, cur_col, next_col)
end
if rows_index[i] == rows_index[j] && cur_col != next_col
add_edge!(inner, cur_col, next_col)
end
end
end
end
return graph
return VSafeGraph(inner)
end