Skip to content

32 zero and NaN weights - #129

Open
eriknw wants to merge 1 commit into
python-graphblas:20-wiener-efficiencyfrom
eriknw:32-float-path-lengths
Open

eriknw wants to merge 1 commit into
python-graphblas:20-wiener-efficiencyfrom
eriknw:32-float-path-lengths

Conversation

@eriknw

@eriknw eriknw commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

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.

  • A zero weight with a cutoff divided by zero. It now bounds nothing, unless the cutoff is negative, which keeps only the source, as NetworkX does.
  • A NaN weight, or a NaN or inf cutoff, raised ValueError. Now none of them drops anything, since NetworkX drops a length only where length > cutoff, which is never true of NaN.
  • With a NaN or inf weight, the source's own length was 0 times the weight, NaN. It is now 0, as in NetworkX.
  • A length equal to the cutoff, as the product rounds it, is kept, so a cutoff keeps exactly the lengths within it that the same call without one gives. With weight 0.3 and cutoff 14.7, node 49 (49 * 0.3 = 14.7) is kept; floor division alone, 14.7 // 0.3 = 48, dropped it. NetworkX's sum for that node is 14.700000000000014, so NetworkX drops it.
  • No served name passes a cutoff yet; 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 with pytest.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.

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

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.93%. Comparing base (5b54ace) to head (28445c9).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eriknw
eriknw force-pushed the 32-float-path-lengths branch from faf0d71 to 28445c9 Compare December 2, 2026 20:40
@eriknw eriknw changed the title 32 float path lengths 32 zero and NaN weights Dec 2, 2026
@eriknw

eriknw commented Dec 2, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant