22# -*- coding: utf-8 -*-
33"""Implementation of Python-level sparse matrix operations."""
44
5- from __future__ import with_statement
6-
75__all__ = ()
86__docformat__ = "restructuredtext en"
97
@@ -65,7 +63,7 @@ def _maybe_halve_diagonal(m, condition):
6563# Logic to get graph from scipy sparse matrix. This would be simple if there
6664# weren't so many modes.
6765def _graph_from_sparse_matrix (klass , matrix , mode = "directed" , loops = "once" ):
68- """Construct graph from sparse matrix, unweighted.
66+ """Construct graph from sparse array or matrix, unweighted.
6967
7068 @param loops: specifies how the diagonal of the matrix should be handled:
7169
@@ -78,7 +76,7 @@ def _graph_from_sparse_matrix(klass, matrix, mode="directed", loops="once"):
7876 # matrix. The caller should make sure those conditions are met.
7977 from scipy import sparse
8078
81- if not isinstance (matrix , sparse .coo_matrix ):
79+ if not isinstance (matrix , ( sparse .coo_matrix , * ([ sparse . coo_array ] if hasattr ( sparse , "coo_array" ) else [])) ):
8280 matrix = matrix .tocoo ()
8381
8482 nvert = max (matrix .shape )
@@ -150,7 +148,7 @@ def _graph_from_sparse_matrix(klass, matrix, mode="directed", loops="once"):
150148def _graph_from_weighted_sparse_matrix (
151149 klass , matrix , mode = ADJ_DIRECTED , attr = "weight" , loops = "once"
152150):
153- """Construct graph from sparse matrix, weighted
151+ """Construct graph from sparse array or matrix, weighted
154152
155153 NOTE: Of course, you cannot emcompass a fully general weighted multigraph
156154 with a single adjacency matrix, so we don't try to do it here either.
@@ -165,7 +163,7 @@ def _graph_from_weighted_sparse_matrix(
165163 # matrix. The caller should make sure those conditions are met.
166164 from scipy import sparse
167165
168- if not isinstance (matrix , sparse .coo_matrix ):
166+ if not isinstance (matrix , ( sparse .coo_matrix , * ([ sparse . coo_array ] if hasattr ( sparse , "coo_array" ) else [])) ):
169167 matrix = matrix .tocoo ()
170168
171169 nvert = max (matrix .shape )
0 commit comments