Generative Fast Fourier Transforms (GFFT)  0.3
gfftgen.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2012-2014 by Vladimir Mirnyy *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  ***************************************************************************/
14 
15 
16 #ifndef __gfftgen_h
17 #define __gfftgen_h
18 
23 #include "sint.h"
24 #include "typelistgen.h"
25 #include "gfftparamgroups.h"
26 
27 
29 namespace GFFT {
30 
31 
45 template<class N,
46 class VType,
47 class Type, // DFT, IDFT, RDFT, IRDFT
48 class Dim,
49 class Parall,
50 class Place, // IN_PLACE, OUT_OF_PLACE
51 class FactoryPolicy = Empty,
52 id_t IDN = N::ID>
53 class Transform;
54 
55 
56 template<class N,
57 class VType,
58 class Type, // DFT, IDFT, RDFT, IRDFT
59 class Dim,
60 class Parall,
61 class FactoryPolicy,
62 id_t IDN>
63 class Transform<N,VType,Type,Dim,Parall,IN_PLACE,FactoryPolicy,IDN> : public FactoryPolicy
64 {
65  typedef typename VType::ValueType T;
66  typedef typename Factorization<N, SInt>::Result NFact;
67  typedef typename Parall::template Swap<NFact::Head::first::value,NFact::Head::second::value,T>::Result Swap;
68  typedef typename Type::template Direction<N::value,T> Dir;
70 
71  typedef typename GetFirstRoot<N::value,Dir::Sign,VType::Accuracy>::Result W1;
72 
73  typedef typename IN_PLACE::template List<N::value,NFact,T,Swap,Dir,Parall::NParProc,W1>::Result TList;
74  typedef typename Type::template Algorithm<TList,Sep>::Result Alg;
75 
77 
78 public:
79  typedef VType ValueType;
80  typedef Type TransformType;
81  typedef Parall ParallType;
82  typedef IN_PLACE PlaceType;
83 
84  enum { ID = IDN };
85  static const int_t Len = N::value;
86 
87  static FactoryPolicy* Create() {
89  }
90 
91  Transform() { }
92  ~Transform() { }
93 
94 // in-place transform
95  void fft(T* data) { run.apply(data); }
96 };
97 
98 
99 template<class N,
100 class VType,
101 class Type, // DFT, IDFT, RDFT, IRDFT
102 class Dim,
103 class Parall,
104 class FactoryPolicy,
105 id_t IDN>
106 class Transform<N,VType,Type,Dim,Parall,OUT_OF_PLACE,FactoryPolicy,IDN> : public FactoryPolicy
107 {
108  typedef typename VType::ValueType T;
109  typedef typename Type::template Direction<N::value,T> Dir;
110  typedef Separate<N::value,T,Dir::Sign> Sep;
111  typedef Caller<Loki::NullType> EmptySwap;
112  typedef typename Factorization<N, SInt>::Result NFact;
113 
114  //typedef typename GenerateRootList<N::value,Dir::Sign,2>::Result RootList;
115  typedef typename GetFirstRoot<N::value,Dir::Sign,VType::Accuracy>::Result W1;
116 
117  typedef typename OUT_OF_PLACE::template List<N::value,NFact,T,EmptySwap,Dir,Parall::NParProc,W1>::Result TList;
118  typedef typename Type::template Algorithm<TList,Sep>::Result Alg;
119 
120  Caller<Loki::Typelist<Parall,Alg> > run;
121 
122 public:
123  typedef VType ValueType;
124  typedef Type TransformType;
125  typedef Parall ParallType;
126  typedef OUT_OF_PLACE PlaceType;
127 
128  enum { ID = IDN, Len = N::value };
129 
130  static FactoryPolicy* Create() {
131  return new Transform<N,VType,Type,Dim,Parall,OUT_OF_PLACE,FactoryPolicy>();
132  }
133 
134  Transform()
135  {
136  }
137 
138  ~Transform()
139  {
140  }
141 
142  // out-of-place transform
143  void fft(const T* src, T* dst) { run.apply(src, dst); }
144 };
145 
146 
148 
156 template<class TList, id_t ID>
158  typedef typename TList::Tail::Head VType;
159  typedef typename TList::Tail::Tail::Head TransformType;
160  typedef typename TList::Tail::Tail::Tail::Tail::Tail::Head Place;
161  typedef typename Place::template Interface<typename VType::ValueType>::Result Abstract;
162 
163  typedef Transform<typename TList::Head, VType, TransformType,
164  typename TList::Tail::Tail::Tail::Head,
165  typename TList::Tail::Tail::Tail::Tail::Head,
166  Place,Abstract,ID> Result;
167 };
168 
169 
170 
171 template<class NList>
172 struct TranslateID;
173 
174 template<id_t N, class T>
175 struct TranslateID<Loki::Typelist<s_uint<N>,T> > {
176  static unsigned int apply(const int_t* n) {
177  return TranslateID<T>::apply(n+1)*N + *n;
178  }
179 };
180 
181 template<id_t N>
182 struct TranslateID<Loki::Typelist<s_uint<N>,Loki::NullType> > {
183  static unsigned int apply(const int_t* n) {
184  return *n;
185  }
186 };
187 
188 
189 
190 template <typename IdentifierType, class AbstractProduct>
191 struct TransformFactoryError
192 {
193  struct Exception : public std::exception
194  {
195  const char* what() const throw() {
196  return "Requested transform is not compiled! Check your instantiation of GenerateTransform class!";
197  }
198  };
199  static AbstractProduct* OnUnknownType(IdentifierType) {
200  throw Exception();
201  }
202 };
203 
204 
206 
246 template<class NList,
247 class T /* = ValueTypeList*/, // has to be set explicitely because of AbstractFFT<T>
248 class TransType = TransformTypeGroup::Default, // DFT, IDFT, RDFT, IRDFT
249 class Dim = SIntID<1>,
250 class Parall = ParallelizationGroup::Default,
251 class Place = PlaceGroup::Default> // IN_PLACE, OUT_OF_PLACE
253  //typedef typename GenNumList<Begin,End>::Result NList;
254  enum { L1 = Loki::TL::Length<NList>::value };
255  enum { L2 = Loki::TL::Length<ValueTypeGroup::FullList>::value };
256  enum { L3 = Loki::TL::Length<TransformTypeGroup::FullList>::value };
257  enum { L4 = 1 };
258  enum { L5 = Loki::TL::Length<ParallelizationGroup::FullList>::value };
259  enum { L6 = Loki::TL::Length<DecimationGroup::FullList>::value };
260  typedef TYPELIST_6(s_uint<L1>,s_uint<L2>,s_uint<L3>,s_uint<L4>,s_uint<L5>,s_uint<L6>) LenList;
261 
262  typedef typename Loki::TL::Reverse<LenList>::Result RevLenList;
263 
264  typedef TYPELIST_6(Place,Parall,Dim,TransType,T,NList) RevList;
265 
266  typedef TranslateID<LenList> Translate;
267 
268 public:
270  typedef typename Place::template Interface<typename T::ValueType>::Result ObjectType;
271 
272  Loki::Factory<ObjectType,int_t,ObjectType*(*)(),TransformFactoryError> factory;
273 
275  FactoryInit<Result>::apply(factory);
276  }
277 
278  ObjectType* CreateTransformObject(int_t n, int_t vtype_id,
279  int_t trans_id = TransformTypeGroup::Default::ID,
280  int_t dim = 1,
281  int_t parall_id = ParallelizationGroup::Default::ID,
282  int_t decim_id = DecimationGroup::Default::ID)
283  {
284  int_t narr[] = {n-1, vtype_id, trans_id, dim-1, parall_id, decim_id};
285  int_t obj_id = Translate::apply(narr);
286  return factory.CreateObject(obj_id);
287  }
288 
289 };
290 
291 
292 } //namespace
293 
294 #endif

Generated on Mon Feb 10 2014 for Generative Fast Fourier Transforms (GFFT) by DoxyGen 1.8.3.1