Skip to content

File fft2d_core.h

FileList > fft2d > fft2d_core.h

Go to the source code of this file

Per-instance 2-D FFT using pocketfft directly. More...

  • #include "clib_common.h"
  • #include "pocketfft/pocketfft.h"

Classes

Type Name
struct fft2d_state_t

Public Functions

Type Name
fft2d_state_t * fft2d_create (size_t ny, size_t nx, int sign, int nthreads)
Allocate a reusable 2-D FFT engine for a fixed ny×nx grid. Two pocketfft 2-D plans are built at construction time — one CF64, one CF32. All execute calls accept and return flat row-major arrays of length ny*nx; the Python layer may reshape them with .reshape(ny, nx). nthreads is accepted for API parity but ignored.
void fft2d_destroy (fft2d_state_t * state)
Destroy and free an fft2d instance.
size_t fft2d_execute_cf32 (fft2d_state_t * state, const float complex * in, size_t n_in, float complex * out)
Compute an out-of-place 2-D DFT on a single-precision complex grid. Single-precision variant of fft2d_execute_cf64() . Accepts and returns flat row-major CF32 arrays of length ny*nx. Output is unnormalised;in andout must not alias.
size_t fft2d_execute_cf32_max_out (fft2d_state_t * state)
Maximum output samples for CF32 execute (ny * nx).
size_t fft2d_execute_cf64 (fft2d_state_t * state, const double complex * in, size_t n_in, double complex * out)
Compute an out-of-place 2-D DFT on a double-precision complex grid. in is a flat row-major CF64 array of length ny*nx. The output is written to the caller-suppliedout buffer (also ny*nx); the two must not alias. The transform is unnormalised.
size_t fft2d_execute_cf64_max_out (fft2d_state_t * state)
Maximum output samples per execute call (ny * nx).
size_t fft2d_execute_inplace_cf32 (fft2d_state_t * state, const float complex * in, size_t n_in, float complex * out)
Copy in intoout , then transformout in-place (CF32 2-D). Single-precision variant offft2d_execute_inplace_cf64() . Copies ny*nx CF32 samples then applies the CF32 2-D pocketfft plan toout .
size_t fft2d_execute_inplace_cf32_max_out (fft2d_state_t * state)
Maximum output samples for inplace CF32 execute (ny * nx).
size_t fft2d_execute_inplace_cf64 (fft2d_state_t * state, const double complex * in, size_t n_in, double complex * out)
Copy in intoout , then transformout in-place (CF64 2-D). The ny*nx CF64 samples fromin are first memcpy'd toout ; the 2-D DFT is then applied toout in-place.in is left unmodified. Useful when the caller ownsout and wants to preservein .
size_t fft2d_execute_inplace_cf64_max_out (fft2d_state_t * state)
Maximum output samples for inplace CF64 execute (ny * nx).
void fft2d_reset (fft2d_state_t * state)
No-op reset (plans are immutable after creation).

Detailed Description

Holds two pocketfft plans — one CF64, one CF32 — for an ny × nx row-major transform. Input and output arrays are flat buffers of length ny*nx; the Python wrapper class reshapes them. nthreads is accepted for API compatibility but ignored.

Lifecycle:

fft2d_state_t *fft = fft2d_create(64, 64, -1, 1);
double complex out[64 * 64];
fft2d_execute_cf64(fft, in, 64 * 64, out);
fft2d_destroy(fft);

Public Functions Documentation

function fft2d_create

Allocate a reusable 2-D FFT engine for a fixed ny×nx grid. Two pocketfft 2-D plans are built at construction time — one CF64, one CF32. All execute calls accept and return flat row-major arrays of length ny*nx; the Python layer may reshape them with .reshape(ny, nx). nthreads is accepted for API parity but ignored.

fft2d_state_t * fft2d_create (
    size_t ny,
    size_t nx,
    int sign,
    int nthreads
) 

Parameters:

  • ny Number of rows (outer dimension).
  • nx Number of columns (inner dimension).
  • sign -1 for the forward DFT, +1 for the inverse DFT.
  • nthreads Accepted for API compatibility; ignored.

Returns:

Heap-allocated state, or NULL on failure.

>>> from doppler.spectral import FFT2D
>>> import numpy as np
>>> fft2d = FFT2D(ny=4, nx=4, sign=-1, nthreads=1)
>>> fft2d.ny, fft2d.nx, fft2d.sign
(4, 4, -1)
>>> x = np.zeros(16, dtype=np.complex64); x[0] = 1.0
>>> out = fft2d.execute_cf32(x)
>>> out.shape, out.dtype
((16,), dtype('complex64'))
>>> bool(np.allclose(out, 1.0))
True


function fft2d_destroy

Destroy and free an fft2d instance.

void fft2d_destroy (
    fft2d_state_t * state
) 

Parameters:

  • state May be NULL.

function fft2d_execute_cf32

Compute an out-of-place 2-D DFT on a single-precision complex grid. Single-precision variant of fft2d_execute_cf64() . Accepts and returns flat row-major CF32 arrays of length ny*nx. Output is unnormalised;in andout must not alias.

size_t fft2d_execute_cf32 (
    fft2d_state_t * state,
    const float complex * in,
    size_t n_in,
    float complex * out
) 

Parameters:

  • state Allocated FFT2D engine (non-NULL).
  • in Flat row-major CF32 input, length ny*nx.
  • n_in Number of input samples; must equal ny*nx.
  • out Flat row-major CF32 output, length >= ny*nx (caller-allocated).

Returns:

ny*nx (number of samples written).

>>> from doppler.spectral import FFT2D
>>> import numpy as np
>>> fft2d = FFT2D(ny=4, nx=4, sign=-1)
>>> x = np.zeros(16, dtype=np.complex64); x[0] = 1.0
>>> out = fft2d.execute_cf32(x)
>>> out.shape, out.dtype
((16,), dtype('complex64'))
>>> bool(np.allclose(out, 1.0))
True


function fft2d_execute_cf32_max_out

Maximum output samples for CF32 execute (ny * nx).

size_t fft2d_execute_cf32_max_out (
    fft2d_state_t * state
) 


function fft2d_execute_cf64

Compute an out-of-place 2-D DFT on a double-precision complex grid. in is a flat row-major CF64 array of length ny*nx. The output is written to the caller-suppliedout buffer (also ny*nx); the two must not alias. The transform is unnormalised.

size_t fft2d_execute_cf64 (
    fft2d_state_t * state,
    const double complex * in,
    size_t n_in,
    double complex * out
) 

Parameters:

  • state Allocated FFT2D engine (non-NULL).
  • in Flat row-major CF64 input, length ny*nx.
  • n_in Number of input samples; must equal ny*nx.
  • out Flat row-major CF64 output, length >= ny*nx (caller-allocated).

Returns:

ny*nx (number of samples written).

>>> from doppler.spectral import FFT2D
>>> import numpy as np
>>> fft2d = FFT2D(ny=4, nx=4, sign=-1)
>>> x = np.zeros(16, dtype=np.complex128); x[0] = 1.0
>>> out = fft2d.execute_cf64(x)
>>> out.shape, out.dtype
((16,), dtype('complex128'))
>>> bool(np.allclose(out, 1.0))
True


function fft2d_execute_cf64_max_out

Maximum output samples per execute call (ny * nx).

size_t fft2d_execute_cf64_max_out (
    fft2d_state_t * state
) 


function fft2d_execute_inplace_cf32

Copy in intoout , then transformout in-place (CF32 2-D). Single-precision variant offft2d_execute_inplace_cf64() . Copies ny*nx CF32 samples then applies the CF32 2-D pocketfft plan toout .

size_t fft2d_execute_inplace_cf32 (
    fft2d_state_t * state,
    const float complex * in,
    size_t n_in,
    float complex * out
) 

Parameters:

  • state Allocated FFT2D engine (non-NULL).
  • in Source, ny*nx CF32 flat row-major; not modified.
  • n_in Number of input samples; must equal ny*nx.
  • out Destination, length >= ny*nx; must not alias in.

Returns:

ny*nx (number of samples written).

>>> from doppler.spectral import FFT2D
>>> import numpy as np
>>> fft2d = FFT2D(ny=4, nx=4, sign=-1)
>>> x = np.zeros(16, dtype=np.complex64); x[0] = 1.0
>>> out = fft2d.execute_inplace_cf32(x)
>>> bool(np.allclose(out, 1.0))
True


function fft2d_execute_inplace_cf32_max_out

Maximum output samples for inplace CF32 execute (ny * nx).

size_t fft2d_execute_inplace_cf32_max_out (
    fft2d_state_t * state
) 


function fft2d_execute_inplace_cf64

Copy in intoout , then transformout in-place (CF64 2-D). The ny*nx CF64 samples fromin are first memcpy'd toout ; the 2-D DFT is then applied toout in-place.in is left unmodified. Useful when the caller ownsout and wants to preservein .

size_t fft2d_execute_inplace_cf64 (
    fft2d_state_t * state,
    const double complex * in,
    size_t n_in,
    double complex * out
) 

Parameters:

  • state Allocated FFT2D engine (non-NULL).
  • in Source, ny*nx CF64 flat row-major; not modified.
  • n_in Number of input samples; must equal ny*nx.
  • out Destination, length >= ny*nx; must not alias in.

Returns:

ny*nx (number of samples written).

>>> from doppler.spectral import FFT2D
>>> import numpy as np
>>> fft2d = FFT2D(ny=4, nx=4, sign=-1)
>>> x = np.zeros(16, dtype=np.complex128); x[0] = 1.0
>>> out = fft2d.execute_inplace_cf64(x)
>>> bool(np.allclose(out, 1.0))
True


function fft2d_execute_inplace_cf64_max_out

Maximum output samples for inplace CF64 execute (ny * nx).

size_t fft2d_execute_inplace_cf64_max_out (
    fft2d_state_t * state
) 


function fft2d_reset

No-op reset (plans are immutable after creation).

void fft2d_reset (
    fft2d_state_t * state
) 



The documentation for this class was generated from the following file native/inc/fft2d/fft2d_core.h