Skip to content

Weights, tensors, fits, NUFFT routes and a terse namespace - #39

Merged
jbphyswx merged 3 commits into
mainfrom
speed_of_light
Sep 17, 2026
Merged

jbphyswx merged 3 commits into
mainfrom
speed_of_light

Conversation

@jbphyswx

@jbphyswx jbphyswx commented Sep 17, 2026 •

Copy link
Copy Markdown
Owner

Adds pair weights, moment tensors from the transform, regularised fits and a soft-binned non-uniform
FFT route for scattered points; renames Channels to MultiFields; cuts the top-level exports from
141 names to 24.

What this adds

  • Pair weights on every lag route and point entry, with cell_measure(grid) for an area average.
  • Moment tensors off the transform on every separable schedule, a joint tensor over angle, and
    any order on point lists.
  • An exact sorted route for one-dimensional point lists, built on prefix sums of the monomials,
    so the cost stops scaling with the pair count.
  • Scattered points through a non-uniform FFT (ScatteredModesSchedule), with NonuniformFFTs and
    FINUFFT as providers on CPU and CUDA. The route is soft-binned and not exact at any finite mode
    count; the result carries ModeBinEdges and it is selected only by passing the tag.
  • Regularised fits inverting binned structure functions to spectra and fluxes:
    SpectrumForwardModel, HelmholtzForwardModel, FluxForwardModel with RegularizedLeastSquares,
    NonNegativeLeastSquares or a SegmentedPowerLaw.
  • Exact spectra and fluxes from lag space, the Helmholtz E/B split, and the third-order flux
    companions with their boundary terms.

Breaking changes

  • The package exports 24 names instead of 141. Everything else is reached through the submodule that
    owns it: Calculations for the entries, StructureFunctionTypes for the operators,
    HelperFunctions for the geometry, MultiFields for Fields.
  • Channels is MultiFields; ChannelIncrement is FieldIncrement; n_vector_channels,
    n_scalar_channels and channel_dimension are n_vector_fields, n_scalar_fields and
    field_dimension. "Channel" was signal-processing vocabulary for what the domain calls a field.
  • The transverse convention is a field of the projected operator,
    ProjectedStructureFunctionType{NL,NT}(basis). Each convention's first basis vector is odd under
    r -> -r, which unordered pairs require; CoordinateGaugeTransverseBasis and the user-basis
    closure wrappers are removed.

Fixes

  • The GPU batch kernel negated T3 and L2T1; no GPU test covered an odd transverse operator.
  • The slice-batch drivers refused three-dimensional batches while their own launchers specialize for
    D ∈ {2,3}.
  • generate_assets.jl could not run in its documented environment, so six figures were four months
    stale; the GPU asset collection read a field off a type that does not carry it.
  • The thread-scaling harness never pinned its worker threads and timed a single run. Either alone
    made the numbers irreproducible: an unpinned 16-thread run landed on 8 cores as often as 16, and a
    single sample carried noise the size of the speedup.

Performance

case before after
720x360 lat-lon L2, A100 vs 8-thread CPU — 0.045 s vs 1.28 s
stretched 256x128, A100 vs 8-thread CPU 0.035 s vs 0.012 s 0.0027 s vs 0.0098 s
1-D point list, 10^6 points, 8 threads pair loop, ~1 h 0.39 s
threaded point kernel, 32 pinned cores — 25.6x, 80 % efficiency

Verification

  • Full suite: 12 724 / 12 724, Aqua and JET included.
  • CUDA tier on an A100: 34 / 34, gridded parity OK on 23 rows with counts exact on every unweighted
    row.
  • Documentation builds with checkdocs = :exports and warnonly = false, no warnings.

Issues

Closes #38 — the transform engine: every polynomial operator at every lag as cross-correlations of
masked monomials, on uniform, stretched and lat-lon grids, on the CPU and on a device, with the
direct lag sweep kept as an independent route to check it against.

Closes #36 — the Pearson advective structure functions and their flux companions, with the
finite-range boundary terms. Two boundary terms are dimensionally inconsistent as printed in the
paper's appendix B; the consistent forms are the ones implemented, and the closed-form gates fail
without them.

Closes #25 — the KHM inversions (KHM.epsilon_from_four_fifths, epsilon_from_four_thirds,
epsilon_theta_from_yaglom) and full moment-tensor output of any rank, on point lists and off the
transform on every separable schedule, plus the joint tensor over angle.

Closes #24 — NaN and Bool masks on grids at every order, exact: the mask's own autocorrelation
gives the pair counts and the masked monomials give the sums. Point lists carry no mask by design;
a non-finite sample makes the bins it pairs into NaN, and the caller filters with indexing.

Closes #18 — RegularizedLeastSquares and NonNegativeLeastSquares on FluxForwardModel for the
cross-scale transfer from third-order functions, with posterior covariances and tradeoff_curve for
choosing the prior. The Hankel machinery the issue asks after is in: the J₁, J₂ and J₃ flux
routes and isotropic_spectrum/helmholtz_spectra all go through it.

Addresses #23 — the shared- and varying-position batch drivers do the point loop once and vectorise
along the trailing axis, on CPU (batch-leading (B, D, N) buffers, Val(D)-specialised) and GPU
(fused N-body launches, now for D ∈ {2,3}), and (D, N, aux...) covers <x,y,z,t> swept over a
subset by flattening the swept axes into N. Not included: a gridded transform fused over a
time axis. The gridded entries take one snapshot (n_cells(schedule) columns), so many times means
many calls. Leaving this open rather than claiming it.

Not touched by this PR: #37, which is a literature tracker.

Pair weights reach every lag route and point entry, with cell_measure(grid) for
an area average. Moment tensors come off the transform on every separable
schedule, with a joint tensor over angle and any order on point lists.
One-dimensional point lists take an exact sorted route built on prefix sums of
the monomials. Scattered points reach the transform engine through a soft-binned
non-uniform FFT, with NonuniformFFTs and FINUFFT as providers on CPU and CUDA,
and ModeBinEdges marking a result that is not hard-binned. Regularised fits
invert binned structure functions to spectra and fluxes.

The transverse convention is now a field of the projected operator, so every
route takes its sign from one place, and each convention's first basis vector is
odd under r -> -r, which unordered pairs require.

Namespace: the package exports its own 24 names; everything else is reached
through the submodule that owns it. "Channel" was signal-processing vocabulary
for what the domain calls a field, so Channels is MultiFields throughout.

Device: the transform's forward stage builds each monomial for every slab in one
broadcast and transforms the slabs in one batch; the binning kernel launches each
slab pair over its own lag box, which a schedule reports through uniform_lag_box.
The slice-batch drivers now accept every velocity width their launchers
specialize for, rather than refusing three-dimensional batches.

Benchmarks: the thread-scaling harness pins its worker threads and reports the
minimum of several runs. Without either, a 16-thread run landed on 8 cores as
often as 16 and a single sample carried noise the size of the speedup, which read
as a scaling collapse that was not there.

Documentation is rebuilt against the code, with two wrong formulas in the theory
page fixed and twenty-six figures regenerated.
@jbphyswx
jbphyswx merged commit 850ca9e into main Sep 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant