| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
from_networkx always routed nx -> scipy CSR -> Matrix, so every conversion paid for scipy.sparse (importing it alone costs over 100ms) plus an extra coo -> csr materialization. Simple graphs with numeric weights now build COO arrays straight from the nx adjacency and call Matrix.from_coo. The node selection preamble mirrors nx.to_scipy_sparse_array so ordering, subsetting, and error behavior match exactly; undirected graphs are symmetrized with the same diagonal correction nx uses (self-loop entries appear as wt + wt - wt under dup_op=plus, which is exact in IEEE arithmetic). Kept on the scipy fallback automatically: multigraphs (scipy's duplicate-coordinate summation matches exactly) and weights that do not form a 1-D numeric array. That second condition covers non-numeric attributes, including all-string weights, which infer a <U dtype rather than object; the fallback raises the identical ValueError. It also covers array-valued weights: sequence attributes of uniform length infer a 2-D numeric array, which passes a dtype-kind test but which from_coo would read as a UDT, so they keep raising ValueError as before rather than quietly widening what from_networkx accepts. graphblas without scipy installed can now convert simple graphs (previously ImportError); multigraphs still need scipy.
A networkx multigraph fell back to scipy in from_networkx because the direct path could not sum the weights of parallel edges. The directed branch now passes dup_op=plus when the graph is a multigraph, so parallel edges accumulate exactly as scipy's coo -> csr summation does. Simple graphs keep dup_op=None and are unchanged, and the undirected branch already summed because it uses plus for the self-loop diagonal correction. Numeric multigraphs no longer need scipy at all; non-numeric weights still defer to it. Parity with the retained scipy path holds for MultiGraph and MultiDiGraph with parallel edges, parallel self-loops, reciprocal parallel edges, parallel edges whose weights cancel to zero (both sides keep the explicit zero), absent weight attributes (nx defaults to 1), weight=None, bool and int weights, and nodelist permutations and subsets. New tests pin the multigraph diagonal sum and assert the numeric path never reaches the scipy fallback.
| Back | FazBrowse Home | New Git URL |
from_networkx routed every conversion through scipy CSR, paying the
scipy.sparse import (over 100ms) plus an extra coo to csr materialization.
It now builds COO arrays straight from the networkx adjacency and calls
Matrix.from_coo.
preamble mirrors nx.to_scipy_sparse_array, so ordering, subsetting, and
error behavior match exactly; undirected graphs symmetrize with the same
diagonal correction nx uses. Non-numeric and array-valued weights keep
the scipy fallback and its identical errors. graphblas without scipy
installed can now convert simple graphs (previously ImportError).
parallel edges accumulate exactly as scipy's coo to csr summation does.
Numeric multigraphs no longer need scipy at all; non-numeric weights
still defer to it.
Parity with the retained scipy path is pinned by tests over parallel edges,
parallel self-loops, reciprocal parallel edges, weights that cancel to zero,
absent weight attributes, weight=None, bool and int weights, and nodelist
permutations and subsets.
Stack created with GitHub Stacks CLI • Give Feedback 💬