Skip to content

Fix simplex noise gradient lookups and permutation indices - #2124

Open
sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:wave1/simplex-noise-bounds
Open

sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:wave1/simplex-noise-bounds

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

What

f_simplex2d indexed grad2(g + 1, :) with g already in 1..10, reading
past the end of the table (gfortran: "Index '11' of dimension 1 of
array 'grad2' above upper bound of 10"). f_simplex3d added + 1 to every
permutation lookup although p_vec is declared 0:511, which shifted the
hash and could index p_vec(512). Both gradient tables were also listed
row by row but reshaped in column-major order, so grad3 held duplicate
and missing directions instead of the 12 cube-edge vectors.

Index the tables directly, drop the extra offsets so the lookups match
Gustavson's reference (perm[ii + perm[jj + perm[kk]]] % 12), reshape
with order=[2, 1], and replace real(i + j, 8) with real(i + j, wp).

Verified against a Python port of the reference algorithm at 20000
random points (max difference 4e-16 in 2D, 1e-16 in 3D) with
-fcheck=all clean, and with 2D and 3D pre_process runs using simplex
density and velocity perturbation. No test or example in the suite
uses simplex perturbation (3D_IGR_33jet is skipped), so no goldens
change.

Verification

Testing. Built with GPU offload (OpenMP, AMD) and ran the full test suite with this fix and seven other independent fixes applied together: 729 tests in 4 shards, 0 failures (two shards on MI300A, two on MI250X).

Prepared with Claude Code (AI-assisted); I reviewed the change and ran the tests.

f_simplex2d indexed grad2(g + 1, :) with g already in 1..10, reading
past the end of the table (gfortran: "Index '11' of dimension 1 of
array 'grad2' above upper bound of 10"). f_simplex3d added + 1 to every
permutation lookup although p_vec is declared 0:511, which shifted the
hash and could index p_vec(512). Both gradient tables were also listed
row by row but reshaped in column-major order, so grad3 held duplicate
and missing directions instead of the 12 cube-edge vectors.

Index the tables directly, drop the extra offsets so the lookups match
Gustavson's reference (perm[ii + perm[jj + perm[kk]]] % 12), reshape
with order=[2, 1], and replace real(i + j, 8) with real(i + j, wp).

Verified against a Python port of the reference algorithm at 20000
random points (max difference 4e-16 in 2D, 1e-16 in 3D) with
-fcheck=all clean, and with 2D and 3D pre_process runs using simplex
density and velocity perturbation. No test or example in the suite
uses simplex perturbation (3D_IGR_33jet is skipped), so no goldens
change.
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Claude Code Review

Head SHA: 5225f68

Files changed:

  • 1
  • src/pre_process/m_simplex_noise.fpp

Findings:
No issues found. Checked in step 4: src/pre_process/m_simplex_noise.fpp (grad3/grad2 order=[2,1] layouts, p_vec index bounds with the removed +1 offsets, dot2 1-based indexing, real(..., wp) kind).

@sbryngelson
sbryngelson marked this pull request as ready for review November 3, 2026 13:53
@sbryngelson
sbryngelson requested a review from a team as a code owner November 3, 2026 13:53
@sbryngelson
sbryngelson requested review from wilfonba and removed request for a team November 3, 2026 13:53

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant