Skip to content

Gridded data fast paths #32

Closed
Closed

Description

@jbphyswx

Everything in this package so far has been in service of unstructured data.
However, we should offer fast paths for gridded data.

At the very least, gridded cartesian (fully uniform, and separable by axis),
lat-lon gridded (a bit more math but should be doable)

Arbitrary gridded data perhaps as well (i.e. the spacing is not uniform along any axis but is shared across dimensions)

Both on CPU and GPU.

For pure gridded data, decide if to support natively, or via something like FlowGeometries.jl via extension
We should also look into support for like Healpix, etc that FG provides and that have clear adjacency and distance rules

Activity

  1. jbphyswx commented on Sep 6, 2026

    @jbphyswx
    OwnerAuthor

    Implemented, all four data layouts.

    The seam is a lag schedule in core; the FlowGeometries extension is host-side only (grid → schedule), so core carries no grid concept.

    layout path result
    uniform Cartesian UniformLagSchedule lag sweep geometry once per lag, one histogram write per lag
    uniform Cartesian correlation-theorem transform 153× at 512² over the full lag space
    lat-lon ZonalLagSchedule 147× vs the pair loop, counts exactly equal
    stretched / curvilinear / pixelized ScatteredPairs → culled pair loop exact; no lag structure exists to exploit

    The transform is exact, not approximate. The binomial expansion turns an integer-order increment moment into cross-correlations, and the correlation theorem evaluates all lags at once, so the whole second-order increment tensor costs 1 + D + D(D+1)/2 forward transforms and D(D+1)/2 inverse ones. Bounded directions are zero-padded past 2n−1; periodic ones are not, because there the circular correlation is already the sum wanted. Verified against the lag sweep to rtol = 1e-8 across bounded / periodic / mixed in 1-D, 2-D and 3-D.

    AutoSpectralBackend() costs both algorithms and picks the cheaper — it chose correctly in all 12 configurations measured, including the three where that is the sweep. Neither dominates, which is why the axis exists.

    Masked / missing data works (this is what #24 needed): validity flows in as a mask, sums stay exact and counts come from the mask autocorrelation.

    Two findings worth recording:

    • A stretched rectilinear grid does not benefit from per-axis difference tables. The plan called for them; measured, they are 1.1× to 3.5× slower and get worse with grid size, because a pair's index pair varies per pair so the "lookup" is a gather from an O(n²) table, while recomputing r² is five flops on arrays that never leave L1. Routed to the culled pair loop instead.
    • The gridded path bins a whole shell together and a pair loop does not. All pairs sharing a lag have one exact separation; the pair loop recomputes each difference and they differ by an ulp. When a bin edge falls on an achievable separation the two disagree about the entire shell. The gridded behaviour is the correct one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions