Skip to content

Commit 1abd62e

Browse files
authored
Replace sparse(A) with convert(SparseMatrixCSC, A) (#112)
1 parent cbce39f commit 1abd62e

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/graph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function bipartite_graph(A::SparseMatrixCSC; symmetric_pattern::Bool=false)
159159
checksquare(A) # proxy for checking full symmetry
160160
g1 = g2
161161
else
162-
g1 = Graph{true}(sparse(transpose(A))) # rows to columns
162+
g1 = Graph{true}(convert(SparseMatrixCSC, transpose(A))) # rows to columns
163163
end
164164
return BipartiteGraph(g1, g2)
165165
end

src/interface.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function coloring(
180180
decompression_eltype::Type=Float64,
181181
symmetric_pattern::Bool=false,
182182
)
183-
S = sparse(A)
183+
S = convert(SparseMatrixCSC, A)
184184
bg = bipartite_graph(
185185
S; symmetric_pattern=symmetric_pattern || A isa Union{Symmetric,Hermitian}
186186
)
@@ -195,7 +195,7 @@ function coloring(
195195
decompression_eltype::Type=Float64,
196196
symmetric_pattern::Bool=false,
197197
)
198-
S = sparse(A)
198+
S = convert(SparseMatrixCSC, A)
199199
bg = bipartite_graph(
200200
S; symmetric_pattern=symmetric_pattern || A isa Union{Symmetric,Hermitian}
201201
)
@@ -209,7 +209,7 @@ function coloring(
209209
algo::GreedyColoringAlgorithm{:direct};
210210
decompression_eltype::Type=Float64,
211211
)
212-
S = sparse(A)
212+
S = convert(SparseMatrixCSC, A)
213213
ag = adjacency_graph(S)
214214
color, star_set = star_coloring(ag, algo.order)
215215
return StarSetColoringResult(S, color, star_set)
@@ -221,7 +221,7 @@ function coloring(
221221
algo::GreedyColoringAlgorithm{:substitution};
222222
decompression_eltype::Type=Float64,
223223
)
224-
S = sparse(A)
224+
S = convert(SparseMatrixCSC, A)
225225
ag = adjacency_graph(S)
226226
color, tree_set = acyclic_coloring(ag, algo.order)
227227
return TreeSetColoringResult(S, color, tree_set, decompression_eltype)
@@ -230,21 +230,21 @@ end
230230
## ADTypes interface
231231

232232
function ADTypes.column_coloring(A::AbstractMatrix, algo::GreedyColoringAlgorithm)
233-
S = sparse(A)
233+
S = convert(SparseMatrixCSC, A)
234234
bg = bipartite_graph(S; symmetric_pattern=A isa Union{Symmetric,Hermitian})
235235
color = partial_distance2_coloring(bg, Val(2), algo.order)
236236
return color
237237
end
238238

239239
function ADTypes.row_coloring(A::AbstractMatrix, algo::GreedyColoringAlgorithm)
240-
S = sparse(A)
240+
S = convert(SparseMatrixCSC, A)
241241
bg = bipartite_graph(S; symmetric_pattern=A isa Union{Symmetric,Hermitian})
242242
color = partial_distance2_coloring(bg, Val(1), algo.order)
243243
return color
244244
end
245245

246246
function ADTypes.symmetric_coloring(A::AbstractMatrix, algo::GreedyColoringAlgorithm)
247-
S = sparse(A)
247+
S = convert(SparseMatrixCSC, A)
248248
ag = adjacency_graph(S)
249249
color, star_set = star_coloring(ag, algo.order)
250250
return color

src/result.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct RowColoringResult{M} <: AbstractColoringResult{:nonsymmetric,:row,:direct
143143
end
144144

145145
function RowColoringResult(S::SparseMatrixCSC, color::Vector{Int})
146-
Sᵀ = sparse(transpose(S))
146+
Sᵀ = convert(SparseMatrixCSC, transpose(S))
147147
group = group_by_color(color)
148148
C = length(group) # ncolors
149149
rv = rowvals(S)

0 commit comments

Comments
 (0)