Skip to content

Commit ab0c315

Browse files
djfrancescoclaude
andcommitted
fix: use direct indexing instead of masked arrays in Spiess-Florian
Masked array argsort may not properly respect the kind='stable' parameter across all NumPy versions and coverage modes. This change replaces the masked array approach with explicit index filtering to ensure deterministic edge processing order in the second pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 55f7b56 commit ab0c315

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/edsger/spiess_florian.pyx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ cpdef void compute_SF_in(
107107
)
108108

109109
# sort the links with descreasing order of u_j + c_a
110-
# Use stable sort to ensure consistent ordering across Python/NumPy versions
111-
h_a_count = h_a_vec.sum()
112-
masked_a = np.ma.array(-u_j_c_a_vec, mask=~h_a_vec)
113-
edge_indices = np.argsort(masked_a, kind='stable').astype(np.uint32)
110+
# Use direct indexing instead of masked arrays for deterministic behavior
111+
# across all NumPy versions and Python environments (including coverage mode)
112+
hyperpath_indices = np.where(h_a_vec)[0].astype(np.uint32)
113+
h_a_count = len(hyperpath_indices)
114+
values_to_sort = -u_j_c_a_vec[hyperpath_indices]
115+
sorted_positions = np.argsort(values_to_sort, kind='stable')
116+
edge_indices = hyperpath_indices[sorted_positions]
114117

115118
_SF_in_second_pass(
116119
edge_indices,

0 commit comments

Comments
 (0)