API Reference

Symbols are accessed via fully-qualified submodule paths (the package does not re-export names into its top-level namespace); using ScatteringTransforms: ScatteringTransforms as ST, then e.g. ST.ScatteringCore.ScatteringTransform(...).

ScatteringTransforms.ScatteringTransforms — Module
ScatteringTransforms.jl — Native Julia implementation of wavelet scattering transforms

Surfaces: 1D signals, 2D and 3D gridded fields, scattered planar points (NUFFT), and the sphere — both on a structured grid and at scattered points. Each has a monogenic variant; the gridded ones also have a localized (Mallat) field output and a multi-resolution second order. The spherical and scattered paths run dependency-free by default, with fast paths supplied by extensions.

Quick Start

Names live in submodules and are reached by their full path; alias the package for brevity.

using ScatteringTransforms: ScatteringTransforms as ST

# 1D scattering (N = signal length, J = number of octaves)
signal = randn(1024)
st = ST.ScatteringCore.ScatteringTransform(1024, 8; Q=1, max_order=2)
coeffs = st(signal)

# 2D planar scattering (N = image size, J = scales, L = orientations)
image = randn(256, 256)
st2d = ST.ScatteringCore.ScatteringTransform((256, 256), 4; L=8, max_order=2)
coeffs2d = st2d(image)

References

  • Mallat (2012): Group invariant scattering. Comm. Pure Appl. Math.
  • Bruna & Mallat (2013): Invariant Scattering Convolution Networks. IEEE PAMI.
  • Cheng & Ménard (2021): How to quantify fields or textures? A guide to the scattering transform.
source

Grid-support matrix

Planar (Cartesian) and spherical scattering, on uniform/structured and nonuniform/scattered sampling:

domainuniform / structurednonuniform / scattered
CartesianScatteringTransform{D} (FFT/direct sum; GPU via GPUBackend)scattered_planar_scattering (exact direct NUDFT; NonuniformFFTs or FINUFFT fast path)
Sphere (S²)structured_spherical_scattering (exact direct SHT; FastSphericalHarmonics fast path)spherical_scattering (exact direct SHT; NUFSHT fast path)

Every cell has an in-core, dependency-free default (direct summation), with an optional fast path selected by the transform keyword, which takes a SpectralBackends.jl tag. DirectSumSpectralBackend is the in-core default everywhere; the fast paths are FFTSpectralBackend (FFTW) on a grid, FlowTransformBindings.jl's NonuniformFFTsBackend() or FINUFFTBackend() for scattered points, NUFSHTSpectralBackend (NUFSHT) for the scattered sphere, and FSHTSpectralBackend (FastSphericalHarmonics) for the structured sphere. AutoSpectralBackend (the default) picks the fast path if its extension is loaded, else the direct sum — so nothing requires an external library. Naming a backend explicitly is honoured exactly: if its extension is absent it throws.

Monogenic variants support gridded Cartesian fields and both spherical samplings. spherical_monogenic_components accepts scattered and structured spherical transforms.

Transforms

All transform objects subtype ScatteringCore.AbstractScatteringTransform and are callable as st(field). Both Cartesian families carry spatial rank as ScatteringTransform{D,…} and MonogenicScatteringTransform{D,…}. D = 1, 2, 3 selects a signal, image or volume.

ScatteringTransforms.ScatteringCore.ScatteringTransform — Type
ScatteringTransform{D}
ScatteringTransform([T=Float64,] dims, J; kwargs...)

Regular Cartesian scattering transform with D spatial axes, a wavelet bank and reusable buffers. The rank of the dims tuple selects the 1D, 2D or 3D wavelet builder; an integer selects 1D.

source
ScatteringTransforms.Scattering1D.scattering_transform! — Function
scattering_transform!(coeffs, st, signal; execution = SerialBackend()) -> coeffs′

Fill coeffs.S1/coeffs.S2 and return the coefficients with S0 set by Coefficients.update_S0, which allocates a new container only when S0 is a scalar.

execution is where the cascade runs: SerialBackend in this task; ThreadedBackend (OhMyThreads extension) runs the first-order wavelet groups as parallel tasks after one serial input transform.

source
ScatteringTransforms.Scattering3D.scattering_transform3d! — Function
scattering_transform3d!(coeffs, st, volume; execution = SerialBackend()) -> coeffs

In-place 3D volumetric scattering transform; fills coeffs (a scales×orientations container) and returns it with S0 updated. execution is as for Scattering2D.scattering_transform2d!.

source
ScatteringTransforms.ScatteringCore.scattering — Function
scattering(st, x) -> coefficient container

The coefficients of st(x), computed without mutation so the forward map can be differentiated (as synthesize does) and takes any element type, such as ForwardDiff.Dual.

Every intermediate comes from the non-mutating Plans.forward_transform and Plans.inverse_transform and broadcasts, so each call allocates; st(x) is the in-place forward pass. Methods are defined for the 1D, 2D and 3D transforms.

source
ScatteringTransforms.scattered_planar_scattering — Function
scattered_planar_scattering([T=Float64,] x, y, ms, J; period, origin=(0, 0), L=8, max_order=2,
                            transform=SpectralBackends.AutoSpectralBackend(),
                            analysis=Plans.WeightedAdjoint(), weights=nothing, tol=nothing,
                            maxiter=100, rtol=Plans.default_solver_rtol(T, transform, tol), damp=0,
                            ntrans=1, nthreads=0, filters=StoredFilters(), oversampling=J)
scattered_planar_scattering([T,] grid, ms, J; kwargs...)

Build a 2D planar scattering transform for a scalar field sampled at scattered points (x, y). A nonuniform DFT analyses the samples onto a uniform Fourier mode grid of size ms = (m1, m2), and the cascade of the gridded ScatteringCore.ScatteringTransform{2}, with its oriented Morlet bank and oversampling, runs on that grid: each coefficient is the domain mean of a modulus of the field the analysis recovers. Apply it to a length-M vector of samples.

period is the length of the domain the points sample along each axis and origin its lower corner (a number for both axes, or a 2-tuple): mode k has wavelength period/k, so the wavelets' physical scales are those of the domain, and point sets drawn from one domain share them. Points 0:m-1 with period = m are the nodes of the length-m DFT. With FlowGeometries loaded, a 2-D Cartesian FlowGeometries.Grids grid stands in for the points: its active cells are the points, its periodic axes supply their periods, bounded axes their extents plus the coarsest wavelet width, the lowest cell centre supplies the origin, and cell measures supply default weights.

transform names the nonuniform transform: SpectralBackends.DirectSumSpectralBackend is the in-core, dependency-free exact NUDFT (always available, O(M·prod(ms))); FlowTransformBindings.NonuniformFFTsBackend() and FlowTransformBindings.FINUFFTBackend() select a nonuniform-FFT library (using NonuniformFFTs / using FINUFFT); and SpectralBackends.AutoSpectralBackend (the default) takes NonuniformFFTs when it is loaded, FINUFFT when only it is, and the direct sum otherwise. analysis=Plans.WeightedAdjoint() takes the adjoint weighted by weights, the quadrature of each Fourier coefficient's domain integral: exact on the nodes of the DFT, an estimate elsewhere. analysis=Plans.LeastSquares() fits the band-limited coefficients by least squares (slower, for irregular sampling). weights (length M, normalized to sum to 1) are uniform by default; S0 is the mean of the analysed field. tol is the NUFFT tolerance (ignored by the exact direct sum). ntrans = B builds a transform that runs B fields per call through one execution per cascade step (see scattering_batch). filters = FilterBanks.ComputedFilters() evaluates the wavelets on demand.

The solve is LSMR (FlowTransformBindings.lsmr!), which costs one type-2 and one type-1 per iteration and keeps both ‖b - Af‖ and ‖A†(b - Af)‖ monotone, so stopping at maxiter returns the best iterate reached. rtol targets ‖A†(b - Af)‖ ≤ rtol ‖A†b‖ and defaults to the accuracy of the transform under it: sqrt(eps(T)) for the exact direct sum and at least 10·tol for a fast library, whose type-1 and type-2 are adjoints only to its own tolerance (Plans.default_solver_rtol). damp is a Tikhonov λ minimising ‖Af - b‖² + λ²‖f‖², 0 by default; with prod(ms) > M the problem is underdetermined, construction warns, and LSMR returns the minimum-norm solution unless a λ is given.

The Krylov process terminates within prod(ms) steps, and maxiter caps it earlier. A truncated solve returns the best iterate reached but is reproducible only to the accuracy of the transform under it: a multi-threaded NUFFT accumulates its spreading in a run-dependent order, which an unconverged solve amplifies by about cond(A)². Raise maxiter until the solve converges for an answer independent of the thread count, or set nthreads = 1 for bitwise-identical repeats.

nthreads is the fast library's own thread count, honoured by every copy of the plan, including the per-task copies a threaded backend builds. 0 (the default) takes Threads.nthreads() on a serial backend and gives each per-task copy one thread. 1 keeps the library single-threaded everywhere, and its plan executes without allocating; a multi-threaded FFTW plan runs its parallel loop on Julia tasks.

source
ScatteringTransforms.spherical_scattering — Function
spherical_scattering(pts_theta, pts_phi, lmax, J; max_order=2,
                     transform=SpectralBackends.AutoSpectralBackend(), analysis=Plans.LeastSquares(),
                     rtol=SphericalCore.default_rtol(transform), maxiter=500, weights=nothing,
                     ntrans=1, nufft=SpectralBackends.AutoSpectralBackend(), grid_lmax=2lmax)

Build a spherical scattering transform for a scalar field at scattered points (θ, φ) on S², using smooth difference-of-Gaussians band-pass wavelets. transform names the spherical-harmonic transform: SpectralBackends.DirectSumSpectralBackend is the in-core, dependency-free exact least-squares transform (always available, O(M·(lmax+1)²)); SpectralBackends.NUFSHTSpectralBackend uses the NUFSHT fast path (needs using NUFSHT); SpectralBackends.AutoSpectralBackend (the default) picks NUFSHT if its extension is loaded, else the direct transform. Accurate analysis needs the sampling to resolve the band limit, i.e. roughly M ≳ (lmax+1)² well-distributed points.

The samples are analysed once, onto the harmonics of degree ≤ lmax. Every band, modulus, mean and second analysis after that runs on the Gauss–Legendre grid of band limit grid_lmax (SphericalCore.gauss_legendre_grid): each coefficient is the spherical mean of a modulus of the field the analysis recovers, and S0 is that field's mean. A modulus is not band limited, and the grid's analysis of it onto degree ≤ lmax is exact for its content up to degree 2grid_lmax + 1 − lmax.

analysis = Plans.LeastSquares() fits by LSMR, configured by rtol and maxiter, and returns its best iterate at a stopping limit. Plans.WeightedAdjoint() takes the adjoint weighted by weights: the expansion of a degree-lmax field where the weights integrate the product of two degree-lmax harmonics exactly, and an approximation elsewhere. weights (length M, normalized to sum to 1) are the quadrature of that adjoint and the weights of the fit, uniform by default. ntrans = B builds a plan that transforms B co-located fields per call. nufft names the NUFFT library NUFSHT runs on; the in-core plan runs none and accepts only an Auto nufft.

source
ScatteringTransforms.structured_spherical_scattering — Function
structured_spherical_scattering([T=Float64,] lmax, J; max_order=2,
                                transform=SpectralBackends.AutoSpectralBackend(),
                                band_headroom=nothing, rtol=1e-8, maxiter=500)

Build a spherical scattering transform for a scalar field sampled on the structured equiangular grid (Nθ = lmax+1 colatitudes, Nφ = 2lmax+1 longitudes), using the same smooth difference-of-Gaussians band-pass wavelets as spherical_scattering. Apply it to a (Nθ, Nφ) grid of samples; obtain the grid points with structured_sphere_points. transform names the spherical-harmonic transform: SpectralBackends.DirectSumSpectralBackend (in-core, dependency-free), or SpectralBackends.FSHTSpectralBackend (the fast exact SHT, needs using FastSphericalHarmonics); SpectralBackends.AutoSpectralBackend picks the fast path if its extension is loaded, else the direct SHT.

On a backend that can narrow its band limit (FastSphericalHarmonics), a finite band_headroom synthesises band j at band limit band_headroom·ℓ_j, discarding the tail SphericalCore.band_lmax describes; the default nothing runs the full-band-limit cascade bit for bit. rtol and maxiter configure the in-core plan's analysis solve.

source

Reconstruction & synthesis

ScatteringTransforms.Inverse.ReconstructionWorkspace — Type
ReconstructionWorkspace(st)

Scratch for the linear wavelet inverse and for phase retrieval: the complex wavelet coefficient fields (nw of them), the low-pass field, a spectrum accumulator, and the bank's Littlewood–Paley sum frame. Every filter's Fourier response is real, so the dual filters are ψ̂_λ/A and φ̂/A.

source
ScatteringTransforms.Inverse.wavelet_transform! — Function
wavelet_transform(st, x) -> (; wavelet, lowpass)
wavelet_transform!(ws, st, x) -> (; wavelet, lowpass)

The linear (pre-modulus) wavelet layer underlying the scattering transform: the complex wavelet coefficient fields wavelet[λ] = x ⋆ ψ_λ and the low-pass field lowpass = x ⋆ φ, which together determine x exactly (see iwavelet!). The ! form returns arrays owned by ws.

source
ScatteringTransforms.Inverse.iwavelet! — Function
iwavelet(st, wavelet, lowpass) -> x
iwavelet(st, wt) -> x
iwavelet!(ws, st, wavelet, lowpass) -> x

Inverse of wavelet_transform! for a real field by the canonical dual frame, x = Re F⁻¹[(φ̂·Ŷ + Σ_λ ψ̂_λ·Ŵ_λ) / A] with A the bank's Littlewood–Paley sum: the real part takes C(k) to (C(k) + conj C(−k))/2, which turns C = (φ̂² + Σ_λ ψ̂_λ²)·x̂ into A·x̂. Returns the reconstructed real field; iwavelet(st, wavelet_transform(st, x)) ≈ x to rounding.

source
ScatteringTransforms.Inverse.reconstruct_phase — Function
reconstruct_phase(st, moduli; iters=200, init=nothing, seed_lowpass=nothing) -> x

Phase retrieval from the first-order moduli moduli[λ] = |x ⋆ ψ_λ| (the real fields the scattering transform averages), via Gerchberg–Saxton alternating projections:

  1. take the linear wavelet transform of the current estimate;
  2. re-impose the target magnitudes on each band-pass channel (keeping the recovered phase);
  3. reconstruct with the exact frame inverse iwavelet!; repeat.

The low-pass channel carries no magnitude target, so it is taken from the current estimate each iteration (or from seed_lowpass if supplied). The reconstruction is determined only up to a global sign/phase. init (defaults to a random field matched in energy to the moduli) seeds the estimate; pass one for reproducibility. Returns the real reconstructed field, on the array type of the transform's filters. The loop reuses one workspace.

source
ScatteringTransforms.synthesize — Function
synthesize(st, target; backend, init=nothing, iters=500, lr=0.05, loss=scattering_loss) -> (; field, losses)

Reconstruct a field whose scattering coefficients match target by gradient descent (Bruna & Mallat microcanonical synthesis): starting from init (random by default), minimize loss(scattering(st, x̂), target) with Adam. target may be a precomputed coefficient container or a field (its coefficients are taken first). The gradient is obtained through DifferentiationInterface, so backend is any ADTypes backend. The modulus discards local phase, so the result is a sample with matching statistics and the original is not recovered. Requires using DifferentiationInterface and an AD backend package.

With Enzyme, pass AutoEnzyme(; mode = Enzyme.set_runtime_activity(Enzyme.Reverse)): the cascade's closures capture constant filters alongside the active input, which Enzyme's static activity analysis cannot separate, and a plain AutoEnzyme() raises EnzymeRuntimeActivityError.

source
ScatteringTransforms.scattering_loss — Function
scattering_loss(c, target) -> Real

Default synthesize objective: the normalized squared error between the coefficient container c and the target, summed over the first- and (when present) second-order coefficients, ‖S₁(c)−S₁(t)‖² + ‖S₂(c)−S₂(t)‖² divided by the target energy. Differentiable in c, so it composes with scattering(st, ·) under autodiff.

source

Monogenic (Riesz) scattering

ScatteringTransforms.Monogenic.MonogenicFilterBank — Type
MonogenicFilterBank{D,T,A,W,R,MV}

Isotropic band-pass wavelets wavelets (one per scale/sub-octave), the D scale-free Riesz multipliers riesz, and the Gaussian low-pass averaging. The wavelets and the low-pass are real functions of |k|; only the Riesz multipliers are complex.

source
ScatteringTransforms.Monogenic.MonogenicWorkspace — Type
MonogenicWorkspace{T,D}

The periodized cascade plus what the monogenic amplitude needs on top of it: one real accumulator per resolution, and the Riesz-weighted band-passes R_d ψ_j periodized to each parent resolution.

Each R_d ψ_j is stored as the periodization of the product, which differs from the product of the periodized factors. Level 1 stores none: the two full-resolution filters fuse in ScatteringCore.periodize_mul2!.

source
ScatteringTransforms.Monogenic.build_monogenic_bank — Function
build_monogenic_bank([T=Float64,] dims::NTuple{D,Int}, J; Q=1) -> MonogenicFilterBank

Build a D-dimensional isotropic Morlet-style monogenic filter bank: J octaves × Q sub-octaves of radial band-pass wavelets whose radial profile is Filters.Morlet1D's (center frequency ξ_j = ξ₀·2^{-j/Q}, adjacent wavelets crossing at √½ of their peak), the Riesz multipliers, and Filters.gaussian_lowpass!. The band-pass and its Riesz components carry 2|ψ̂_j|² per frequency, so the wavelets are scaled by c = lp_scale_1d(Q)/2, which puts 2c² Σ_j g(|k|·2^{j/Q})² (g the radial profile) at a maximum of 1 over the bank continued over every scale.

source
ScatteringTransforms.Monogenic.riesz_multipliers — Function
riesz_multipliers(dims, ::Type{T}=Float64) -> NTuple{D, Array{Complex{T},D}}

The D Riesz-transform frequency multipliers R_d(k) = -i k_d/|k| over a grid of size dims, with R_d(0) = 0. On an even axis d the Nyquist bin holds k_d = ±½ at once, and there R_d is the mean of its two values, 0, so a real field's Riesz components are real. Scale-free, so one set serves every wavelet scale; Σ_d |R_d(k)|² = 1 off the DC bin and the Nyquist planes.

source
ScatteringTransforms.Monogenic.monogenic_amplitude — Function
monogenic_amplitude(m0, riesz_components) -> A

Monogenic amplitude A = √(m₀² + Σ_d m_d²) from the band-pass field m0 and the tuple/vector of Riesz component fields. Broadcast, so it is CPU/GPU/autodiff-generic.

source
ScatteringTransforms.Monogenic.monogenic_components — Function
monogenic_components(st, x, j) -> (; bandpass, riesz, amplitude, phase)

The monogenic decomposition of a real field x band-passed by isotropic wavelet j (1-based): the band-pass field bandpass = x ⋆ ψ_j, the D Riesz component fields riesz, the monogenic amplitude √(bandpass² + Σ|riesz|²), and the local monogenic phase = atan(‖riesz‖, bandpass). The Riesz vector's direction gives the local orientation (e.g. atan(riesz[2], riesz[1]) in 2D).

source
ScatteringTransforms.spherical_monogenic_scattering — Function
spherical_monogenic_scattering(pts_theta, pts_phi, lmax, J; max_order=2,
                               transform=SpectralBackends.AutoSpectralBackend(), analysis=Plans.LeastSquares(),
                               rtol=SphericalCore.default_rtol(transform), maxiter=500,
                               weights=nothing, nufft=SpectralBackends.AutoSpectralBackend(),
                               grid_lmax=2lmax)

Build a monogenic spherical scattering transform for a scalar field at scattered points (θ, φ) on S². The nonlinearity is the spherical monogenic amplitude A_j = √(U⁰_j² + |U^R_j|²), where U⁰_j is the difference-of-Gaussians band-pass and U^R_j is the spin-1 Riesz field R = ð∘(−Δ_S)^{-1/2}. The Riesz energy |U^R_j|² = |∇_S g_j|² (with g_j = (−Δ_S)^{-1/2} U⁰_j) is synthesised exactly from g_j's coefficients (SphericalCore.sphere_riesz_energy!). The cascade runs on the Gauss–Legendre grid and the keywords are as in spherical_scattering.

source
ScatteringTransforms.spherical_monogenic_components — Function
spherical_monogenic_components(st, field, j) -> (; bandpass, riesz, amplitude, phase, orientation)

Pointwise spherical monogenic decomposition of field band-passed at scale j — the S² analogue of the planar monogenic_components. Returns the band-pass field bandpass = U⁰_j, the spin-1 Riesz tangent vector riesz = (u_θ, u_φ) (U^R_j = ð∘(−Δ_S)^{-1/2} U⁰_j), the monogenic amplitude √(U⁰² + ‖U^R‖²), the phase = atan(‖U^R‖, U⁰), and the local orientation = atan(u_φ, u_θ) of the Riesz vector. st is a scattered or structured spherical monogenic transform. With the in-core direct SH plan (dependency-free) the Riesz field is synthesized as the surface gradient of g = (−Δ_S)^{-1/2}U⁰; with a NUFSHT-backed plan it uses spin-weighted synthesis — the two agree to solver accuracy.

source

Localized (Mallat) field

Coefficients & reductions

ScatteringTransforms.Coefficients.ScatteringCoefficients1D — Type
ScatteringCoefficients1D{T,V,M,S0}

Immutable container for 1D scattering coefficients. S0 is either a scalar, which update_S0 replaces by returning a new container, or a 1-element array, which it writes in place.

Type Parameters

  • T: Element type
  • V: 1D array type
  • M: 2D array type
  • S0: S0 storage type (T for scalar, AbstractVector{T} for mutable)
source
ScatteringTransforms.Coefficients.flat_length — Function
flat_length(n) -> Int
flat_row_s0() -> Int
flat_row_s1(j, n) -> Int
flat_row_s2(j1, j2, n) -> Int

Row layout of the flattened coefficient vector [S0; S1; vec(S2 upper triangle)] for n wavelets, as produced by flatten1d!/flatten2d!. The S2 rows are present, zero, for coefficients that hold no S2.

The batched paths write flattened columns through these accessors, so they must match the order the flatten*! loops write.

source
ScatteringTransforms.Coefficients.flat_eltype — Function
flat_eltype(c) -> Type

Element type a flattened column of c needs.

S1 and S2 are moduli and stay real whatever the input is, but S0 is the field mean and is complex for a complex field, so the flat layout is as wide as the two together.

source
ScatteringTransforms.Scattering2D.compute_shape_sparsity — Function
compute_shape_sparsity(S1, S2, meta) -> (; sparsity, shape)

Reduced second-order descriptors (in the spirit of the reduced wavelet scattering transform, Allys et al. 2019; Cheng & Ménard 2021), as J × J matrices over scale pairs (j1, j2) with j2 > j1:

  • sparsity (s₂₁): the orientation-averaged ratio ⟨S₂ / S₁⟩ — how much energy cascades from scale j1 to the coarser scale j2 (large for sparse/intermittent fields).
  • shape (s₂₂): the anisotropy of the cascade — the normalized second angular harmonic ⟨S₂ · cos(2 Δθ)⟩ / ⟨S₂⟩ over orientation pairs, where Δθ = θ₂ − θ₁. It is ≈ 0 for statistically isotropic fields and departs from zero when the field has oriented structure.
source
ScatteringTransforms.Reductions.log_coefficients — Function
log_coefficients(c; pad=eps) -> (; S0, logS1, logS2)

Log-coefficients log(S1 + pad), log(S2 + pad) (the small pad keeps structural zeros finite). Useful to gaussianize the heavy-tailed coefficients of intermittent fields.

source

flat_length's docstring also covers the row accessors flat_row_s0, flat_row_s1 and flat_row_s2, which are the layout flatten1d!, flatten2d! and the batched paths all walk.

Batching & backends

Where a transform runs is chosen with a backend from ComputationalBackends.jl — SerialBackend, ThreadedBackend, GPUBackend, DistributedBackend, MPIBackend, AutoBackend — passed as execution= to scattering_batch and scattering_batch!; the gridded scattering_transform! entries take SerialBackend or ThreadedBackend the same way. Which spectral algorithm it uses is chosen with a SpectralBackends.jl tag passed as transform= at construction. Each is honoured exactly: naming a backend whose extension is not loaded throws.

ScatteringTransforms.scattering_batch — Function
scattering_batch(st::ScatteringCore.ScatteringTransform{1}, X; execution = SerialBackend()) -> Matrix

Apply a 1D scattering transform to a batch of signals X of size (N, B) (signals as columns), returning a (flatten_length, B) matrix whose column b is flatten1d(st(X[:, b])). The plan, the workspace and one coefficient container are reused across the batch. execution is where the batch runs, as in scattering_batch!.

source
scattering_batch(st::ScatteringCore.ScatteringTransform{2}, X; execution = SerialBackend()) -> Matrix

Apply a 2D scattering transform to a batch of images X of size (Ny, Nx, B), returning a (flatten_length, B) matrix whose column b is flatten2d(st(X[:, :, b])). Plan and workspace are reused across the batch. execution is as in scattering_batch!.

source
scattering_batch(st::ScatteringCore.ScatteringTransform{3}, X; execution = SerialBackend()) -> Matrix

Apply a 3D scattering transform to a batch of volumes X of size (Nz, Ny, Nx, B), returning a (flatten_length, B) matrix. Plan and workspace are reused across the batch. execution is as in scattering_batch!.

source
scattering_batch(st::ScatteredPlanar.ScatteredPlanarScatteringTransform, X; execution = SerialBackend())
    -> Matrix or (; coefficients, fit)

Transform every slice of X against one transform, returning a (flatten_length, B) matrix. X is (M, B), where M is the plan's point count. A transform built with ntrans = W > 1 runs the columns W at a time, through one execution per cascade step for each group, the last group padded with zero columns. Under analysis = Plans.LeastSquares() the matrix comes with fit, one FlowTransformBindings.SolverResult per field. execution is as in scattering_batch!.

source
scattering_batch(st::SphericalCore.SphericalScatteringTransform, X; execution = SerialBackend())
    -> Matrix or (; coefficients, fit)
scattering_batch(st::SphericalCore.SphericalMonogenicScatteringTransform, X; execution = SerialBackend())
    -> Matrix or (; coefficients, fit)

Transform a stack of B fields sampled by the same spherical plan — X of size (field_size…, B), so (M, B) for a scattered point set and (nθ, nφ, B) on a structured grid. A plan whose analysis is a least-squares fit gives the matrix with fit, one FlowTransformBindings.SolverResult per field. execution is as in scattering_batch!.

Rows follow Coefficients.flat_length. Scales are finest-first and second-order pairs satisfy j2 > j1, with row flat_row_s2(j1, j2, J).

source
ScatteringTransforms.scattering_batch! — Function
scattering_batch!(out, st, X; execution = SerialBackend(), workspace = nothing) -> out or (; coefficients, fit)

In-place counterpart of scattering_batch: write the flattened coefficients of each slice of X into the preallocated (flatten_length, B) matrix out. A transform whose analysis of its samples is a least-squares fit returns (; coefficients = out, fit), fit[b] field b's FlowTransformBindings.SolverResult as its single call reports it.

execution is where the batch runs: SerialBackend in this task, ThreadedBackend and GPUBackend through their extensions (OhMyThreads; KernelAbstractions, for the gridded transforms), and AutoBackend as Execution.resolve_backend resolves it. DistributedBackend and MPIBackend gather a new matrix, so they run through scattering_batch alone. A backend whose extension is not loaded throws.

On SerialBackend a gridded transform runs one slice at a time against its own single-slice plan, which on a CPU keeps each slice's working set in cache. Passing a batch_workspace runs the whole stack through one batched plan (Batched.batch_cascade!), as the GPU extension does.

source
ScatteringTransforms.batch_coeffs — Function
batch_coeffs(st, T, S0T = T) -> coefficient container

A coefficient container for st whose S0 is a 1-element array, so a loop over a batch writes every field in place.

T is the element type of S1/S2, which are moduli; S0T is that of S0, the field mean, which is complex for a complex field.

source
ScatteringTransforms.batch_workspace — Function
batch_workspace(st, B; transform = nothing, fft_nthreads = 1, kwargs...) -> Batched.BatchWorkspace

Build the batched workspace for transform st at batch size B: a spectral plan over the whole (spatial…, B) stack plus the scratch Batched.batch_cascade! runs in, on the array type of st's own buffers. Build it once and pass it as workspace to scattering_batch! for every stack of B slices.

The stack's plan is of the kind st.plan is (Plans.plan_like), so a device-resident st gets a device workspace; a SpectralBackends tag as transform builds a host plan of that kind. fft_nthreads is the FFT library's own thread count, fixed in the plan; leave it at 1 when the batch or wavelet axis is already threaded. kwargs go to the plan builder.

source
ScatteringTransforms.Batched.batch_cascade! — Function
batch_cascade!(out, ws, X) -> out

Write the flattened scattering coefficients of every slice of X into the columns of out, which has Coefficients.flat_length(n) rows in the layout flatten1d!/flatten2d! produce. A complex X needs complex columns, for its complex S0.

The batched form of Cascade.cascade!, with each mean replaced by a per-slice reduction and each decimation tuple extended by a 1 for the stack axis.

source

The periodized cascade

Each wavelet's output is produced directly on the grid its band needs, decimated by r = 2^max(j-oversampling, 0) per axis. Exact at oversampling ≥ J, which reproduces the undecimated cascade bit for bit; below that it trades accuracy for speed.

ScatteringTransforms.Cascade.decimation — Function
decimation(N, scale, α) -> NTuple{D,Int}

Per-axis decimation for a wavelet of octave scale: 2^max(scale-α, 0), reduced on each axis to the largest power of two that divides N[d]. The clamp only reduces decimation, so any N is accepted at no cost in accuracy.

source
ScatteringTransforms.Cascade.PeriodizedWorkspace — Type
PeriodizedWorkspace{T,D}

Everything the cascade runs in: one working array and one spectrum array per live decimation, the spectral plan at each of those sizes, and the filters periodized to each resolution they are applied at.

Everything per-resolution is a vector indexed by level, with level[j] the level of wavelet j and level 1 the full grid. out[l] === work[l] when the plan inverts in place. spec[l] is empty except at levels that are a parent, where it holds Û₁ across that wavelet's children. D is the spatial rank of the resolutions; a batched workspace's arrays carry a trailing stack axis on top of it. means is a DeviceMeans on a device-resident workspace and nothing otherwise.

source
ScatteringTransforms.Cascade.DeviceMeans — Type
DeviceMeans{R,V,M,H}

The per-path sums of a single-field cascade on device arrays, accumulated on the device so that the cascade synchronises with the host once, after its last path: red is a (1, …, 1) reduction target, s1 holds one sum per wavelet and s2 one per (j1, j2) pair, and invlen[j] is one over the size of the grid wavelet j is produced on, which turns a sum into a mean.

source
ScatteringTransforms.Cascade.build — Function
build(fb, groups, dims, T, α, plan) -> PeriodizedWorkspace

groups is the cascade work list (j1, children, pathids); it determines which resolutions are live and which (wavelet, resolution) filter pairs are ever applied, so nothing unused is built. plan is the transform's full-grid plan and serves as level 1; the coarser levels are planned with its spectral backend.

source
ScatteringTransforms.Cascade.cascade! — Function
cascade!(S1, S2, ws, fb, groups, xfft) -> (S1, S2)

Both scattering orders in one grouped pass, each convolution produced directly on the grid its wavelet's band needs.

Order 1 multiplies by the full-resolution filter and periodizes the product. Order 2 multiplies Û₁ by ψ_{j₂} periodized to the parent's grid, then periodizes the product onto the child's; r₂ ≥ r₁, since admissibility makes the child strictly coarser.

source
ScatteringTransforms.Cascade.group! — Function
group!(S1, S2, ws, fb, g, xfft) -> nothing

One first-order wavelet and all of its children. Group j1 writes only S1[j1] and S2[j1, :], so tasks may run distinct groups concurrently, each with its own task_copy of the workspace. The caller clears S2.

source
ScatteringTransforms.Cascade.scattering_values — Function
scattering_values(st, x) -> (S0, S1, S2)

The same periodized cascade as cascade!, written with allocating transforms and broadcasts so that reverse-mode backends can differentiate it. Dimension-generic; the per-dimension scattering methods wrap the result in their coefficient container.

It must compute the same function as st(x), decimation included: synthesize differentiates this to match coefficients read from st(x).

source
ScatteringTransforms.Cascade.task_copy — Function
task_copy(ws, fb) -> ws′

A workspace usable concurrently with ws: fresh buffers and task-local plans, sharing the read-only periodized filters. Every task that runs group! needs its own.

fb is the bank the copy runs against. For a computed bank it must be the task's own FilterBanks.task_bank, whose scratch the copy's level-1 filters alias.

source
ScatteringTransforms.Cascade.FieldWorkspace — Type
FieldWorkspace{T,D}

The periodized cascade plus what the localized transform S_p = (|U_p| ⋆ φ_J) ↓ s needs on top of it: φ_J periodized to every level a modulus is produced at, and one buffer and plan at the output resolution.

Its cascade is built with alias_out = false and decimates no wavelet past s (see field_oversampling), so every path is produced at or above the output resolution. At the default s = 2^(J-1) the cap changes nothing.

source
ScatteringTransforms.Cascade.build_field — Function
build_field(fb, groups, dims, T, α, s, φ; alloc, makeplan) -> FieldWorkspace

Workspace for the localized transform at output subsample factor s. φ is the full-resolution low-pass.

source
ScatteringTransforms.Cascade.field_workspace — Function
field_workspace(st, subsample) -> FieldWorkspace

The localized-field workspace for transform st at output factor subsample.

st must have fields filter_bank, groups, dims, plan, buffer_input and pw. Buffers take buffer_input's array type and plans plan's kind, so a device-resident transform gets a device-resident workspace.

source
ScatteringTransforms.Cascade.field_oversampling — Function
field_oversampling(fb, α, s) -> Int

The smallest oversampling at least α under which no wavelet decimates past s.

r = 2^max(j-α, 0) ≤ s = 2^q iff α ≥ j - q, so raising α to maxscale - q caps every resolution at the output grid without changing the dyadic family any wavelet lands on.

source
ScatteringTransforms.Cascade.localize! — Function
localize!(dst, fw, spec, level) -> dst

dst = real(ifft(spec ⋅ φ̂) ↓ (rout/r)), where spec is the spectrum of a modulus living at level. The product is periodized onto the output grid, so the inverse runs at output size.

source
ScatteringTransforms.Cascade.field_group! — Function
field_group!(data, fw, fb, g, xfft, p1_first) -> nothing

One first-order wavelet and all of its children, written as localized fields into data's trailing path axis. The order-1 path id is p1_first + j1 - 1; the children's come from the group.

source
ScatteringTransforms.ScatteringCore.periodize_mul! — Function
periodize_mul!(dst, src, filt, r) -> dst
periodize!(dst, src, r) -> dst

dst[k] = (1/∏r) Σ_m src[k + m∘n] * filt[k + m∘n], where n = size(dst) and m runs over the ∏r alias blocks: the spectrum of (src ⋆ filt) decimated by r per axis. For any spectrum Ŷ,

ifft_N(Ŷ)[1:r:end] == ifft_M(periodize_r(Ŷ)),   M = N ./ r

with the 1/∏r supplying the normalisation ifft_M lacks. Indices are 0-based on unshifted grids, so bin k of dst gathers bins k, k+n, k+2n, … of src; a singleton filt axis broadcasts. Both are broadcasts only, so they run on device arrays.

source
ScatteringTransforms.ScatteringCore._modulus — Function
_modulus(z)

|z| for the scattering nonlinearity, computed as sqrt(abs2(z)).

It agrees with abs(z) to one ulp while abs2(z) neither overflows nor underflows, i.e. for sqrt(floatmin) < |z| < sqrt(floatmax). A wavelet coefficient is O(‖x‖), so a field near those magnitudes must be rescaled before transforming.

source
ScatteringTransforms.ScatteringCore.periodize_filter! — Function
periodize_filter!(dst, src, r) -> dst

A filter periodized onto a coarser grid: dst[k] = Σ_m src[k + m∘n], with no 1/∏r, which periodize_mul! applies to the product being decimated.

The periodized filter keeps the original's frequencies. A Morlet evaluated afresh on the N/r grid is a different wavelet: its profile is a function of normalised angular frequency, so its peak lands at bin (N/r)·k0/2π, an octave lower per factor of two.

source
ScatteringTransforms.Filters.gaussian_lowpass! — Function
gaussian_lowpass!(φ, σ) -> φ
gaussian_lowpass(T, dims, J; sigma0=0.8) -> Array{T,D}

Isotropic Gaussian low-pass φ̂(k) = exp(-|k|²σ²/2) on the FFT grid of dims, with k the angular frequency (2π·fftfreq per axis) and σ = sigma0·2^J a real-space width: the averaging filter φ_J of every filter bank, and of the localized transform S_p = (U_p ⋆ φ_J) ↓ s.

φ̂(0) = 1, so averaging preserves a field's mean. Decimation by s keeps ⟨S_p⟩ = ⟨U_p⟩ when φ̂ vanishes on the lattice {2πm/s : m ≠ 0}; at s = 2^(J-1) its largest value there is exp(-(4π·sigma0)²/2), 1e-22 at sigma0 = 0.8.

source
ScatteringTransforms.Plans.plan_like — Function
plan_like(plan, prototype) -> plan′
plan_like(plan, prototype, D; kwargs...) -> plan′

A plan of the same kind as plan, sized for arrays like prototype, for a cascade that needs plans at resolutions chosen after the transform was built. The three-argument form transforms the leading D axes of prototype and leaves its trailing stack axis alone, with kwargs going to the plan builder. A device plan has no spectral-backend tag, so its method plans on prototype's array type.

source
ScatteringTransforms.Plans.inplace_inverse — Function
inplace_inverse(plan) -> Bool

Whether inverse_transform!(x, plan, x) is valid, letting a transform alias its convolution output with its multiply scratch. Default false: the direct-sum plan ping-pongs through its own scratch, and over an odd number of axes its first pass writes into its input.

source

Filter banks, filters & path graph

ScatteringTransforms.FilterBanks.FilterBank1D — Type
FilterBank1D{T,V,W,MV}

Complete 1D filter bank for the scattering transform. V is the per-filter array type, W the wavelet collection and MV the metadata collection.

Fields

  • wavelets::W: wavelet filters in the Fourier domain (W<:AbstractVector{V})
  • averaging::V: low-pass averaging (scaling) filter
  • meta::MV: per-wavelet WaveletMeta
  • J::Int: number of octaves (scales)
  • Q::Int: wavelets per octave
source
ScatteringTransforms.FilterBanks.FilterBank2D — Type
FilterBank2D{T,M,W,MV}

Complete 2D filter bank with oriented wavelets. M is the per-filter matrix type, W the wavelet collection and MV the metadata collection.

Fields

  • wavelets::W: oriented wavelet filters (W<:AbstractVector{M})
  • averaging::M: low-pass averaging filter
  • meta::MV: per-wavelet WaveletMeta
  • J::Int: number of scales
  • L::Int: number of orientations
source
ScatteringTransforms.FilterBanks.FilterBank3D — Type
FilterBank3D{T,A,W,MV}

Complete 3D oriented Morlet filter bank: J scales × n_orient sphere directions, plus a low-pass averaging filter. A is the per-filter array type, W the wavelet collection and MV the metadata collection.

source
ScatteringTransforms.FilterBanks.WaveletMeta — Type
WaveletMeta{T}

Per-wavelet metadata.

Fields

  • scale::Int: octave index j
  • q::Int: sub-octave index within the octave (1D, 0..Q-1); 0 otherwise
  • orient::Int: orientation index (0..L-1 in 2D, 0..n_orient-1 in 3D); 0 in 1D
  • j_eff::T: effective log-scale that orders paths, j + q/Q in 1D and T(j) in 2D and 3D. A second-order path is admissible iff j_eff(child) > j_eff(parent), which in 2D and 3D admits every orientation pair at a strictly coarser scale.
  • center_freq::T: wavelet center frequency
  • theta::T: orientation angle in radians (2D); 0 otherwise
source
ScatteringTransforms.FilterBanks.build_filter_bank1d — Function
build_filter_bank1d([T = Float64,] N, J; Q = 1) -> FilterBank1D

Build a 1D Morlet filter bank with dyadic scales, Littlewood–Paley normalized by lp_scale_1d.

Arguments

  • N::Int: Signal length (FFT size)
  • J::Int: Maximum scale (number of octaves)
  • Q::Int: Wavelets per octave (default 1 for dyadic, 8 for high Q)

Returns

  • FilterBank1D: Complete filter bank with J scales
source
build_filter_bank1d(T, N, J, filters::AbstractFilterStorage; Q = 1)
build_filter_bank3d(T, N, J, filters::AbstractFilterStorage; n_orient = 6)

ComputedFilters() returns a computed bank, which evaluates each wavelet on demand; StoredFilters() returns the stored bank.

source
ScatteringTransforms.FilterBanks.build_filter_bank2d — Function
build_filter_bank2d([T = Float64,] N, J; L = 8) -> FilterBank2D

Build a 2D oriented Morlet filter bank, Littlewood–Paley normalized by lp_scale_2d.

Arguments

  • N::NTuple{2,Int}: Image dimensions (Ny, Nx)
  • J::Int: Number of dyadic scales
  • L::Int: Number of orientations (default 8, evenly spaced)

Returns

  • FilterBank2D: Complete 2D filter bank
source
build_filter_bank2d(T, N, J, filters::AbstractFilterStorage; L = 8)

ComputedFilters() returns a ComputedFilterBank2D, which evaluates each wavelet on demand; StoredFilters() returns the stored bank.

source
ScatteringTransforms.FilterBanks.ComputedFilterBank2D — Type
ComputedFilterBank2D{T,M,MV,WV}

A 2D bank that stores its wavelets' parameters and evaluates one, scaled by the Littlewood–Paley constant, into a single scratch array on each filter_at call.

It holds two grid-sized arrays, the low-pass and the scratch, against J·L+1 for a stored bank, and costs two exp per grid point per application. The scratch is mutable, so tasks cannot share one bank; task_bank gives each its own scratch.

source
ScatteringTransforms.FilterBanks.batch_views — Function
batch_views(fb, spatial) -> Vector

The bank's filters reshaped to (spatial…, 1), so they broadcast over a batch axis.

For a computed bank every entry is the same view of its scratch, so a caller must call filter_at(fb, j) immediately before using entry j.

source
ScatteringTransforms.FilterBanks.littlewood_paley — Function
littlewood_paley(fb) -> A

The bank's Littlewood–Paley sum for a real field, A(ω) = |φ̂(ω)|² + ½ Σ_λ (|ψ̂_λ(ω)|² + |ψ̂_λ(−ω)|²), on its frequency grid. The wavelet transform of a real field is bounded by minimum(A)·‖x‖² ≤ ‖Wx‖² ≤ maximum(A)·‖x‖², and Inverse.iwavelet! divides by A.

source
littlewood_paley(fb::AnyMonogenicBank) -> A

A(k) = |φ̂(k)|² + Σ_j |ψ̂_j(k)|² (1 + Σ_d |R_d(k)|²), the energy the band-pass, Riesz and low-pass outputs of a real field carry per frequency.

source
ScatteringTransforms.FilterBanks.lp_scale_2d — Function
lp_scale_2d(L; sigma0=0.8) -> c

The wavelet scale of a 2D Morlet bank with L orientations: ½ Σ_{j,ℓ} (|c·ψ̂_{j,ℓ}(k)|² + |c·ψ̂_{j,ℓ}(−k)|²) peaks at 1 over the bank continued over every scale.

source
ScatteringTransforms.FilterBanks.lp_scale_3d — Function
lp_scale_3d(n_orient; sigma0=0.8) -> c

The wavelet scale of a 3D Morlet bank over n_orient Fibonacci directions: ½ Σ_{j,o} (|c·ψ̂_{j,o}(k)|² + |c·ψ̂_{j,o}(−k)|²) peaks at 1 over the bank continued over every scale.

source
ScatteringTransforms.Filters.Morlet1D — Type
Morlet1D{T<:Real}

1D Morlet wavelet in frequency domain, over normalized frequency ω ∈ [0, ½]:

Ψ(ω) = exp(-(ω-ξ)²/2σ²) - κ exp(-ω²/2σ²),   κ = exp(-(ξ/σ)²/2)

σ is a frequency-domain width. κ sets Ψ(0) = 0, so the wavelet has zero mean. The filter is analytic: zero for ω < 0.

Type Parameters

  • T: Element type (Float32, Float64, etc.)

Fields

  • center_freq::T: Center frequency ξ
  • bandwidth::T: Frequency-domain width σ
  • N::Int: Filter length (FFT size)
source
ScatteringTransforms.Filters.Morlet2D — Type
Morlet2D{T<:Real}

2D oriented Morlet wavelet in the frequency domain, k the angular wavenumber:

Ψ(k) = exp(-((k∥ - k₀)²σ∥² + k⊥²σ⊥²)/2) - β exp(-(k∥²σ∥² + k⊥²σ⊥²)/2),   β = exp(-(k₀σ∥)²/2)

for k∥ ≥ 0 and zero otherwise, with k∥ = kx cos θ + ky sin θ, k⊥ = -kx sin θ + ky cos θ. The widths are real-space: σ∥ = sigma0·2ʲ, σ⊥ = σ∥·L/4, and k₀ = 3π/(4·2ʲ). The envelope's angular standard deviation at |k| = k₀ is then 4/(L·k₀σ∥), which at the default sigma0 is 0.68·π/L: a fixed fraction of the spacing π/L of the L orientations.

Fields

  • center_freq::T: k₀
  • sigma_par::T, sigma_perp::T: real-space widths along and across the orientation
  • theta::T: orientation angle in radians, from the second array axis
  • beta::T: zero-mean correction
  • N::NTuple{2,Int}: filter dimensions (Ny, Nx)
source
ScatteringTransforms.Filters.Morlet3D — Type
Morlet3D{T<:Real}

3D oriented Morlet wavelet in the frequency domain, a bump centered at k₀ n̂ for a unit direction n̂, analytic on the half-space k·n̂ ≥ 0: Morlet2D's envelope with k∥ = k·n̂ and k⊥ = |k − k∥ n̂|. The real-space widths are σ∥ = sigma0·2ʲ and σ⊥ = σ∥·√(π·n_orient)/8, the 2D rule σ⊥ = σ∥·π/(4Δθ) at the spacing Δθ = √(4π/n_orient) of n_orient directions spread over the sphere.

Fields

  • center_freq::T: |k₀|
  • sigma_par::T, sigma_perp::T: real-space envelope widths along / perpendicular to n̂
  • direction::NTuple{3,T}: unit orientation n̂
  • beta::T: zero-mean correction
  • N::NTuple{3,Int}: grid dimensions
source
ScatteringTransforms.Filters.frequency_response — Function
frequency_response(m::Morlet1D{T}) -> Vector{T}

The frequency response Ψ(ω) of m on its N-point FFT grid, zero at negative frequencies.

source
frequency_response(m::Morlet2D{T}) -> Matrix{T}

The 2D frequency response Ψ(kx, ky) of an oriented Morlet wavelet, on its FFT grid.

source
frequency_response(m::Morlet3D{T}) -> Array{T,3}

3D frequency response Ψ(kx,ky,kz) of an oriented Morlet wavelet.

source
ScatteringTransforms.Filters._alias_rms — Function
_alias_rms(f, n, I) -> value

f at the normalized frequencies of bin I of an n-point grid, f taking an NTuple of them. On an even axis's Nyquist bin −½ and +½ are one bin, so there the value is the root mean square of f over every sign of those coordinates. A real field's Littlewood–Paley sum at that bin is then the mean of the continuous sum over its aliases: an analytic wavelet centred at +½ keeps the bin.

source
ScatteringTransforms.PathGraph.ScatteringTree — Type
ScatteringTree{IV,RV}

Flat CSR description of the scattering tree: wavelet indices into the filter bank and per-path order labels. The containers are parametric; build_tree produces Vector{Int} and Vector{UnitRange{Int}}.

Fields

  • path_data: concatenated wavelet-index lists for all paths
  • path_ptr: CSR offsets (length npaths+1); path p is path_data[path_ptr[p]:path_ptr[p+1]-1]
  • order: scattering order of each path (0, 1, 2, …)
  • by_order: by_order[o+1] is the contiguous range of path ids of order o
source
ScatteringTransforms.PathGraph.build_tree — Function
build_tree(j_eff, max_order) -> ScatteringTree

Enumerate all admissible paths up to max_order from the per-wavelet effective log-scales j_eff (typically [m.j_eff for m in filter_bank.meta]). Admissibility: j_eff strictly increasing along the path. Paths are laid out grouped by order (order 0, then 1, then 2, …), so by_order ranges are contiguous.

source
ScatteringTransforms.PathGraph.order2_groups — Function
order2_groups(tree, nw) -> Vector{Tuple{Int,Vector{Int},Vector{Int}}}

Every first-order wavelet j1 with its admissible order-2 children j2 and the tree path ids of those (j1, j2) pairs, longest group first.

The cascade computes each first-order modulus once per group, and the localized-field output is indexed by the path ids. Longest-first order balances the parallel backends, since the child count varies across scales.

source

Spectral plans & core operations

ScatteringTransforms.Plans.DirectSumPlan — Type
DirectSumPlan{T,V,D,S}

Direct-summation DFT plan: evaluates X_k = Σ_n x_n e^{-2πi kn/N} (and its inverse) by direct summation, separably over the leading D dimensions, leaving a trailing batch axis of length nbatch untouched. Memory is O(N): a per-axis table of roots of unity and its conjugate. scratch is nothing for D == 1 and a full-size complex array otherwise.

source
ScatteringTransforms.Plans.make_plan — Function
make_plan(spectral, T, dims; batch = nothing, kwargs...) -> AbstractScatteringPlan

Build the spectral plan selected by spectral for arrays whose leading dimensions are dims and whose element type is Complex{T}: arrays of size dims for batch = nothing, and (dims…, batch) stacks for an integer batch.

SpectralBackends.DirectSumSpectralBackend is the dependency-free in-core default; SpectralBackends.FFTSpectralBackend requires using FFTW; SpectralBackends.AutoSpectralBackend takes the FFTW fast path when its extension is loaded and otherwise the in-core direct sum.

source
ScatteringTransforms.Plans.make_scattered_plan — Function
make_scattered_plan(spectral, x, y, ms, T; period, origin = (0, 0), analysis, maxiter, rtol, damp,
                    tol, ntrans, nthreads) -> AbstractScatteringPlan

Build the scattered/nonuniform planar plan selected by spectral over points (x, y) and a uniform mode grid of size ms. SpectralBackends.DirectSumSpectralBackend is the dependency-free exact NUDFT; FlowTransformBindings.FINUFFTBackend() and FlowTransformBindings.NonuniformFFTsBackend() select a nonuniform-FFT library; SpectralBackends.AutoSpectralBackend takes NonuniformFFTs when it is loaded and FINUFFT when only it is, and the exact direct sum when neither is.

period is the domain's length along each axis and origin its lower corner, each a number for both axes or a 2-tuple. A point lies at 2π·mod(x - origin, period)/period on the plan's 2π-periodic domain, so mode k has wavelength period/k whatever the point set.

ntrans is the batch width and nthreads the library's own thread count (0, the default, takes Threads.nthreads()). The exact direct sum has no tolerance and runs on one thread, so it accepts tol and nthreads and ignores them.

source
ScatteringTransforms.Plans.available — Function
available(spectral) -> Bool

Whether the extension implementing spectral is loaded: true from that extension, so the transform AutoSpectralBackend takes follows from the loaded methods.

source
ScatteringTransforms.Plans.spectral_backend — Function
spectral_backend(plan) -> SpectralBackends.AbstractSpectralBackend

The spectral-backend tag that rebuilds plan on another process. A plan that a tag cannot rebuild, such as a device-resident FFT plan, throws.

source
ScatteringTransforms.Plans.task_local_plan — Function
task_local_plan(plan) -> plan

A plan equivalent to plan that is safe to use concurrently with it. Stateless plans (FFTW, AbstractFFTs) return themselves; plans carrying mutable scratch return a copy that shares their read-only tables and owns fresh scratch. Called once per task by the parallel backends.

A method that builds a new library plan takes its thread count from per_task_nthreads, and the caller must close_plan! that plan when the task ends.

source
ScatteringTransforms.Plans.batch_width — Function
batch_width(plan) -> Int

Number of co-located fields plan transforms per execution: 1 unless it was built for a batch. A nonuniform plan's width is fixed at construction, so it transforms exactly that many fields per execution.

source
ScatteringTransforms.Plans.plan_points — Function
plan_points(plan) -> (x, y)

The scattered sample locations a nonuniform plan was built on, already mapped onto its 2π-periodic domain, from which a transform is rebuilt on another process. Rebuilding from these requires period = (2π, 2π), since they are already scaled.

source
ScatteringTransforms.Plans.plan_analysis — Function
plan_analysis(plan) -> (; analysis, maxiter, rtol, damp, tol, nthreads)

How a scattered-planar plan turns samples into modes, as the keyword arguments its constructor takes.

A plan rebuilt on the same points needs these too: on irregular sampling the type-1 adjoint and the least-squares inversion are different transforms. tol is nothing for the exact direct sum.

source
ScatteringTransforms.Plans.DirectNUFFTPlan — Type
DirectNUFFTPlan{T,TB,CV,RV,WS}

Exact direct-summation NUDFT between M scattered points and an ms mode grid, transforming batch_width(plan) co-located fields per call. Memory is O(M·(ms₁ + ms₂)): one exponential table per axis.

source
ScatteringTransforms.Plans.NUFFTScatteringPlan — Type
NUFFTScatteringPlan

Scattered-planar plan over FlowTransformBindings NUFFT plans on fixed points: a complex plan for synthesis and for complex samples, and a real plan for real samples and the real solve. B is the number of co-located fields each execution transforms, and transform the NUFFT library tag the plans run on.

source
ScatteringTransforms.Plans.nufft_scattered_plan — Function
nufft_scattered_plan(backend, x, y, ms, T; period, origin = (0, 0), analysis, maxiter, rtol, damp,
                     tol, ntrans, nthreads) -> NUFFTScatteringPlan

The scattered-planar plan over points (x, y) and mode grid ms on a FlowTransformBindings NUFFT backend, on a domain of length period with lower corner origin (see make_scattered_plan). nthreads = 0 takes the session's Threads.nthreads().

source
ScatteringTransforms.Plans.with_fft_nthreads — Function
with_fft_nthreads(f, n) -> f()

Run f, which builds plans, under FFTW.jl's planner lock with FFTW's planner thread count set to n and restored after (FFTW.set_num_threads(f, n)); without FFTW loaded, just call f().

FFTW's planner state is process-global and shared by every library that plans on libfftw3, and a plan keeps the thread count it was built with, so every plan builder here sets the count through this. The fallback takes args... so the FFTW extension's two-argument method is more specific and adds a method; redefining this one is an error during precompilation.

source
ScatteringTransforms.Plans.close_plan! — Function
close_plan!(plan) -> nothing

Release the foreign-library resources plan owns without waiting for garbage collection. A no-op by default, and safe to call more than once. Whoever builds a plan for a task closes it when the task ends; cuFINUFFT plans are released only by this.

source
ScatteringTransforms.ScatteringCore.wavelet_convolve! — Function
wavelet_convolve!(out, signal_fft, filter_fft, plan, buffer)

Wavelet convolution without allocation: multiplies signal_fft .* filter_fft into buffer, then applies the inverse spectral transform via Plans.inverse_transform!(out, plan, buffer).

out and buffer must both be pre-allocated complex arrays of the same size.

source
ScatteringTransforms.ScatteringCore.task_workspace — Function
task_workspace(st) -> st′

A transform equivalent to st that shares its read-only parts — filter bank, path tree, work list — but owns fresh buffers and a task-local spectral plan, so the two can run concurrently. Methods are defined per transform type.

source

Scattered least-squares solve

analysis = ST.Plans.LeastSquares() fits spectral coefficients with FlowTransformBindings.lsmr!. ST.Plans.WeightedAdjoint() applies the quadrature-weighted adjoint. The planar default is WeightedAdjoint(); the scattered-sphere default is LeastSquares().

rtol controls the fit's relative normal residual. A fit that reaches its iteration or condition limit returns its best iterate. A transform whose analysis is a fit returns (; coefficients, fit): fit is the FlowTransformBindings.SolverResult (converged, iterations, residual) of the least converged fit the call ran, and a batch's fit holds one per field. A transform that fits nothing returns its coefficients alone. For scattered planar transforms, tol controls NUFFT accuracy and nthreads controls the NUFFT library's threads.

ScatteringTransforms.Plans.default_solver_rtol — Function
default_solver_rtol(::Type{T}, spectral, tol) -> T

Stopping tolerance for the scattered least-squares solve, set by the accuracy of the transform under it.

The direct sum evaluates an exact adjoint pair, so the target is sqrt(Base.eps(T)). A fast NUFFT's type-1 and type-2 are adjoints only to its tolerance tol (the library default for T when nothing), so the target is max(10·tol, sqrt(Base.eps(T))).

source
ScatteringTransforms.Plans.warn_underdetermined — Function
warn_underdetermined(M, ms, analysis, damp) -> nothing

Warn, once, that a solve has more modes than samples and no damping.

With prod(ms) > M at least prod(ms) - M mode directions are constrained by no sample, and LSMR returns the minimum-norm iterate. Whether that is the answer wanted, or whether to reduce ms, add samples, or set damp for Tikhonov regularisation, is the caller's choice; no λ is chosen for them.

source

Plans supplied by extensions

These are declared in the core and given a method by the corresponding extension. Calling one without its package loaded raises with the using line to run.

ScatteringTransforms.Plans.fftw_plan — Function
fftw_plan(T, dims; batch, planning, fft_nthreads) -> AbstractScatteringPlan

Build the FFTW-backed plan, a method the FFTW extension defines; this fallback throws an ArgumentError naming using FFTW.

source
ScatteringTransforms.Plans.abstractffts_plan — Function
abstractffts_plan(dummy_device_array; region = 1:ndims(dummy_device_array), fft_nthreads = 1)

FFT plan for the array type of dummy_device_array, built through AbstractFFTs.plan_fft and plan_ifft, so a CuArray gives a cuFFT plan and a ROCArray a rocFFT plan. region selects the transformed dimensions, e.g. (1, 2) for a (Ny, Nx, B) stack. The KernelAbstractions extension defines the method.

source

Execution backends

ScatteringTransforms.Execution.resolve_backend — Function
resolve_backend(backend) -> AbstractLocalBackend

Concrete backends pass through unchanged — a request is honoured exactly or refused, never silently downgraded. AutoBackend resolves on real capability: ThreadedBackend when there is more than one thread and the OhMyThreads extension is loaded, otherwise SerialBackend.

source

Cascade internals

The cascade each gridded transform runs, and the per-surface in-place entry points.

ScatteringTransforms.Scattering1D.cascade! — Function
cascade!(S1, S2, st, signal_fft) -> (S1, S2)

Both scattering orders in one pass over the tree, grouped by first-order wavelet:

for (j1, children):  U₁ = |x ⋆ ψ_j1| ;  S1[j1] = ⟨U₁⟩
                     Û₁ = fft(U₁)     ;  S2[j1,j2] = ⟨|U₁ ⋆ ψ_j2|⟩  for each child

One U₁/Û₁ pair is live at a time, and a wavelet with no admissible child reduces to a single ⟨|·|⟩. signal_fft is read only.

source
ScatteringTransforms.Scattering2D.cascade! — Function
cascade!(S1, S2, st, image_fft) -> (S1, S2)

Both scattering orders in one grouped pass, as in the 1D cascade!. An order-2 path pairs any two orientations at strictly increasing scale.

source
ScatteringTransforms.ScatteredPlanar.ScatteredPlanarScatteringTransform — Type
ScatteredPlanarScatteringTransform

Scattering transform of a field sampled at scattered planar points, as built by scattered_planar_scattering: the samples analysed onto the ms mode grid by the spectral plan, then the cascade of the gridded Scattering2D transform on that grid, with its oriented Morlet bank.

A transform built with ntrans = B > 1 analyses B fields per call: its sample and mode buffers are (M, B) and (ms…, B), including a trailing batch axis at width 1.

source
ScatteringTransforms.ScatteredPlanar.scattered_planar_scattering_batch! — Function
scattered_planar_scattering_batch!(S0, S1, S2, st, X) -> (; S0, S1, S2[, fit])

Cascade over a stack of B fields sampled at the same points: X is (M, B), S0 is (B), S1 is (nw, B) and S2 is (nw, nw, B), (0, 0, B) without a second order. Under LeastSquares(), fit holds each field's FlowTransformBindings.SolverResult.

The analysis covers the whole stack in one execution, and each field's cascade then runs on the mode grid; st must have been built with ntrans = B.

source

Spherical scattering

A spherical plan implements three primitives — analysis, multiply-and-synthesise, and the spherical mean — and everything above them is shared. A scattered transform analyses its samples once and runs the rest of its cascade on a plan of the same kind on the Gauss–Legendre grid of its band limit. The in-core direct plan is always available; NUFSHT and FastSphericalHarmonics supply the fast ones.

ScatteringTransforms.SphericalCore.DirectSHTSphericalPlan — Type
DirectSHTSphericalPlan

The in-core scattered-sphere plan over M points at band limit lmax, transforming B co-located fields per call. Analysis is the least-squares fit of the real spherical harmonics of degree ≤ lmax by LSMR (FlowTransformBindings.lsmr!), weighted by the quadrature weights w, which sum to 1: min Σⱼ wⱼ (fⱼ − Σ a_ℓm Y_ℓm(xⱼ))². With analysis = Plans.WeightedAdjoint() it is the weighted adjoint a_ℓm = Σⱼ wⱼ fⱼ Y_ℓm(xⱼ) over harmonics of mean square 1. Synthesis is their direct sum at the points; neither forms the M × (lmax+1)² matrix of harmonics, so memory is O(M + (lmax+1)²).

source
ScatteringTransforms.SphericalCore.sphere_coeffs — Function
sphere_coeffs(plan, field) -> C

Spherical-harmonic analysis: the coefficients C of field up to the plan's band limit. For a structured grid this is the forward SHT; for scattered points it is the least-squares fit or the weighted adjoint. C is opaque and valid only with the interface functions of plan or of a plan of its kind at its band limit, such as sphere_apply!.

source
ScatteringTransforms.SphericalCore.sphere_apply! — Function
sphere_apply!(out, plan, C, h) -> out

Apply the per-degree multiplier h(ℓ) to (a copy of) the coefficients C and synthesise the result into out — i.e. out = Σ_{ℓm} h(ℓ) · C_{ℓm} · Y_{ℓm}. Does not mutate C.

source
ScatteringTransforms.SphericalCore.sphere_mean — Function
sphere_mean(plan, field) -> scalar

Spherical average of field under the plan's quadrature: for scattered points the sample mean, or the weighted mean when the plan carries weights; for a structured grid the exact quadrature integral. Provided by each backend.

source
ScatteringTransforms.SphericalCore.sphere_plan_at — Function
sphere_plan_at(plan, lmax) -> plan or nothing

A plan of the same kind at the lower band limit lmax, or nothing when this backend cannot be narrowed, in which case every band is synthesised at the full band limit. This is the spherical form of decimation: band-pass wavelet j is confined to degrees ≲ ℓ_j.

source
ScatteringTransforms.SphericalCore.sphere_restrict! — Function
sphere_restrict!(Cdst, pdst, Csrc, psrc) -> Cdst

Copy the spherical-harmonic coefficients of degree ≤ pdst's band limit out of Csrc (laid out for psrc) into Cdst (laid out for pdst), zeroing anything Cdst holds beyond them. Coefficient layout is backend-specific, so each backend defines this.

source
ScatteringTransforms.SphericalCore.grid_plan — Function
grid_plan(plan, L) -> plan or nothing

A plan of plan's kind, band limit and batch width on the Gauss–Legendre grid of band limit L ≥ lmax (gauss_legendre_grid), analysing by that grid's quadrature, or nothing for a backend with none. Its coefficients are laid out as plan's. Its analysis of a field holding degrees up to 2L + 1 − lmax is exact. A scattered transform analyses its samples with plan and runs every later step of its cascade on this one.

source
ScatteringTransforms.SphericalCore.gauss_legendre_grid — Function
gauss_legendre_grid(lmax, T) -> (θ, φ, w)

The Gauss–Legendre grid of band limit lmax, flattened with colatitude fastest: the lmax + 1 roots of P_{lmax+1}(cos θ) by 2lmax + 1 equispaced longitudes, and quadrature weights w summing to 1. The rule integrates the product of two harmonics of degree ≤ lmax exactly, so its weighted adjoint expands a degree-lmax field.

source
ScatteringTransforms.SphericalCore.band_lmax — Function
band_lmax(lmax, J, j, headroom) -> Int

Band limit that carries wavelet j: headroom · ℓ_j, clamped to lmax; headroom = Inf keeps lmax.

Band j is a difference of Gaussians whose transfer above its cutoff is exp(-ℓ(ℓ+1) / 2ℓ_j(ℓ_j+1)): 0.135 at 2ℓ_j, 0.011 at 3ℓ_j, 3.4e-4 at 4ℓ_j, the largest value a given headroom discards.

source
ScatteringTransforms.SphericalCore.band_plans — Function
band_plans(plan, lmax, ls) -> Vector or nothing

One plan per scale, scale j at band limit ls[j], or nothing if this backend cannot narrow or no band needs narrowing. A scale at the full band limit lmax reuses plan.

source
ScatteringTransforms.SphericalCore.SphericalScatteringTransform — Type
SphericalScatteringTransform

Spherical scattering transform over a backend plan::P. sigma2[k+1] is the Gaussian-transfer variance for the dyadic low-pass cutoff ℓ_k (k=0..J); band-pass wavelet j is lowpass(ℓ_{j-1}) − lowpass(ℓ_j). bands holds one narrowed plan per scale (band_plans), or nothing. grid is the plan the cascade runs on after plan analyses the field (grid_plan), or nothing for a transform whose cascade runs on plan.

source
ScatteringTransforms.SphericalCore.SphericalWorkspace — Type
SphericalWorkspace{A,C,AV,CV}

Scratch for one spherical cascade: the band-pass output band, the current first-order field u1, both on the samples the cascade runs on (the transform's grid, where it has one), and two coefficient containers, C for the input field and C1 for the first-order field being re-analysed. Two suffice, since the cascade finishes every child of a scale before starting the next. bband, bu1, bC and bC1 are the same per scale at its narrowed band limit, and empty when the transform has no bands. fits holds a batch's per-field fit outcomes, nothing for a plan whose analysis fits nothing.

Build one with SphericalWorkspace(st, field) and reuse it across calls; a task that transforms concurrently needs its own, with a task_local transform.

source
ScatteringTransforms.SphericalCore.spherical_scattering! — Function
spherical_scattering!(S1, S2, st, ws, field) -> ScatteringCoefficients1D or (; coefficients, fit)

In-place spherical scattering into pre-allocated S1/S2 using the workspace ws (see SphericalWorkspace). The returned container uses the supplied arrays; a fitting plan returns it with its fit's outcome, as the callable does.

Grouped by first-order scale so only one first-order field and one coefficient vector are live at a time: scale j1 is band-passed, averaged into S1[j1], analysed once, and then consumed by every coarser j2 > j1 before the next j1 begins.

source
ScatteringTransforms.SphericalCore.spherical_scattering_batch! — Function
spherical_scattering_batch!(S1, S2, st, ws, X) -> (; S0, S1, S2[, fit])

Cascade over a stack of B fields sampled at the same points: X is (M, B), S1 is (J, B) and S2 is (J, J, B). Every transform covers all B fields in one call; st.plan, and its grid, must have batch width B (batch_transform). A fitting plan adds fit, each field's FlowTransformBindings.SolverResult as the callable reports it, in ws's own buffer.

source
ScatteringTransforms.SphericalCore.monogenic_amplitude! — Function
monogenic_amplitude!(amp, st, C, j, w) -> amp

Spherical monogenic amplitude at scale j of the field whose (already-computed) SH coefficients are C, written into amp on the samples the cascade runs on. w holds the Riesz energy field r2 and that plan's riesz scratch.

With g_j = (−Δ_S)^{-1/2} U⁰_j the spin-1 Riesz field has |U^R_j| = |∇_S g_j|, so A_j = √(U⁰_j² + |∇_S g_j|²), the energy evaluated by sphere_riesz_energy!. The Riesz vector (orientation/phase) is spherical_monogenic_components.

source
ScatteringTransforms.SphericalCore.sph_layout_riesz_energy! — Function
sph_layout_riesz_energy!(out, plan, C, h, lmax, scratch) -> out

sphere_riesz_energy! for coefficients in the real sph_mode layout, by three scalar syntheses through sphere_apply!. With L = -i r×∇, a real g has |∇_S g|² = |L₊g|² + (∂_φ g)², and both operators act within each degree: L₊Y_{ℓm} = √((ℓ-m)(ℓ+m+1)) Y_{ℓ,m+1} on the Condon–Shortley complex harmonics, and ∂_φ maps cos(mφ) ↦ -m sin(mφ), sin(mφ) ↦ m cos(mφ). L₊g = P + iQ is synthesised as its real and imaginary parts.

source
ScatteringTransforms.SphericalCore.plan_points — Function
plan_points(plan) -> (θ, φ) or nothing

The sample locations a spherical plan was built on, from which a transform is rebuilt on another process, or nothing when the plan is defined by its band limit alone (a structured grid).

source
ScatteringTransforms.SphericalCore.plan_weights — Function
plan_weights(plan) -> weights or nothing

The quadrature weights the plan averages with, or nothing for a backend that takes the unweighted sample mean or whose quadrature follows from its grid. A plan rebuilt on the same points needs these too: the in-core structured plan's Fejér weights are not uniform.

source
ScatteringTransforms.SphericalCore.task_local_batch_plan — Function
task_local_batch_plan(plan, B) -> plan or nothing

A B-wide plan safe to apply while plan is applied in another task, owned by the caller, or nothing when the backend has no batched form.

A spherical plan's analysis solves through its own scratch, so tasks cannot share one. At plan's own width this is Plans.task_local_plan(plan), and at any other width batch_plan builds a fresh one.

source
ScatteringTransforms.SphericalCore.plan_nufft — Function
plan_nufft(plan) -> SpectralBackends.AbstractSpectralBackend

The NUFFT backend a scattered-sphere plan resolved to, or AutoSpectralBackend() for a plan that runs none. Plans.spectral_backend reports NUFSHTSpectralBackend whichever NUFFT runs underneath, so a transform rebuilt on another process needs this too to run the same one.

source
ScatteringTransforms.SphericalCore.default_rtol — Function
default_rtol(spectral) -> Real

Tolerance for the scattered-sphere analysis solve under spectral: 1e-8 for the in-core direct sum, which evaluates the harmonics exactly, and 1e-4 for NUFSHT, whose analysis is accurate only to its own approximation error.

source
ScatteringTransforms.SphericalCore.make_spherical_plan — Function
make_spherical_plan(kind, spectral, θ, φ, lmax, T; rtol, maxiter, weights, ntrans, nufft, analysis)
    -> AbstractSphericalPlan

Build the scattered-sphere plan selected by spectral over points (θ, φ) and band limit lmax. SpectralBackends.DirectSumSpectralBackend is the dependency-free default; SpectralBackends.NUFSHTSpectralBackend (or SpectralBackends.AutoSpectralBackend once the NUFSHT extension is loaded) uses the NUFSHT fast path.

ntrans = B builds a plan that transforms B co-located fields per call, and weights are the quadrature weights of the spherical mean. LeastSquares() fits coefficients and WeightedAdjoint() applies the weighted adjoint. kind = SphericalMonogenicScatteringTransform builds NUFSHT's spin pair for spherical_monogenic_components. The in-core plan takes the surface gradient of (−Δ_S)^{-1/2}U⁰ and accepts only an Auto nufft.

source
ScatteringTransforms.SphericalCore.make_structured_plan — Function
make_structured_plan(spectral, lmax, T; rtol, maxiter) -> AbstractSphericalPlan

Build the structured-sphere plan selected by spectral. SpectralBackends.DirectSumSpectralBackend is the dependency-free default (direct SHT on the grid); SpectralBackends.FSHTSpectralBackend (or SpectralBackends.AutoSpectralBackend once the FastSphericalHarmonics extension is loaded) uses the fast exact SHT.

source

Plotting

Methods are supplied by the CairoMakie extension.

ScatteringTransforms.plot_coefficients — Function
plot_coefficients(c; signal=nothing) — plot 1D scattering coefficients.
plot_coefficients(c; image=nothing) — plot 2D scattering coefficients.

Passing the input adds a panel showing it. Requires using CairoMakie.

source