Repository navigation
Conversation
A graph reads some properties from others it has already cached, and four of those readings went wrong. The count of edges, read from cached counts of the rows or columns, counted them again, giving the number of rows with an edge. It now adds them up. Whether the diagonal holds a negative weight was read as yes from a negative weight anywhere when the least weight off the diagonal was not cached, since its absence was taken for 0. A missing fact now tells nothing, and the diagonal is read. A graph with a loop of weight 1 and an edge of weight -2 was otherwise said to have a negative cycle. The reciprocal degrees are counts, but those built with the diagonal took its dtype: floats on a graph of floats, integers otherwise, by the order they were filled in. They are now integers on every path. The off-diagonal reduction from the cached triangles called a reduce that a Matrix lacks; it now reduces each to a scalar. And the clustering of one node looked for its degrees under names the cache does not use, so it read them from the matrix every time.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 79-self-edges #180 +/- ##
=================================================
+ Coverage 81.35% 83.25% +1.90%
=================================================
Files 121 122 +1
Lines 4553 4718 +165
Branches 750 774 +24
=================================================
+ Hits 3704 3928 +224
+ Misses 657 619 -38
+ Partials 192 171 -21 🚀 New features to boost your workflow:
|
Open
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.
A graph reads some properties from others it has already cached. Four of those readings were wrong, and one place looked in the cache under names it never uses. Each is checked here against what a fresh graph computes, and a new test does that for random fill orders.
count_element+orcount_element-read from a cachedcount_rowwiseorcount_columnwisecounted the counts, giving the number of rows (or columns) with an edge rather than the number of edges. It now adds them up. AGraphpath 0-1-2, which stores 4 entries, said 3. No function in the backend asks for these two today, so no NetworkX answer changes; they are wrong only throughget_property.has_negative_diagonaltook a missingmin_element-for 0, so a negative weight off the diagonal was read as a negative loop. A missing fact now tells nothing, and the diagonal is read. NetworkX-facing: aDiGraphwith edges0->1of weight -2,1->2of 3 and a loop of 1 on node 2 has no negative cycle, but aftermin_element+is cached,nx.negative_edge_cyclesaidTrue; it returns as soon as the flag is set. (The Bellman-Ford functions also read the flag, but look at the diagonal before they raise.) On main that takes a graph converted withDiGraph.from_networkx; with 20 wiener efficiency #121 or with the cache stamp branch, whoseis_isocachesmin_element+, a plain NetworkX graph gets there too:nx.single_source_bellman_ford_path_length(G, 0, backend="graphblas"), thennx.negative_edge_cycle(G, backend="graphblas")givesTrueon each of them alone andFalsemerged with this. These lines are the same as 34 nan, infinite and negative weights #132's.recip_degrees+andrecip_degrees-built with the diagonal took its dtype throughunary.one, so they were floats on a graph of floats, integers on a fresh one, by the order they were filled in. They now useunary.one[int]on every path and match a fresh graph'sINT64. No NetworkX answer changes:reciprocity,overall_reciprocityand directedclusteringdivide into floats, and give the same values before and after on a graph with a loop, in the four orders tried.single_clusteringlooked fordegrees-anddegrees+in the cache by those names, but the cache keeps them under the names they resolve to (count_rowwise-/+), so it never found them and read the node's row again. Speed only: answers are unchanged, and the rows read for 4 nodes afterdegree_centralitygo from 7 to 4.-scalar reduction (such asmax_element-) read from cachedL-andU-calledMatrix.reduce, which does not exist. It now reduces each triangle to a scalar, the same lines as 06 cluster #105 (and so 20 wiener efficiency #121). NetworkX-facing: weightednx.clusteringof aGraphwith a self-loop, over all nodes, stops raisingAttributeErrorand now gives main's per-node number, which still differs from NetworkX until 06 cluster #105. On a triangle with edges of weight 1, 2 and 3 and a loop of weight 9 on node 0, that is 0.6057 for each node against NetworkX's 0.2019: clustering's own formula on main divides by the heaviest edge off the diagonal, and 06 cluster #105 divides by the heaviest edge. Merged with 20 wiener efficiency #121, every node matches NetworkX. So this is best merged after 06 cluster #105, or an error on that call becomes main's wrong number.tests/test_cache_inference.pybuilds graphs of 1 to 6 nodes (floats, integers or booleans, with loops on some nodes or none, one weight or several) and asks 1 to 10 things of each in a seeded random order: one property (of 54 for aGraph, 58 for aDiGraph, with theplus,min,max,timesandcountreductions), three at once, a vector under a random mask, or an algorithm (degree centralities, and on aDiGraphreciprocity). Each answer, dtype included, must equal the answer of a graph of its own; three at once are compared one by one. Four seeds of 100 orders per class run in about a second. Over 3000 orders, 79 self edges #177 gives 174 wrong answers on aGraphand 221 on aDiGraph(main, 174 and 519); this gives none, for seeds 0 and 1, in NetworkX dev, 3.7 and 3.6.1.anyreductions, whose answer depends on the order values are read.iso_value, which raisesKeyErrorafteris_isois cached asFalse; 20 wiener efficiency #121 rewrites both. Graphs with no nodes, since python-graphblas 2026.11 counts the entries of a 0 by 0 matrix as 1.offdiagcached first or not; the negative diagonal on five weightings, from five sets of cached facts;negative_edge_cycleaftermin_element+; the reciprocal degrees' dtype after six fill orders, masked and not, for float, integer and boolean graphs; and the rows read by the clustering of one node afterdegrees-ordegrees+is cached. On 79 self edges #177, 68 of the 142 tests fail, in each of the three NetworkX versions.Matrix.reduce; a missingmin_element-taken for 0, in either case; the negative-weight checks loosened;unary.oneback in each of the six places; the clustering's old names, and a cacheddegrees+used without taking off the loop), 22 fail these tests in dev, 3.7 and 3.6.1. The two that pass count the counts where the+count reads cached-row or column counts. That case is not reached: each-row or column getter settleshas_self_edgesfirst and, when it isFalse, caches itself as the+as well, and no order of up to three of 12 related properties gets there.DiGraph'shas_self_edgesas 79 self edges #177 has it.Stacked on #177.