FastTransforms.jl

repository·master·Indexed 42 days ago

https://github.com/juliaapproximation/fasttransforms.jl

A Julia wrapper for a C library providing high-performance transforms for extremely high-degree polynomials. It includes support for orthogonal polynomials (Chebyshev, Legendre), spherical harmonics, Nonuniform Fast Fourier Transforms (NUFFT), and the Padua transform. The package provides tools for computing Chebyshev and Jacobi moments, as well as generating Clenshaw-Curtis and Fejér nodes and weights.

Tokens
2.1K
Snippets
7
Records
13
Agent score
53%

What's inside FastTransforms.jl

  1. Introduction to FastTransforms.jl

    master

    FastTransforms.jl is a Julia wrapper for the FastTransforms C library. It is designed to allow users to work with orthogonal polynomials of very high degrees (into the millions).

    Key capabilities include:

    • Fast orthogonal polynomial transforms.
    • Nonuniform Fast Fourier Transforms (NUFFT) of three different types.
    • The Padua Transform.
    • Specialized quadrature and special functions.
  2. Use Fast orthogonal polynomial transforms

    master

    FastTransforms provides transforms for orthogonal polynomials (e.g., Chebyshev, Legendre) with degrees reaching into the millions.

    Available transforms can be found in FastTransforms.Transforms or by inspecting FastTransforms.kind2string.(instances(FastTransforms.Transforms)).

    For univariate transforms, you can use standard normalization or orthonormalization. For multivariate transforms, standard normalization is omitted to avoid floating-point issues.

  3. How FastTransforms.jl core types work

    master

    The Julia API unifies orthogonal polynomial transforms as linear operators using parametric composite types. The core types are FTPlan{T, N, K}, AdjointFTPlan, and TransposeFTPlan.

    • T: The element type of the plan (e.g., Float64).
    • N: The number of leading dimensions of the array on which the plan operates. For example, N=1 allows the plan to operate on vectors or matrices (column-by-column).
    • K: An enumeration used to distinguish the specific orthogonal polynomials being used.

    Example: FTPlan{Float64, 1, LEG2CHEB} represents the pre-computations required to convert 64-bit Legendre series to Chebyshev series (of the first kind).

  4. Build the C library from source

    master

    To accelerate development by coupling Julia with the underlying C library source code, you can trigger a build from source by setting the FT_BUILD_FROM_SOURCE environment variable to "true" before building the package.

    This allows you to experiment with new features by ccalling into the bleeding-edge C source code.

    # Set the environment variable to trigger the build script
    ENV["FT_BUILD_FROM_SOURCE"] = "true"
    
    # In the Julia package manager, build the package
    (@v1.5) pkg> build FastTransforms
  5. Calculate the 256-bit SHA for a C library release

    master

    When releasing a new version, you must provide the 256-bit SHA for the C library tarball. You can calculate this using the command line or within Julia using the SHA.jl package.

    # Using the command line
    curl https://codeload.github.com/MikaelSlevinsky/FastTransforms/tar.gz/v0.6.2 --output FastTransforms.tar.gz
    shasum -a 256 FastTransforms.tar.gz
    rm -f FastTransforms.tar.gz
    # Using SHA.jl in Julia
    using SHA
    
    open("FastTransforms.tar.gz") do f
        bytes2hex(sha256(f))
    end
  6. Perform spherical harmonic transforms

    master

    Spherical harmonic transforms allow conversion between spherical harmonic expansion coefficients and bivariate Fourier series, or between coefficients and function samples on an equiangular grid.

    • sph2fourier: Converts spherical harmonic coefficients to a bivariate Fourier series.
    • fourier2sph: Converts a bivariate Fourier series back to spherical harmonic coefficients.
    • plan_sph_synthesis: Converts coefficients to function samples on an equiangular grid (does not sample poles).
    • plan_sph_analysis: Converts function samples back to coefficients.

    These transforms can be performed in-place using lmul! and ldiv!.

    # F: array of coefficients (columns by increasing absolute order, alternating +/-)
    F = sphrandn(Float64, 1024, 2047);
    
    P = plan_sph2fourier(F);
    PS = plan_sph_synthesis(F);
    PA = plan_sph_analysis(F);
    
    # Synthesis/Analysis workflow
    G = PS * (P * F);
    H = P \ (PA * G);
  7. Use Nonuniform Fast Fourier Transforms (NUFFT)

    master

    The package implements several types of Nonuniform Fast Fourier Transforms (NUFFT):

    • nufft1: Uniform samples and noninteger frequencies.
    • nufft2: Nonuniform samples and integer frequencies.
    • nufft3 (or nufft): Nonuniform samples and noninteger frequencies.
    • inufft1: Inverse of nufft1.
    • inufft2: Inverse of nufft2.

    For performance, use the plan_* versions of these functions to pre-compute the transform plan.

    n = 10^4;
    c = complex(rand(n));
    ω = collect(0:n-1) + rand(n); # noninteger frequencies
    x = (collect(0:n-1) + 3rand(n))/n; # nonuniform samples
    
    # NUFFT1: Uniform samples, noninteger frequencies
    p1 = plan_nufft1(ω, eps());
    result1 = p1 * c;
    
    # NUFFT2: Nonuniform samples, integer frequencies
    p2 = plan_nufft2(x, eps());
    result2 = p2 * c;
    
    # NUFFT3: Nonuniform samples, noninteger frequencies
    p3 = plan_nufft3(x, ω, eps());
    result3 = p3 * c;
  8. Use the Padua Transform

    master

    The Padua transform is used for computing bivariate Chebyshev coefficients by interpolating a bivariate function at the Padua points on [-1,1]^2.

    • paduatransform(v): Computes the transform.
    • ipaduatransform(v): Computes the inverse transform.
    n = 200;
    N = div((n+1)*(n+2), 2);
    v = rand(N); # Length is the number of Padua points
    
    # Transform and inverse
    result = ipaduatransform(paduatransform(v))
  9. Compute Chebyshev and Jacobi Moments

    master

    The package includes methods for computing various moments used in quadrature and polynomial analysis, specifically for Chebyshev and Jacobi polynomials.

    Chebyshev Moments:

    • chebyshevmoments1
    • chebyshevmoments2
    • chebyshevlogmoments1
    • chebyshevlogmoments2

    Jacobi Moments:

    • chebyshevjacobimoments1
    • chebyshevjacobimoments2