Repository navigation
Conversation
When every edge weighs the same, the Bellman-Ford kernels walk breadth-first and multiply each node's edge count by the weight. A zero weight with a cutoff no longer divides by zero, and a NaN weight or a NaN or inf cutoff no longer raises: NetworkX drops a length only where it is past the cutoff, which NaN never is. With a NaN or inf weight the source's own length is 0, not 0 times the weight. A cutoff keeps a length equal to it as the product rounds it, which floor division alone could miss.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 20-wiener-efficiency #129 +/- ##
========================================================
+ Coverage 92.88% 92.93% +0.04%
========================================================
Files 182 182
Lines 11227 11276 +49
Branches 1274 1275 +1
========================================================
+ Hits 10428 10479 +51
+ Misses 546 545 -1
+ Partials 253 252 -1 🚀 New features to boost your workflow:
|
This was referenced Dec 2, 2026
Open
eriknw
force-pushed
the
32-float-path-lengths
branch
from
December 2, 2026 20:40
faf0d71 to
28445c9
Compare
Member
Author
|
Rescoped: this PR no longer adds equal float weights edge by edge to reproduce NetworkX's last bits. Float lengths only need to agree within rounding, and multiplying the edge count by the weight is as accurate and cheaper (about 1.3x on all-pairs). What remains are the zero, NaN and inf weight fixes; the body is updated. |
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.
On a graph whose edges all weigh the same, the Bellman-Ford kernels walk breadth-first and multiply each node's edge count by the weight. This fixes that route for a zero, NaN or inf weight and for its cutoff.
length > cutoff, which is never true of NaN.all_pairs_dijkstra_path_length(30 dijkstra #133) will.Float lengths are products, so they can differ from NetworkX's in the last bits: NetworkX adds a path's weights one edge at a time. On
path_graph(14)with weight 0.1, node 10 is 1.0 here and 0.9999999999999999 in NetworkX. The tests compare float lengths withpytest.approx(rel=1e-12, or 1e-5 for float32 weights). The largest relative difference measured on the tests' graphs is 2.9e-15 for float64 weights and 2.0e-6 for float32. So a cutoff within rounding of a length, as in the example above, may keep or drop that node unlike NetworkX; the tests compare with NetworkX only at cutoffs away from such lengths. Integer lengths are exact, as before.Not changed: with NaN weights the Bellman-Ford names give every reachable node a NaN length, where NetworkX's Bellman-Ford gives only the nodes it reaches before the first NaN. #132 takes up NaN weights in those names.
Stacked on #121.