GammaLib 2.0.0
Loading...
Searching...
No Matches
GFft Class Reference

Fast Fourier Transformation class. More...

#include <GFft.hpp>

Inheritance diagram for GFft:
GBase

Public Member Functions

 GFft (void)
 Void constructor.
 
 GFft (const GNdarray &array)
 N-dimensional array constructor.
 
 GFft (const GFft &fft)
 Copy constructor.
 
virtual ~GFft (void)
 Destructor.
 
std::complex< double > & operator() (const int &ix)
 1-dimensional FFT element access operator
 
std::complex< double > & operator() (const int &ix, const int &iy)
 2-dimensional FFT element access operator
 
const std::complex< double > & operator() (const int &ix) const
 1-dimensional FFT element access operator (const variant)
 
const std::complex< double > & operator() (const int &ix, const int &iy) const
 2-dimensional FFT element access operator (const variant)
 
GFftoperator= (const GFft &fft)
 Assignment operator.
 
GFftoperator+= (const GFft &fft)
 Unary addition operator.
 
GFftoperator-= (const GFft &fft)
 Unary subtraction operator.
 
GFftoperator*= (const GFft &fft)
 Unary multiplication operator.
 
GFftoperator/= (const GFft &fft)
 Unary division operator.
 
GFft operator- (void) const
 Unary minus operator.
 
void clear (void)
 Clear Fast Fourier Transform.
 
GFftclone (void) const
 Clone Fast Fourier Transform.
 
std::string classname (void) const
 Return class name.
 
int dim (void) const
 Return dimension of Fast Fourier Transformation.
 
int size (void) const
 Return number of elements in array.
 
const std::vector< int > & shape (void) const
 Return shape of array.
 
const std::vector< int > & strides (void) const
 Return strides of array.
 
void forward (const GNdarray &array)
 Forward Fast Fourier Transform.
 
GNdarray backward (void) const
 Backward Fast Fourier Transform.
 
std::string print (const GChatter &chatter=NORMAL) const
 Print Fast Fourier Transform information.
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor.
 

Protected Member Functions

void init_members (void)
 Initialise class members.
 
void copy_members (const GFft &fft)
 Copy class members.
 
void free_members (void)
 Delete class members.
 
void set_data (const GNdarray &array)
 Set data from n-dimensional array.
 
bool has_same_shape (const GFft &fft) const
 Check if FFT has the same shape.
 
void require_same_shape (const std::string &method, const GFft &fft) const
 Throw exception if FFT shapes differ.
 
void transform (std::complex< double > *data, const int &stride, const int &n, const GFftWavetable &wavetable, const bool &forward=true)
 Perform Fast Fourier Transform.
 
void factor2 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index)
 Compute FFT for factor 2.
 
void factor3 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index)
 Compute FFT for factor 3.
 
void factor4 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index)
 Compute FFT for factor 4.
 
void factor5 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index)
 Compute FFT for factor 5.
 
void factor6 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index)
 Compute FFT for factor 6.
 
void factor7 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index)
 Compute FFT for factor 7.
 
void factorn (std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &factor, const int &product, const int &n, const int &index)
 Compute FFT for arbitrary factor.
 
std::vector< std::complex< double > > get_w (const GFftWavetable &wavetable, const int &index, const int &k, const int &q, const int &n, const int &sign) const
 Extract coefficients from wavetable.
 
std::complex< double > timesi (const std::complex< double > &value) const
 Return complex value times i.
 

Protected Attributes

int m_size
 Size of data array.
 
std::complex< double > * m_data
 Pointer on array data.
 
std::vector< int > m_shape
 Array dimensions.
 
std::vector< int > m_strides
 Steps in each dimension.
 
std::vector< GFftWavetablem_wavetable
 Trigonometric coefficients.
 

Detailed Description

Fast Fourier Transformation class.

This class implements a Fast Fourier Transformation of an n-dimensional double precision floating point array.

The class implementation is based on the Fast Fourier Transformation functions that are provided by the GNU Scientific Library (GSL) (version 2.2.1). The mixed-radix routines for complex numbers have been adopted that work for any array lengths. The mixed-radix routines are a reimplementation of the FFTPACK library of Paul Swarztrauber.

The GSL is documented at https://www.gnu.org/software/gsl/manual

Definition at line 57 of file GFft.hpp.

Constructor & Destructor Documentation

◆ GFft() [1/3]

GFft::GFft ( void )

Void constructor.

Definition at line 55 of file GFft.cpp.

References init_members().

Referenced by clone().

◆ GFft() [2/3]

GFft::GFft ( const GNdarray & array)
explicit

N-dimensional array constructor.

Parameters
[in]arrayN-dimensional array.

Constructs a Fast Fourier Transformation from a n-dimensional array.

Definition at line 72 of file GFft.cpp.

References forward(), and init_members().

◆ GFft() [3/3]

GFft::GFft ( const GFft & fft)

Copy constructor.

Parameters
[in]fftFast Fourier Transform.

Definition at line 90 of file GFft.cpp.

References copy_members(), and init_members().

◆ ~GFft()

GFft::~GFft ( void )
virtual

Destructor.

Definition at line 106 of file GFft.cpp.

References free_members().

Member Function Documentation

◆ backward()

GNdarray GFft::backward ( void ) const

Backward Fast Fourier Transform.

Returns
N-dimensional array.

GException::feature_not_implemented Array dimension is not supported.

Performs the inverse (or backward) discret Fast Fourier forward transformation for 1- and 2-dimensional arrays.

For one dimensional arrays of length \(N\) the transformation is given by

\[ z_k = \frac{1}{N} \sum_{n=0}^{N-1} X_n e^{i 2 \pi \frac{k n}{N}} \]

and for two dimensional arrays of length \( M \times N\) the transformation is given by

\[ z_{k,l} = \frac{1}{N} \sum_{n=0}^{N-1} \left( \frac{1}{M} \sum_{m=0}^{M-1} X_{m,n} e^{i 2 \pi \frac{m k}{M}} \right) e^{i 2 \pi \frac{n l}{N}} \]

Definition at line 401 of file GFft.cpp.

References GNdarray::dim(), G_BACKWARD, m_data, m_shape, m_size, m_strides, m_wavetable, norm(), shape(), gammalib::str(), and transform().

Referenced by GSkyMap::convolve().

◆ classname()

std::string GFft::classname ( void ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GFft").

Implements GBase.

Definition at line 194 of file GFft.hpp.

◆ clear()

void GFft::clear ( void )
virtual

Clear Fast Fourier Transform.

Implements GBase.

Definition at line 276 of file GFft.cpp.

References free_members(), and init_members().

◆ clone()

GFft * GFft::clone ( void ) const
virtual

Clone Fast Fourier Transform.

Returns
Pointer to deep copy of Fast Fourier Transform.

Implements GBase.

Definition at line 294 of file GFft.cpp.

References GFft().

◆ copy_members()

void GFft::copy_members ( const GFft & fft)
protected

Copy class members.

Parameters
[in]fftFast Fourier Transform.

Definition at line 558 of file GFft.cpp.

References m_data, m_shape, m_size, m_strides, and m_wavetable.

Referenced by GFft(), and operator=().

◆ dim()

int GFft::dim ( void ) const
inline

Return dimension of Fast Fourier Transformation.

Returns
Dimension of Fast Fourier Transformation.

Returns the dimension of the Fast Fourier Transformation.

Definition at line 268 of file GFft.hpp.

References m_shape.

Referenced by print().

◆ factor2()

void GFft::factor2 ( const std::complex< double > * in,
const int & istride,
std::complex< double > * out,
const int & ostride,
const GFftWavetable & wavetable,
const int & sign,
const int & product,
const int & n,
const int & index )
protected

Compute FFT for factor 2.

Parameters
[in]inPointer to input array.
[in]istrideStep size when traversing input array.
[in]outPointer to output array.
[in]ostrideStep size when traversing output array.
[in]wavetableTrigonometric coefficients.
[in]signForward (-1) or backward (+1).
[in]product...
[in]nLogical array length.
[in]indexStart index of trigonometric coefficients.

Definition at line 825 of file GFft.cpp.

References get_w(), and sign().

Referenced by transform().

◆ factor3()

void GFft::factor3 ( const std::complex< double > * in,
const int & istride,
std::complex< double > * out,
const int & ostride,
const GFftWavetable & wavetable,
const int & sign,
const int & product,
const int & n,
const int & index )
protected

Compute FFT for factor 3.

Parameters
[in]inPointer to input array.
[in]istrideStep size when traversing input array.
[in]outPointer to output array.
[in]ostrideStep size when traversing output array.
[in]wavetableTrigonometric coefficients.
[in]signForward (-1) or backward (+1).
[in]product...
[in]nLogical array length.
[in]indexStart index of trigonometric coefficients.

Definition at line 885 of file GFft.cpp.

References get_w(), sign(), and timesi().

Referenced by transform().

◆ factor4()

void GFft::factor4 ( const std::complex< double > * in,
const int & istride,
std::complex< double > * out,
const int & ostride,
const GFftWavetable & wavetable,
const int & sign,
const int & product,
const int & n,
const int & index )
protected

Compute FFT for factor 4.

Parameters
[in]inPointer to input array.
[in]istrideStep size when traversing input array.
[in]outPointer to output array.
[in]ostrideStep size when traversing output array.
[in]wavetableTrigonometric coefficients.
[in]signForward (-1) or backward (+1).
[in]product...
[in]nLogical array length.
[in]indexStart index of trigonometric coefficients.

Definition at line 957 of file GFft.cpp.

References get_w(), sign(), and timesi().

Referenced by transform().

◆ factor5()

void GFft::factor5 ( const std::complex< double > * in,
const int & istride,
std::complex< double > * out,
const int & ostride,
const GFftWavetable & wavetable,
const int & sign,
const int & product,
const int & n,
const int & index )
protected

Compute FFT for factor 5.

Parameters
[in]inPointer to input array.
[in]istrideStep size when traversing input array.
[in]outPointer to output array.
[in]ostrideStep size when traversing output array.
[in]wavetableTrigonometric coefficients.
[in]signForward (-1) or backward (+1).
[in]product...
[in]nLogical array length.
[in]indexStart index of trigonometric coefficients.

Definition at line 1029 of file GFft.cpp.

References get_w(), sign(), timesi(), and gammalib::twopi.

Referenced by transform().

◆ factor6()

void GFft::factor6 ( const std::complex< double > * in,
const int & istride,
std::complex< double > * out,
const int & ostride,
const GFftWavetable & wavetable,
const int & sign,
const int & product,
const int & n,
const int & index )
protected

Compute FFT for factor 6.

Parameters
[in]inPointer to input array.
[in]istrideStep size when traversing input array.
[in]outPointer to output array.
[in]ostrideStep size when traversing output array.
[in]wavetableTrigonometric coefficients.
[in]signForward (-1) or backward (+1).
[in]product...
[in]nLogical array length.
[in]indexStart index of trigonometric coefficients.

Definition at line 1118 of file GFft.cpp.

References get_w(), sign(), and timesi().

Referenced by transform().

◆ factor7()

void GFft::factor7 ( const std::complex< double > * in,
const int & istride,
std::complex< double > * out,
const int & ostride,
const GFftWavetable & wavetable,
const int & sign,
const int & product,
const int & n,
const int & index )
protected

Compute FFT for factor 7.

Parameters
[in]inPointer to input array.
[in]istrideStep size when traversing input array.
[in]outPointer to output array.
[in]ostrideStep size when traversing output array.
[in]wavetableTrigonometric coefficients.
[in]signForward (-1) or backward (+1).
[in]product...
[in]nLogical array length.
[in]indexStart index of trigonometric coefficients.

Definition at line 1214 of file GFft.cpp.

References get_w(), sign(), timesi(), and gammalib::twopi.

Referenced by transform().

◆ factorn()

void GFft::factorn ( std::complex< double > * in,
const int & istride,
std::complex< double > * out,
const int & ostride,
const GFftWavetable & wavetable,
const int & sign,
const int & factor,
const int & product,
const int & n,
const int & index )
protected

Compute FFT for arbitrary factor.

Parameters
[in]inPointer to input array.
[in]istrideStep size when traversing input array.
[in]outPointer to output array.
[in]ostrideStep size when traversing output array.
[in]wavetableTrigonometric coefficients.
[in]signForward (-1) or backward (+1).
[in]factorFactor.
[in]product...
[in]nLogical array length.
[in]indexStart index of trigonometric coefficients.

Definition at line 1343 of file GFft.cpp.

References sign().

Referenced by transform().

◆ forward()

void GFft::forward ( const GNdarray & array)

Forward Fast Fourier Transform.

Parameters
[in]arrayN-dimensional array.

GException::feature_not_implemented Array dimension is not supported.

Performs discret Fast Fourier forward transformation for 1- and 2-dimensional arrays.

For one dimensional arrays of length \(N\) the transformation is given by

\[ X_k = \sum_{n=0}^{N-1} z_n e^{-i 2 \pi \frac{k n}{N}} \]

and for two dimensional arrays of length \( M \times N\) the transformation is given by

\[ X_{k,l} = \sum_{n=0}^{N-1} \left( \sum_{m=0}^{M-1} z_{m,n} e^{-i 2 \pi \frac{m k}{M}} \right) e^{-i 2 \pi \frac{n l}{N}} \]

Definition at line 328 of file GFft.cpp.

References GNdarray::dim(), G_FORWARD, m_data, m_shape, m_size, m_strides, m_wavetable, set_data(), gammalib::str(), and transform().

Referenced by GFft(), and transform().

◆ free_members()

void GFft::free_members ( void )
protected

Delete class members.

Definition at line 582 of file GFft.cpp.

References m_data, and m_size.

Referenced by clear(), operator=(), set_data(), and ~GFft().

◆ get_w()

std::vector< std::complex< double > > GFft::get_w ( const GFftWavetable & wavetable,
const int & index,
const int & k,
const int & q,
const int & n,
const int & sign ) const
protected

Extract coefficients from wavetable.

Parameters
[in]indexStart index of trigonometric coefficients.
[in]k...
[in]q...
[in]nNumber of coefficients.
[in]signForward (-1) or backward (+1) transformation.
[in]wavetableTrigonometric coefficients.

Definition at line 1535 of file GFft.cpp.

References sign().

Referenced by factor2(), factor3(), factor4(), factor5(), factor6(), and factor7().

◆ has_same_shape()

bool GFft::has_same_shape ( const GFft & fft) const
protected

Check if FFT has the same shape.

Parameters
[in]fftFast Fourier Transform.
Returns
True if the FFT has the same shape.

Definition at line 646 of file GFft.cpp.

References m_shape.

Referenced by require_same_shape().

◆ init_members()

void GFft::init_members ( void )
protected

Initialise class members.

Definition at line 539 of file GFft.cpp.

References m_data, m_shape, m_size, m_strides, and m_wavetable.

Referenced by clear(), GFft(), GFft(), GFft(), operator=(), and set_data().

◆ operator()() [1/4]

std::complex< double > & GFft::operator() ( const int & ix)
inline

1-dimensional FFT element access operator

Parameters
[in]ixElement index [0,...,shape(0)-1].
Returns
Reference to FFT element.

Definition at line 207 of file GFft.hpp.

References m_data.

◆ operator()() [2/4]

const std::complex< double > & GFft::operator() ( const int & ix) const
inline

1-dimensional FFT element access operator (const variant)

Parameters
[in]ixElement index [0,...,shape(0)-1].
Returns
Const reference to FFT element.

Definition at line 236 of file GFft.hpp.

References m_data.

◆ operator()() [3/4]

std::complex< double > & GFft::operator() ( const int & ix,
const int & iy )
inline

2-dimensional FFT element access operator

Parameters
[in]ixIndex in first dimension [0,...,shape(0)-1].
[in]iyIndex in second dimension [0,...,shape(1)-1].
Returns
Reference to FFT element.

Definition at line 222 of file GFft.hpp.

References m_data, and m_strides.

◆ operator()() [4/4]

const std::complex< double > & GFft::operator() ( const int & ix,
const int & iy ) const
inline

2-dimensional FFT element access operator (const variant)

Parameters
[in]ixIndex in first dimension [0,...,shape(0)-1].
[in]iyIndex in second dimension [0,...,shape(1)-1].
Returns
Const reference to FFT element.

Definition at line 251 of file GFft.hpp.

References m_data, and m_strides.

◆ operator*=()

GFft & GFft::operator*= ( const GFft & fft)

Unary multiplication operator.

Parameters
[in]fftFast Fourier transform.
Returns
Fast Fourier transform.

Multiplies a Fast Fourier Transform to another Fast Fourier Transform. The method requires that both FFTs have the same dimension.

Definition at line 206 of file GFft.cpp.

References G_OP_MUL, m_data, m_size, and require_same_shape().

◆ operator+=()

GFft & GFft::operator+= ( const GFft & fft)

Unary addition operator.

Parameters
[in]fftFast Fourier Transform.
Returns
Fast Fourier Transform.

Adds a Fast Fourier Transform to another Fast Fourier Transform. The method requires that both FFTs have the same dimension.

Definition at line 158 of file GFft.cpp.

References G_OP_ADD, m_data, m_size, and require_same_shape().

◆ operator-()

GFft GFft::operator- ( void ) const

Unary minus operator.

Returns
Fast Fourier transformation.

Negates all elements of the Fast Fourier Transformation.

Definition at line 252 of file GFft.cpp.

References size().

◆ operator-=()

GFft & GFft::operator-= ( const GFft & fft)

Unary subtraction operator.

Parameters
[in]fftFast Fourier transform.
Returns
Fast Fourier transform.

Subtracts a Fast Fourier Transform from another Fast Fourier Transform. The method requires that both FFTs have the same dimension.

Definition at line 182 of file GFft.cpp.

References G_OP_SUB, m_data, m_size, and require_same_shape().

◆ operator/=()

GFft & GFft::operator/= ( const GFft & fft)

Unary division operator.

Parameters
[in]fftFast Fourier transform.
Returns
Fast Fourier transform.

Divides a Fast Fourier Transform by another Fast Fourier Transform. The method requires that both FFTs have the same dimension.

Definition at line 230 of file GFft.cpp.

References G_OP_DIV, m_data, m_size, and require_same_shape().

◆ operator=()

GFft & GFft::operator= ( const GFft & fft)

Assignment operator.

Parameters
[in]fftFast Fourier Transform.
Returns
Fast Fourier Transform.

Definition at line 128 of file GFft.cpp.

References copy_members(), free_members(), and init_members().

◆ print()

std::string GFft::print ( const GChatter & chatter = NORMAL) const
virtual

Print Fast Fourier Transform information.

Parameters
[in]chatterChattiness.
Returns
String containing Fast Fourier Transform information.

Implements GBase.

Definition at line 485 of file GFft.cpp.

References dim(), m_shape, m_size, gammalib::parformat(), SILENT, size(), gammalib::str(), and VERBOSE.

◆ require_same_shape()

void GFft::require_same_shape ( const std::string & method,
const GFft & fft ) const
protected

Throw exception if FFT shapes differ.

Parameters
[in]methodMethod that throws exception.
[in]fftFast Fourier Transform.
Exceptions
GException::invalid_argumentFFT shapes differ.

Definition at line 676 of file GFft.cpp.

References has_same_shape(), m_shape, and gammalib::str().

Referenced by operator*=(), operator+=(), operator-=(), and operator/=().

◆ set_data()

void GFft::set_data ( const GNdarray & array)
protected

Set data from n-dimensional array.

Parameters
[in]arrayN-dimensional array

Definition at line 603 of file GFft.cpp.

References free_members(), init_members(), m_data, m_shape, m_size, m_strides, m_wavetable, GNdarray::shape(), GNdarray::size(), and GNdarray::strides().

Referenced by forward().

◆ shape()

const std::vector< int > & GFft::shape ( void ) const
inline

Return shape of array.

Returns
Shape of array

Returns the shape of the array.

Definition at line 296 of file GFft.hpp.

References m_shape.

Referenced by backward().

◆ size()

int GFft::size ( void ) const
inline

Return number of elements in array.

Returns
Number of elements in array

Returns the number of elements in the array.

Definition at line 282 of file GFft.hpp.

References m_size.

Referenced by operator-(), and print().

◆ strides()

const std::vector< int > & GFft::strides ( void ) const
inline

Return strides of array.

Returns
Strides of array

Returns the strides of the array.

Definition at line 310 of file GFft.hpp.

References m_strides.

◆ timesi()

std::complex< double > GFft::timesi ( const std::complex< double > & value) const
inlineprotected

Return complex value times i.

Parameters
[in]valueComplex value.
Returns
Complex value times i.

Returns complex value times i.

Definition at line 397 of file GFft.hpp.

Referenced by factor3(), factor4(), factor5(), factor6(), and factor7().

◆ transform()

void GFft::transform ( std::complex< double > * data,
const int & stride,
const int & n,
const GFftWavetable & wavetable,
const bool & forward = true )
protected

Perform Fast Fourier Transform.

Parameters
[in]dataPointer to complex array to be transformed.
[in]strideStep size when traversing complex array.
[in]nNumber of elements in complex array.
[in]wavetableTrigonometric coefficients.
[in]forwardForward transform if true, otherwise backward transform.

Definition at line 718 of file GFft.cpp.

References GFftWavetable::factor(), factor2(), factor3(), factor4(), factor5(), factor6(), factor7(), factorn(), GFftWavetable::factors(), forward(), GFftWavetable::index(), and sign().

Referenced by backward(), and forward().

Member Data Documentation

◆ m_data

std::complex<double>* GFft::m_data
protected

◆ m_shape

std::vector<int> GFft::m_shape
protected

Array dimensions.

Definition at line 182 of file GFft.hpp.

Referenced by backward(), copy_members(), dim(), forward(), has_same_shape(), init_members(), print(), require_same_shape(), set_data(), and shape().

◆ m_size

int GFft::m_size
protected

◆ m_strides

std::vector<int> GFft::m_strides
protected

Steps in each dimension.

Definition at line 183 of file GFft.hpp.

Referenced by backward(), copy_members(), forward(), init_members(), operator()(), operator()(), set_data(), and strides().

◆ m_wavetable

std::vector<GFftWavetable> GFft::m_wavetable
protected

Trigonometric coefficients.

Definition at line 184 of file GFft.hpp.

Referenced by backward(), copy_members(), forward(), init_members(), and set_data().


The documentation for this class was generated from the following files: