Skip to content

Support dims in 2D and 3D transform plans - #277

Merged
dlfivefifty merged 2 commits into
masterfrom
disk-dims
Nov 24, 2026
Merged

dlfivefifty merged 2 commits into
masterfrom
disk-dims

Conversation

@dlfivefifty

@dlfivefifty dlfivefifty commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Adds an optional dims argument, similar to FFTW.jl, to every plan for a transform acting on matrices or 3-arrays, so they can be applied to slices of higher-dimensional arrays. dims is a tuple listing the dimensions of each slice, applied in order:

A = randn(n, K, 4n-3)
P = plan_disk2cxf(A, α, β, ((1,3),))       # P*A applies the transform to A[:,k,:] for each k
pa = plan_disk_analysis(B, ((1,3), (2,4))) # B[:,k,:,j] for each k, j, then B[k,:,j,:]
pt = plan_tet2cheb(C, ((1,2,4),))          # C[:,:,k,:] for each k

Supported plans:

Kind Plans
Coefficient transforms plan_sph2fourier, plan_sphv2fourier, plan_disk2cxf, plan_ann2cxf, plan_rectdisk2cheb, plan_tri2cheb, plan_spinsph2fourier, plan_tet2cheb
FFTW synthesis/analysis sph, sphv, disk, annulus, rectdisk, tri, spinsph, tet

dims is positional, as in FFTW. It goes after the transform parameters, which keep their defaults, and is told apart from them by being a Tuple. For example, plan_disk2cxf(A, dims), plan_disk2cxf(A, α, β, dims), plan_annulus_analysis(A, ρ, dims; flags) and plan_spinsph2fourier(A, s, dims) all work. The existing convenience functions forward their arguments, so disk2cxf/cxf2disk, tri2cheb/cheb2tri and the rest accept dims with no further changes. The methods are generated from two tables in src/arrays.jl, which also produce the docstrings.

Implementation

This extends NDimsPlan rather than adding a new plan type:

  • Integer dims: the existing vector-transform path through ArrayPlan is unchanged.
  • Tuple-of-tuples dims: each entry lists the dimensions a slice spans. An entry (i, j) means rows run along dimension i and columns along dimension j, so ((3,1),) transforms the transposed slices. Each slice is copied into a buffer stored in the plan, transformed in place with lmul!/ldiv!, and copied back. This works for any plan that supports in-place application to an Array of the slice size, including vector plans, for example ((2,), (3,)).
  • Inverse, adjoint and transpose: \, inv, adjoint and transpose apply the factors in reverse order, which matters when dims overlap, e.g. ((1,3), (2,3)). inv(plan_disk_analysis(A, dims)) isa typeof(plan_disk_synthesis(A, dims)), matching Inv of synthesis #274.
  • Complex input: for real transforms, the real and imaginary parts are transformed separately, as with FTPlan. The spin-weighted plans use a complex buffer.

Throughput matches a hand-written loop over slices. For n = 50 and 40 slices, plan_disk_analysis takes 51.6 ms with the plan versus 51.7 ms with the loop, and in-place lmul! allocates 160 bytes.

Tests

For every plan listed above, the tests compare *, ' and transpose against applying the plan slice by slice, and do the same for \ where the underlying plan supports it. They also cover 4-arrays, transposed and overlapping dims, complex input, and errors for malformed dims, differing slice sizes and size mismatches.

Limitations

  • Equal slice sizes: as with the existing integer case, one plan is shared by every slice, so all slices must be the same size. Otherwise construction throws an error saying this is not yet implemented. Removing the limit would mean storing one plan per dims entry.
  • Not thread-safe: the buffer is shared, so a plan must not be applied from several tasks at once. This is noted in the docstring.
  • No inv or \ beyond the disk: among the FFTW plans, only the disk plans define inv (Inv of synthesis #274), and none define \. The other dims plans therefore inherit the same limitation.
  • Type change: NDimsPlan gains a fifth type parameter, Buf. It isn't exported, and no package in my local depot uses it.

Version bumped to 0.17.6.

🤖 Generated with Claude Code

Extend NDimsPlan so that dims may be a tuple of tuples, each listing the
dimensions spanned by the slices a transform acts on. Slices are copied
into a buffer stored in the plan, transformed in place, and copied back,
so transforms only implemented on matrices can act on 3- and 4-arrays.
For example dims = ((1,3), (2,4)) applies the transform to A[:,k,:,j]
and then to A[k,:,j,:].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.17%. Comparing base (abdbeff) to head (510a7a8).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #277      +/-   ##
==========================================
+ Coverage   77.48%   78.17%   +0.68%     
==========================================
  Files          17       17              
  Lines        3247     3313      +66     
==========================================
+ Hits         2516     2590      +74     
+ Misses        731      723       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Generate the dims methods from tables so that plan_sph2fourier,
plan_sphv2fourier, plan_ann2cxf, plan_rectdisk2cheb, plan_tri2cheb,
plan_tet2cheb, plan_spinsph2fourier and the corresponding FFTW synthesis
and analysis plans all accept dims, like the disk plans. tet transforms
act on 3-dimensional slices, so their dims entries are triples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dlfivefifty dlfivefifty changed the title Support dims in plan_disk2cxf, plan_disk_analysis, plan_disk_synthesis Support dims in 2D and 3D transform plans Nov 24, 2026
@dlfivefifty
dlfivefifty merged commit 803d86f into master Nov 24, 2026
20 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

Development

Successfully merging this pull request may close these issues.

1 participant