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

Don't restrict the input type of matrix2graph unnecessarily #258

Merged
merged 1 commit into from
Sep 5, 2023
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 Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseDiffTools"
uuid = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
authors = ["Pankaj Mishra <[email protected]>", "Chris Rackauckas <[email protected]>"]
version = "2.5.1"
version = "2.5.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
18 changes: 8 additions & 10 deletions src/coloring/matrix2graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ end
"""
_rows_by_cols(rows_index,cols_index)

Returns a vector of columns where each column contains
a vector of its row indices.
Returns a vector of columns where each column contains a vector of its row indices.
"""
function _rows_by_cols(rows_index, cols_index)
return _cols_by_rows(cols_index, rows_index)
Expand All @@ -26,15 +25,14 @@ end
"""
matrix2graph(sparse_matrix, [partition_by_rows::Bool=true])

A utility function to generate a graph from input
sparse matrix, columns are represented with vertices
and 2 vertices are connected with an edge only if
the two columns are mutually orthogonal.
A utility function to generate a graph from input sparse matrix, columns are represented
with vertices and 2 vertices are connected with an edge only if the two columns are mutually
orthogonal.

Note that the sparsity pattern is defined by structural nonzeroes, ie includes
explicitly stored zeros.
Note that the sparsity pattern is defined by structural nonzeroes, ie includes explicitly
stored zeros.
"""
function matrix2graph(sparse_matrix::SparseMatrixCSC{<:Number, Int},
function matrix2graph(sparse_matrix::AbstractSparseMatrix{<:Number},
partition_by_rows::Bool = true)
(rows_index, cols_index, _) = findnz(sparse_matrix)

Expand All @@ -43,7 +41,7 @@ function matrix2graph(sparse_matrix::SparseMatrixCSC{<:Number, Int},

num_vtx = partition_by_rows ? nrows : ncols

inner = SimpleGraph(num_vtx)
inner = SimpleGraph{promote_type(eltype(rows_index), eltype(cols_index))}(num_vtx)

if partition_by_rows
rows_by_cols = _rows_by_cols(rows_index, cols_index)
Expand Down