ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
fft_halfcomplex.hpp
Go to the documentation of this file.
1/*
2 * $Id: fft_halfcomplex.hpp 283 2012-08-26 15:36:43Z jdl3 $
3 * Copyright (C) 2012 John D Lamb
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#ifndef CCGSL_FFT_HALFCOMPLEX_HPP
21#define CCGSL_FFT_HALFCOMPLEX_HPP
22
23#include <gsl/gsl_fft_halfcomplex.h>
24#include "complex.hpp"
25#include "vector_complex.hpp"
26#include "fft_real.hpp"
27
28namespace gsl {
29 namespace fft {
33 namespace halfcomplex {
37 namespace radix2 {
45 inline int backward( double data[], size_t const stride, size_t const n ){
46 return gsl_fft_halfcomplex_radix2_backward( data, stride, n ); }
47
55 inline int inverse( double data[], size_t const stride, size_t const n ){
56 return gsl_fft_halfcomplex_radix2_inverse( data, stride, n ); }
57
64 inline int backward( double data[], size_t const n ){
65 return gsl_fft_halfcomplex_radix2_backward( data, 1, n ); }
66
73 inline int inverse( double data[], size_t const n ){
74 return gsl_fft_halfcomplex_radix2_inverse( data, 1, n ); }
75
83 template<typename DATA>
84 inline int backward( DATA& data, size_t const stride = 1 ){
85 return gsl_fft_halfcomplex_radix2_backward( data.data(), stride, data.size() / stride ); }
86
94 template<typename DATA>
95 inline int inverse( DATA& data, size_t const stride = 1 ){
96 return gsl_fft_halfcomplex_radix2_inverse( data.data(), stride, data.size() / stride ); }
97 }
98
102 class wavetable {
103 public:
108 ccgsl_pointer = 0;
109 count = 0; // initially nullptr will do
110 }
111 // Refines random access container
112 // Refines assignable
117 explicit wavetable( size_t const n ){
118 ccgsl_pointer = gsl_fft_halfcomplex_wavetable_alloc( n );
119 // just plausibly we could allocate wavetable but not count
120 try { count = new size_t; } catch( std::bad_alloc& e ){
121 // try to tidy up before rethrowing
122 gsl_fft_halfcomplex_wavetable_free( ccgsl_pointer );
123 throw e;
124 }
125 *count = 1; // initially there is just one reference to ccgsl_pointer
126 }
133 explicit wavetable( gsl_fft_halfcomplex_wavetable* v ){
134 ccgsl_pointer = v;
135 // just plausibly we could fail to allocate count: no further action needed.
136 count = new size_t;
137 *count = 1; // initially there is just one reference to ccgsl_pointer
138 }
139 // copy constructor
145 count = v.count; if( count != 0 ) ++*count; }
146 // assignment operator
152 // first, possibly delete anything pointed to by this
153 if( count == 0 or --*count == 0 ){
154 if( ccgsl_pointer != 0 ) gsl_fft_halfcomplex_wavetable_free( ccgsl_pointer );
155 delete count;
156 } // Then copy
157 ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
158 }
159 // destructor
164 if( count == 0 or --*count == 0 ){
165 // could have allocated null pointer
166 if( ccgsl_pointer != 0 ) gsl_fft_halfcomplex_wavetable_free( ccgsl_pointer );
167 delete count;
168 }
169 }
170#ifdef __GXX_EXPERIMENTAL_CXX0X__
176 std::swap( count, v.count );
177 v.ccgsl_pointer = nullptr;
178 }
185 wavetable( std::move( v ) ).swap( *this );
186 return *this;
187 }
188#endif
189 // Refines equality comparable
190 // == operator
197 bool operator==( wavetable const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
198 // != operator
205 bool operator!=( wavetable const& v ) const { return not operator==( v ); }
206 // Refines forward container
207 // Refines less than comparable
208 // operator<
217 bool operator<( wavetable const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
218 // operator>
227 bool operator>( wavetable const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
228 // operator<=
237 bool operator<=( wavetable const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
238 // operator>=
247 bool operator>=( wavetable const& v ) const { return ccgsl_pointer >= v.ccgsl_pointer; }
252 bool empty() const { return ccgsl_pointer == 0; }
253 // swap() --- should work even if sizes don't match
259 void swap( wavetable& v ){
260 std::swap( ccgsl_pointer, v.ccgsl_pointer );
261 std::swap( count, v.count );
262 }
263 private:
267 gsl_fft_halfcomplex_wavetable* ccgsl_pointer;
271 size_t* count;
272 public:
273 // shared reference functions
278 gsl_fft_halfcomplex_wavetable* get() const { return ccgsl_pointer; }
284 bool unique() const { return count != 0 and *count == 1; }
289 size_t use_count() const { return count == 0 ? 0 : *count; }
295#ifdef __GXX_EXPERIMENTAL_CXX0X__
296 explicit
297#endif
298 operator bool() const { return ccgsl_pointer != 0; }
299 };
300
310 inline int backward( gsl::complex_packed_array data, size_t const stride, size_t const n,
311 wavetable const& wavetable, real::workspace& work ){
312 return gsl_fft_halfcomplex_backward( data, stride, n, wavetable.get(), work.get() ); }
313
323 inline int inverse( gsl::complex_packed_array data, size_t const stride, size_t const n,
324 wavetable const& wavetable, real::workspace& work ){
325 return gsl_fft_halfcomplex_inverse( data, stride, n, wavetable.get(), work.get() ); }
326
335 inline int unpack( double const real_coefficient[], double complex_coefficient[],
336 size_t const stride, size_t const n ){
337 return gsl_fft_halfcomplex_unpack( real_coefficient, complex_coefficient, stride, n ); }
338
348 template<typename DATA>
349 inline int backward( DATA& data, size_t const stride, wavetable const& wavetable,
350 real::workspace& work ){
351 return gsl_fft_halfcomplex_backward( data.data(), stride, data.size(),
352 wavetable.get(), work.get() ); }
353
363 template<typename DATA>
364 inline int inverse( DATA& data, size_t const stride, wavetable const& wavetable,
365 real::workspace& work ){
366 return gsl_fft_halfcomplex_inverse( data.data(), stride, data.size(),
367 wavetable.get(), work.get() ); }
368
377 template<typename R, typename C>
378 inline int unpack( R const& real_coefficient, C& complex_coefficient, size_t const stride ){
379 size_t n = std::max( real_coefficient.size(), complex_coefficient.size() / 2);
380 return gsl_fft_halfcomplex_unpack( real_coefficient.data(), complex_coefficient.data(),
381 stride, n ); }
382 // Partial specialisation
383
392 template<>
393 inline int unpack( vector const& real_coefficient, vector_complex& complex_coefficient,
394 size_t const stride ){
395 size_t n = std::max( real_coefficient.size(), complex_coefficient.size() );
396 return gsl_fft_halfcomplex_unpack( real_coefficient.data(), complex_coefficient.data(),
397 stride, n ); }
398
399 // stride-free versions
400
409 inline int backward( gsl::complex_packed_array data, size_t const n,
410 wavetable const& wavetable, real::workspace& work ){
411 return gsl_fft_halfcomplex_backward( data, 1, n, wavetable.get(), work.get() ); }
412
421 inline int inverse( gsl::complex_packed_array data, size_t const n,
422 wavetable const& wavetable, real::workspace& work ){
423 return gsl_fft_halfcomplex_inverse( data, 1, n, wavetable.get(), work.get() ); }
424
432 inline int unpack( double const real_coefficient[], double complex_coefficient[], size_t const n ){
433 return gsl_fft_halfcomplex_unpack( real_coefficient, complex_coefficient, 1, n ); }
434
443 template<typename DATA>
444 inline int backward( DATA& data, wavetable const& wavetable,
445 real::workspace& work ){
446 return gsl_fft_halfcomplex_backward( data.data(), 1, data.size(),
447 wavetable.get(), work.get() ); }
448
457 template<typename DATA>
458 inline int inverse( DATA& data, wavetable const& wavetable,
459 real::workspace& work ){
460 return gsl_fft_halfcomplex_inverse( data.data(), 1, data.size(),
461 wavetable.get(), work.get() ); }
462
470 template<typename R, typename C>
471 inline int unpack( R const& real_coefficient, C& complex_coefficient ){
472 size_t n = std::max( real_coefficient.size(), complex_coefficient.size() / 2);
473 return gsl_fft_halfcomplex_unpack( real_coefficient.data(), complex_coefficient.data(), 1, n ); }
474
482 template<>
483 inline int unpack( vector const& real_coefficient, vector_complex& complex_coefficient ){
484 size_t n = std::max( real_coefficient.size(), complex_coefficient.size() );
485 return gsl_fft_halfcomplex_unpack( real_coefficient.data(), complex_coefficient.data(), 1, n ); }
486
487
488 }
489 }
490}
491
492#endif
C++ version of gsl_fft_halfcomplex_wavetable functions.
wavetable(gsl_fft_halfcomplex_wavetable *v)
Could construct from a gsl_fft_halfcomplex_wavetable.
bool unique() const
Find if this is the only object sharing the gsl_fft_halfcomplex_wavetable.
bool operator>=(wavetable const &v) const
A container needs to define an ordering for sorting.
bool operator>(wavetable const &v) const
A container needs to define an ordering for sorting.
wavetable()
The default constructor is only really useful for assigning to.
wavetable & operator=(wavetable const &v)
The assignment operator.
wavetable(size_t const n)
The default constructor creates a new workspace of size n.
bool operator<=(wavetable const &v) const
A container needs to define an ordering for sorting.
bool empty() const
Find if the wavetable is empty.
wavetable(wavetable const &v)
The copy constructor.
gsl_fft_halfcomplex_wavetable * ccgsl_pointer
The shared pointer.
bool operator==(wavetable const &v) const
Two wavetable are identically equal if their elements are identical.
size_t use_count() const
Find how many workspace objects share this pointer.
size_t * count
The shared reference count.
wavetable & operator=(wavetable &&v)
Move operator.
bool operator!=(wavetable const &v) const
Two wavetable are different equal if their elements are not identical.
void swap(wavetable &v)
Swap two wavetable.
bool operator<(wavetable const &v) const
A container needs to define an ordering for sorting.
~wavetable()
The destructor only deletes the pointers if count reaches zero.
gsl_fft_halfcomplex_wavetable * get() const
Get the gsl_fft_halfcomplex_wavetable.
wavetable(wavetable &&v)
Move constructor.
Workspace for real fast fourier transforms.
Definition: fft_real.hpp:273
gsl_fft_real_workspace * get() const
Get the gsl_fft_real_workspace.
Definition: fft_real.hpp:449
This class handles vector_complex objects as shared handles.
size_type size() const
The size (number of elements) of the vector_complex.
double * data()
Give access to the data block.
This class handles vector objects as shared handles.
Definition: vector.hpp:74
size_type size() const
The size (number of elements) of the vector.
Definition: vector.hpp:1169
double * data()
Give access to the data block.
Definition: vector.hpp:1177
int backward(double data[], size_t const stride, size_t const n)
C++ version of gsl_fft_halfcomplex_radix2_backward().
int inverse(double data[], size_t const stride, size_t const n)
C++ version of gsl_fft_halfcomplex_radix2_inverse().
int unpack(double const real_coefficient[], double complex_coefficient[], size_t const stride, size_t const n)
C++ version of gsl_fft_halfcomplex_unpack().
int inverse(gsl::complex_packed_array data, size_t const stride, size_t const n, wavetable const &wavetable, real::workspace &work)
C++ version of gsl_fft_halfcomplex_inverse().
int backward(gsl::complex_packed_array data, size_t const stride, size_t const n, wavetable const &wavetable, real::workspace &work)
C++ version of gsl_fft_halfcomplex_backward().
int max(movstat::end_t const endtype, vector const &x, vector &y, workspace &w)
C++ version of gsl_movstat_max().
Definition: movstat.hpp:592
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
Definition: rstat.hpp:299
The gsl package creates an interface to the GNU Scientific Library for C++.
Definition: blas.hpp:34
gsl_complex_packed_array complex_packed_array
Typedef.
Definition: complex.hpp:1218