Repository navigation
Conversation
The counts are a power of the adjacency matrix, each edge counted once whatever its value. The power is built through the leading bits of the walk length, from one power to the next by a squaring or by single-edge steps, whichever needs fewer multiplications: steps once the counts fill in, squarings where they stay sparse, as on a cycle or a path. The power is taken in floats first, which are exact while every count on the way stays below 2**53. Past that it is taken again in uint64, which wraps modulo 2**64 and so is exact below 2**64, where the floats bound every count; OverflowError is raised where one could reach 2**64. From 2**63 NetworkX's int64 counts wrap to negative ones, and these stay exact. The counts come back as a dict of dicts of ints in node order, as in NetworkX, and as floats on a graph without edges, whose adjacency matrix in NetworkX is float64. A walk_length that is not an int is left to NetworkX.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 20-wiener-efficiency #170 +/- ##
========================================================
+ Coverage 92.88% 93.09% +0.20%
========================================================
Files 182 185 +3
Lines 11227 11579 +352
Branches 1274 1322 +48
========================================================
+ Hits 10428 10779 +351
- Misses 546 547 +1
Partials 253 253 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
number_of_walks. NetworkX (3.6.1, 3.7 and dev alike) takes its int64 adjacency matrix to the powerwalk_lengthwith SciPy's sparsematrix_power, then reads every pair out of the sparse result, one at a time, into a dict of dicts. Here GraphBLAS takes the power, and the dict is built from the rows of a dense array.weight=None, and an undirected self-loop once, as in NetworkX's adjacency matrix. The power is built through the leading bits ofwalk_length: from one power to the next by a squaring (and a step) or by single-edge steps, whichever needs fewer multiplications, as counted from the entries in each row and column. Steps win once the counts fill in, as on a random graph; squarings where they stay sparse, as on a cycle or a path (a walk length of 10000 on a directed cycle of 1000 nodes: 2.4 ms against 250 ms by steps, Indicative). Both ways are tested against exact counts.walk_lengthraises its ValueError, and the null graph its NetworkXError "Graph has no nodes or edges". Ints of every kind are served, bools and NumPy ints too. Awalk_lengththat is not an int (2.0, a Fraction, a 0-d array, a string) is left to NetworkX, whose comparison with 0 or SciPy's matrix power answers or raises. Multigraphs are declined, as everywhere in this backend (NetworkX counts parallel edges as walks of their own).G.edges(data=None, default=1), which reads an attribute named None as the edge's value: with 5 there, a path of 3 nodes has 25 walks of length 2 from an end back to itself, where there is one. This counts the edge once. So does this backend'sadjacency_matrix, which NetworkX'snumber_of_walkscalls, so with this backend first NetworkX's own answer counts it once too, and declining here would not bring NetworkX's back. The matrix names withweight=Noneare a follow-up.backend="graphblas"and with this backend first in NetworkX's priority and fallback off; both ways of taking the power are checked too. Also the edges of the bound: n(k - 1) walks on complete graphs with self-loops (1287, 2557, 2558 and 264 itself), and NetworkX's wrapped counts on the complete graph of 10 nodes; counts past 253 on the way and few at the end (layers of 64 nodes, 254 walks across 11 layers and none longer, beside a cycle); walk lengths of 270 and 10400; the bound itself; every error and decline above; and the kernel on a weighted backend graph. 26 mutants of the kernel and the wrapper each fail them, in NetworkX dev, 3.7 and 3.6.1.test_walks), through the backend in dev, 3.7 and 3.6.1: the same tests pass before and after (19, 19 and 6), with 6 conversions to the backend after against 5 before, when NetworkX'snumber_of_walkshanded itsadjacency_matrixto this backend. The repo's tests pass in all three.Stacked on #121.