Fix argsort's sorted-input check for a runtime descending flag #246
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 530 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.375
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #246"
general
weight: 0.35
r-devulap
Fix argsort's sorted-input check for a runtime
descendingflagThe current code passes a runtime-selected comparator pointer to
std::is_sorted, which can mean an indirect call for each comparison. The patch selects between two complete scans. Each scan has a fixed comparator that the compiler can inline.Benchmarks
I built the original and patched headers on my Ryzen AI 7 350 with GCC 16.2.1,
-std=c++17 -O3 -march=haswell. An initial single run timed 100 calls on one million already-sorted values with runtimedescending:| Version | int32 ascending | double ascending | int32 descending | double descending |
| --- | ---: | ---: | ---: | ---: |
| Original | 3.01 ms | 2.87 ms | 3.04 ms | 2.96 ms |
| This patch | 0.52 ms | 0.59 ms | 0.52 ms | 0.53 ms |
I also compared literal
falsewith runtimefalse, using reversedint32_tas a control. This benchmark checks the result, averages 20 calls per run, and alternates build order over three runs. The ranges are:| Input | Original, constant | Original, runtime | Patch, constant | Patch, runtime |
| --- | ---: | ---: | ---: | ---: |
| sorted int32 | 2.738–3.100 ms | 2.815–3.334 ms | 0.761–0.783 ms | 0.757–0.779 ms |
| sorted float64 | 2.770–2.908 ms | 2.916–2.981 ms | 0.765–0.812 ms | 0.764–0.792 ms |
| reversed int32 | 35.553–36.276 ms | 35.691–36.381 ms | 36.045–36.798 ms | 36.076–37.832 ms |
The sorted-input gain was consistent. I couldn't reproduce the constant-versus-runtime gap from #240 here. These are static API timings, not NumPy timings; the reversed control was close, but slightly slower with the patch.
Benchmark source: