Skip to content
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

Replace sparse(A) with convert(SparseMatrixCSC, A) #112

Merged
merged 1 commit into from
Sep 26, 2024
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
2 changes: 1 addition & 1 deletion src/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function bipartite_graph(A::SparseMatrixCSC; symmetric_pattern::Bool=false)
checksquare(A) # proxy for checking full symmetry
g1 = g2
else
g1 = Graph{true}(sparse(transpose(A))) # rows to columns
g1 = Graph{true}(convert(SparseMatrixCSC, transpose(A))) # rows to columns
end
return BipartiteGraph(g1, g2)
end
14 changes: 7 additions & 7 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function coloring(
decompression_eltype::Type=Float64,
symmetric_pattern::Bool=false,
)
S = sparse(A)
S = convert(SparseMatrixCSC, A)
bg = bipartite_graph(
S; symmetric_pattern=symmetric_pattern || A isa Union{Symmetric,Hermitian}
)
Expand All @@ -195,7 +195,7 @@ function coloring(
decompression_eltype::Type=Float64,
symmetric_pattern::Bool=false,
)
S = sparse(A)
S = convert(SparseMatrixCSC, A)
bg = bipartite_graph(
S; symmetric_pattern=symmetric_pattern || A isa Union{Symmetric,Hermitian}
)
Expand All @@ -209,7 +209,7 @@ function coloring(
algo::GreedyColoringAlgorithm{:direct};
decompression_eltype::Type=Float64,
)
S = sparse(A)
S = convert(SparseMatrixCSC, A)
ag = adjacency_graph(S)
color, star_set = star_coloring(ag, algo.order)
return StarSetColoringResult(S, color, star_set)
Expand All @@ -221,7 +221,7 @@ function coloring(
algo::GreedyColoringAlgorithm{:substitution};
decompression_eltype::Type=Float64,
)
S = sparse(A)
S = convert(SparseMatrixCSC, A)
ag = adjacency_graph(S)
color, tree_set = acyclic_coloring(ag, algo.order)
return TreeSetColoringResult(S, color, tree_set, decompression_eltype)
Expand All @@ -230,21 +230,21 @@ end
## ADTypes interface

function ADTypes.column_coloring(A::AbstractMatrix, algo::GreedyColoringAlgorithm)
S = sparse(A)
S = convert(SparseMatrixCSC, A)
bg = bipartite_graph(S; symmetric_pattern=A isa Union{Symmetric,Hermitian})
color = partial_distance2_coloring(bg, Val(2), algo.order)
return color
end

function ADTypes.row_coloring(A::AbstractMatrix, algo::GreedyColoringAlgorithm)
S = sparse(A)
S = convert(SparseMatrixCSC, A)
bg = bipartite_graph(S; symmetric_pattern=A isa Union{Symmetric,Hermitian})
color = partial_distance2_coloring(bg, Val(1), algo.order)
return color
end

function ADTypes.symmetric_coloring(A::AbstractMatrix, algo::GreedyColoringAlgorithm)
S = sparse(A)
S = convert(SparseMatrixCSC, A)
ag = adjacency_graph(S)
color, star_set = star_coloring(ag, algo.order)
return color
Expand Down
2 changes: 1 addition & 1 deletion src/result.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct RowColoringResult{M} <: AbstractColoringResult{:nonsymmetric,:row,:direct
end

function RowColoringResult(S::SparseMatrixCSC, color::Vector{Int})
Sᵀ = sparse(transpose(S))
Sᵀ = convert(SparseMatrixCSC, transpose(S))
group = group_by_color(color)
C = length(group) # ncolors
rv = rowvals(S)
Expand Down
Loading