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
12
12
Return the colorvec vector for the matrix A using the chosen coloring
13
13
algorithm. If a known analytical solution exists, that is used instead.
14
14
The 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.
15
18
"""
16
19
function ArrayInterface. matrix_colors (A:: AbstractMatrix , alg:: SparseDiffToolsColoringAlgorithm = GreedyD1Color (); partition_by_rows:: Bool = false )
17
20
_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
32
32
sparse matrix, columns are represented with vertices
33
33
and 2 vertices are connected with an edge only if
34
34
the two columns are mutually orthogonal.
35
+
36
+ Note that the sparsity pattern is defined by structural nonzeroes, ie includes
37
+ explicitly stored zeros.
35
38
"""
36
39
function matrix2graph (sparse_matrix:: SparseMatrixCSC{<:Number, Int} , partition_by_rows:: Bool = true )
37
-
38
- dropzeros! (sparse_matrix)
40
+
39
41
(rows_index, cols_index, _) = findnz (sparse_matrix)
40
42
41
43
ncols = size (sparse_matrix, 2 )
Original file line number Diff line number Diff line change @@ -40,3 +40,22 @@ for i in 1:20
40
40
@test pr != 0
41
41
end
42
42
end
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