Commit a5afdbc
fix(barycenter): native directed path via shortest_path_length [br-r37-c1-ecqmz]
Skill: /porting-to-rust (was 30+ min ago at the boundary; same
pattern as br-r37-c1-89n9d / br-r37-c1-wojl3 — drop a directed-graph
delegate to a buggy Rust path, reuse a correct fnx primitive).
Found via differential probe extending the directed-collapse-defect
audit: fnx.barycenter on a strongly-connected DiGraph cycle5+chord
returns [0, 2], nx returns [0]. Manual computation:
bc[0] = 0+1+1+2+3 = 7 ← minimum, the only barycenter
bc[1] = 4+0+1+2+3 = 10
bc[2] = 3+4+0+1+2 = 10
bc[3] = 2+3+4+0+1 = 10
bc[4] = 1+2+2+3+0 = 8
The Rust _raw_barycenter has the same gr.undirected() collapse as
_raw_diameter / _raw_radius — computes barycentricity on the
undirected projection where node 2 sits symmetrically with node 0.
Fix: in fnx.barycenter, after the strongly-connected guard, the
directed branch now computes barycentricity natively via
``fnx.shortest_path_length(G)`` (already directed-aware) and finds
the argmin. Same pattern as the existing ``attr=`` Python branch in
the same wrapper. Rust _raw_barycenter stays for undirected.
Verified bit-exact against nx 3.6.1 on:
- directed cycle5: [0,1,2,3,4] (vertex-transitive)
- directed cycle5+chord: [0] (was [0,2] — wrong)
- directed K4: [0,1,2,3]
- directed cycle3: [0,1,2]
- undirected K4 / P5: unchanged
Wider test surface: 112 barycenter-family tests pass. Golden
snapshot regenerated to capture the corrected directed barycenter
output for the dicycle5 / dicycle5+chord fixtures added in
br-r37-c1-zr9e0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ab8f8f2 commit a5afdbc
2 files changed
Lines changed: 22 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9612 | 9612 | | |
9613 | 9613 | | |
9614 | 9614 | | |
9615 | | - | |
9616 | | - | |
9617 | | - | |
9618 | | - | |
9619 | | - | |
| 9615 | + | |
| 9616 | + | |
| 9617 | + | |
| 9618 | + | |
| 9619 | + | |
| 9620 | + | |
| 9621 | + | |
| 9622 | + | |
| 9623 | + | |
| 9624 | + | |
| 9625 | + | |
| 9626 | + | |
| 9627 | + | |
| 9628 | + | |
| 9629 | + | |
| 9630 | + | |
| 9631 | + | |
| 9632 | + | |
| 9633 | + | |
| 9634 | + | |
| 9635 | + | |
9620 | 9636 | | |
9621 | 9637 | | |
9622 | 9638 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5549 | 5549 | | |
5550 | 5550 | | |
5551 | 5551 | | |
5552 | | - | |
5553 | | - | |
| 5552 | + | |
5554 | 5553 | | |
5555 | 5554 | | |
5556 | 5555 | | |
| |||
0 commit comments