File fft2d_core.h¶
FileList > doppler > fft2d > fft2d_core.h
Go to the source code of this file
Per-instance 2-D FFT using pocketfft directly. More...
#include "doppler/clib_common.h"#include "doppler/pocketfft/pocketfft.h"
Classes¶
| Type | Name |
|---|---|
| struct | dp_fft2d_state_t |
Public Functions¶
| Type | Name |
|---|---|
| dp_fft2d_state_t * | dp_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 | dp_fft2d_destroy (dp_fft2d_state_t * state) Destroy and free an fft2d instance. |
| size_t | dp_fft2d_execute_cf32 (dp_fft2d_state_t * state, const float _Complex * in, size_t n_in, float _Complex * out, size_t max_out) Compute an out-of-place 2-D DFT on a single-precision complex grid. Single-precision variant of dp_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 | dp_fft2d_execute_cf32_max_out (dp_fft2d_state_t * state) Maximum output samples for CF32 execute (ny * nx). |
| size_t | dp_fft2d_execute_cf64 (dp_fft2d_state_t * state, const double _Complex * in, size_t n_in, double _Complex * out, size_t max_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 | dp_fft2d_execute_cf64_max_out (dp_fft2d_state_t * state) Maximum output samples per execute call (ny * nx). |
| size_t | dp_fft2d_execute_inplace_cf32 (dp_fft2d_state_t * state, const float _Complex * in, size_t n_in, float _Complex * out, size_t max_out) Copy in intoout , then transformout in-place (CF32 2-D). Single-precision variant ofdp_fft2d_execute_inplace_cf64() . Copies ny*nx CF32 samples then applies the CF32 2-D pocketfft plan toout . |
| size_t | dp_fft2d_execute_inplace_cf32_max_out (dp_fft2d_state_t * state) Maximum output samples for inplace CF32 execute (ny * nx). |
| size_t | dp_fft2d_execute_inplace_cf64 (dp_fft2d_state_t * state, const double _Complex * in, size_t n_in, double _Complex * out, size_t max_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 | dp_fft2d_execute_inplace_cf64_max_out (dp_fft2d_state_t * state) Maximum output samples for inplace CF64 execute (ny * nx). |
| void | dp_fft2d_reset (dp_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:
dp_fft2d_state_t *fft = dp_fft2d_create(64, 64, -1, 1);
double _Complex out[64 * 64];
dp_fft2d_execute_cf64(fft, in, 64 * 64, out, 64 * 64);
dp_fft2d_destroy(fft);
Public Functions Documentation¶
function dp_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.
Parameters:
nyNumber of rows (outer dimension).nxNumber of columns (inner dimension).sign-1 for the forward DFT, +1 for the inverse DFT.nthreadsAccepted 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 dp_fft2d_destroy¶
Destroy and free an fft2d instance.
Parameters:
stateMay be NULL.
function dp_fft2d_execute_cf32¶
Compute an out-of-place 2-D DFT on a single-precision complex grid. Single-precision variant of dp_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 dp_fft2d_execute_cf32 (
dp_fft2d_state_t * state,
const float _Complex * in,
size_t n_in,
float _Complex * out,
size_t max_out
)
Parameters:
stateAllocated FFT2D engine (non-NULL).inFlat row-major CF32 input, length ny*nx.n_inNumber of input samples; must equal ny*nx; else REFUSED.outFlat row-major CF32 output, length >= ny*nx (caller-allocated).max_outCapacity ofoutin samples. Normally ny*nx; if it is smaller the first max_out samples of the transform are written and the rest is discarded.
Returns:
min(ny*nx, max_out) samples. If n_in is not the required length the call is REFUSED with nothing read, written or counted: SIZE_MAX in C, ValueError in Python (#1925).
>>> 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 dp_fft2d_execute_cf32_max_out¶
Maximum output samples for CF32 execute (ny * nx).
function dp_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 dp_fft2d_execute_cf64 (
dp_fft2d_state_t * state,
const double _Complex * in,
size_t n_in,
double _Complex * out,
size_t max_out
)
Parameters:
stateAllocated FFT2D engine (non-NULL).inFlat row-major CF64 input, length ny*nx.n_inNumber of input samples; must equal ny*nx; else REFUSED.outFlat row-major CF64 output, length >= ny*nx (caller-allocated).max_outCapacity ofoutin samples. Normally ny*nx; if it is smaller the first max_out samples of the transform are written and the rest is discarded.
Returns:
min(ny*nx, max_out) samples. If n_in is not the required length the call is REFUSED with nothing read, written or counted: SIZE_MAX in C, ValueError in Python (#1925).
>>> 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 dp_fft2d_execute_cf64_max_out¶
Maximum output samples per execute call (ny * nx).
function dp_fft2d_execute_inplace_cf32¶
Copy in intoout , then transformout in-place (CF32 2-D). Single-precision variant ofdp_fft2d_execute_inplace_cf64() . Copies ny*nx CF32 samples then applies the CF32 2-D pocketfft plan toout .
size_t dp_fft2d_execute_inplace_cf32 (
dp_fft2d_state_t * state,
const float _Complex * in,
size_t n_in,
float _Complex * out,
size_t max_out
)
Parameters:
stateAllocated FFT2D engine (non-NULL).inSource, ny*nx CF32 flat row-major; not modified.n_inNumber of input samples; must equal ny*nx; else REFUSED.outDestination, length >= ny*nx; must not alias in.max_outCapacity ofoutin samples. Normally ny*nx; if it is smaller the copy-and-transform happens in scratch and only the first max_out samples reachout.
Returns:
min(ny*nx, max_out) samples. If n_in is not the required length the call is REFUSED with nothing read, written or counted: SIZE_MAX in C, ValueError in Python (#1925).
>>> 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 dp_fft2d_execute_inplace_cf32_max_out¶
Maximum output samples for inplace CF32 execute (ny * nx).
function dp_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 dp_fft2d_execute_inplace_cf64 (
dp_fft2d_state_t * state,
const double _Complex * in,
size_t n_in,
double _Complex * out,
size_t max_out
)
Parameters:
stateAllocated FFT2D engine (non-NULL).inSource, ny*nx CF64 flat row-major; not modified.n_inNumber of input samples; must equal ny*nx; else REFUSED.outDestination, length >= ny*nx; must not alias in.max_outCapacity ofoutin samples. Normally ny*nx; if it is smaller the copy-and-transform happens in scratch and only the first max_out samples reachout.
Returns:
min(ny*nx, max_out) samples. If n_in is not the required length the call is REFUSED with nothing read, written or counted: SIZE_MAX in C, ValueError in Python (#1925).
>>> 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 dp_fft2d_execute_inplace_cf64_max_out¶
Maximum output samples for inplace CF64 execute (ny * nx).
function dp_fft2d_reset¶
No-op reset (plans are immutable after creation).
The documentation for this class was generated from the following file native/inc/doppler/fft2d/fft2d_core.h