This repository was archived by the owner on Aug 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ struct AcyclicColoring <: SparseDiffToolsColoringAlgorithm end
1212Return the colorvec vector for the matrix A using the chosen coloring
1313algorithm. If a known analytical solution exists, that is used instead.
1414The coloring defaults to a greedy distance-1 coloring.
15+
16+ Note that if A isa SparseMatrixCSC, the sparsity pattern is defined by structural nonzeroes,
17+ ie includes explicitly stored zeros.
1518"""
1619function ArrayInterface. matrix_colors (A:: AbstractMatrix , alg:: SparseDiffToolsColoringAlgorithm = GreedyD1Color (); partition_by_rows:: Bool = false )
1720 _A = A isa SparseMatrixCSC ? A : sparse (A) # Avoid the copy
Original file line number Diff line number Diff line change @@ -32,10 +32,12 @@ A utility function to generate a graph from input
3232sparse matrix, columns are represented with vertices
3333and 2 vertices are connected with an edge only if
3434the two columns are mutually orthogonal.
35+
36+ Note that the sparsity pattern is defined by structural nonzeroes, ie includes
37+ explicitly stored zeros.
3538"""
3639function matrix2graph (sparse_matrix:: SparseMatrixCSC{<:Number, Int} , partition_by_rows:: Bool = true )
37-
38- dropzeros! (sparse_matrix)
40+
3941 (rows_index, cols_index, _) = findnz (sparse_matrix)
4042
4143 ncols = size (sparse_matrix, 2 )
Original file line number Diff line number Diff line change @@ -40,3 +40,22 @@ for i in 1:20
4040 @test pr != 0
4141 end
4242end
43+
44+ @info " stored zeros"
45+ for i in 1 : 20
46+ matrix = matrices[i]
47+ g = matrix2graph (matrix)
48+ # recalculate graph with stored zeros
49+ matrix_sz = copy (matrix)
50+ fill! (matrix_sz, 0.0 )
51+ g_sz = matrix2graph (matrix_sz)
52+ # check that graphs are the same
53+ @test nv (g) == nv (g_sz)
54+ @test ne (g) == ne (g_sz)
55+ for e in edges (g)
56+ @test has_edge (g_sz, e)
57+ end
58+ for e in edges (g_sz)
59+ @test has_edge (g, e)
60+ end
61+ end
You can’t perform that action at this time.
0 commit comments