Compute the linear index of Cartesian indexing in Horner form #217
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 406 lines diff across 5 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.359
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #217"
general
weight: 0.35
giordano
Follow-up to #213: compute the linear index of Cartesian indexing in Horner form.
Before:
static_size_linear_indexcomputes the column-major index as a sum of strided terms,1 + (i - 1) + n1 (j - 1) + (n1 n2) (k - 1).After: Horner form,
i + n1 ((j - 1) + n2 (k - 1)). Static dimensions still give constant factors. This affects allFixedSizeArrays, not only those with static dimensions.History
The first
StaticSizeArrayversion in #210 used Horner form. When any dimension could be static, it switched to the strided sum, with this rationale: "Unlike the Horner form, the terms of indices that don't change in a loop can be hoisted out of it if the dimensions are dynamic." A review commit later dropped that comment. The measurements below show the concern is small.Trixi.jl
This is the volume integral of Trixi.jl's 2D
elixir_euler_ec.jl, with the flux-differencing kernel inlined. Setup: 4096 elements, polydeg 3, Julia 1.12, 1 thread pinned to one core,Vectorbackend.| | volume integral |
rhs_hyperbolic!||---|---|---|
| strided sum (#213) | 2578–2588 µs | 3076–3108 µs |
| Horner (this PR) | 2476–2489 µs | 2986–2990 µs |
That is about −3.9% and −3.3%. Each row covers 3 processes run with
JULIA_LLVM_ARGS="-align-all-nofallthru-blocks=6". Without forced alignment, the mean gain over 6 processes is 1.5% (2566 → 2527 µs), because the timing of this kernel swings by up to about 6% from one process to the next, depending on where the code is placed. In the kernel IR, the integer shifts go from 21 to 15.Microbenchmarks: static and dynamic dimensions
I compared both formulas in one process on the same
Memory, computingdst = 2 srcand similar operations on a 32×32×32 array (8×64×64 for the pairs kernel). I tested all 8 static/dynamic patterns of the 3 dimensions (d= dynamic,s= static). The table shows Horner time / strided time, minimum of 200 calls:| loop | ddd | sdd | dsd | dds | ssd | sds | dss | sss |
|---|---|---|---|---|---|---|---|---|
|
iinnermost (column-major) | 1.003 | 0.997 | 1.003 | 1.000 | 1.002 | 0.992 | 0.997 | 1.006 ||
kinnermost (row-major) | 0.999 | 0.997 | 1.027 | 1.003 | 1.017 | 0.999 | 1.017 | 0.992 ||
jinnermost | 1.000 | 1.001 | 1.002 | 1.003 | 0.986 | 0.999 | 1.003 | 1.005 || stencil along
j,k| 1.000 | 1.009 | 1.010 | 0.996 | 0.986 | 1.006 | 0.996 | 0.988 || node pairs
i,ii| 0.982 | 1.000 | 1.000 | 0.984 | 1.000 | 1.000 | 1.013 | 1.017 |ddd, i.e. every plainFixedSizeArray) show no difference.Tests: the full suite, including the FileCheck tests for indexing, passes on Julia 1.10 and 1.12.
🤖 Generated with Claude Code
https://claude.ai/code/session_01D5z6TVTAFfLGSFafUoLzuo