Generative Fast Fourier Transforms (GFFT)  0.3
metaroot.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 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 #ifndef __metaroot_h
16 #define __metaroot_h
17 
22 #include <cmath>
23 
24 #include "metafunc.h"
25 
26 namespace MF {
27 
28 // template<class W, class W1, int_t N, int_t I, int S>
29 // struct GetNextRoot;
30 //
31 // template<class H, class T, class H1, class T1, int_t N, int_t I, int S>
32 // struct GetNextRoot<Loki::Typelist<H,T>,Loki::Typelist<H1,T1>,N,I,S>
33 // {
34 // typedef typename Mult<H,H1>::Result W;
35 // typedef typename GetNextRoot<T,T1,N,I,S>::Result Next;
36 // typedef Loki::Typelist<W,Next> Result;
37 // };
38 //
39 // template<int_t N, int_t I, int S>
40 // struct GetNextRoot<Loki::NullType,Loki::NullType,N,I,S>
41 // {
42 // typedef Loki::NullType Result;
43 // };
44 
45 template<int_t I, int_t M, class W1, class W, int Accuracy>
46 struct GetNextRoot {
47  typedef typename Mult<W1,W>::Result Result;
48 };
49 /*
50 template<class W1, class W, int_t I, int Accuracy>
51 struct GetNextRoot<I,2,W1,W,Accuracy> {
52  typedef typename CosPiFrac<I,2,Accuracy>::Result Re;
53  typedef typename SinPiFrac<I,2,Accuracy>::Result Im;
54  typedef typename RationalToDecimal<Re,Accuracy>::Result ReDec;
55  typedef typename RationalToDecimal<Im,Accuracy>::Result ImDec;
56  typedef MComplex<ReDec,ImDec> Result;
57 };
58 
59 template<class W1, class W, int_t I, int Accuracy>
60 struct GetNextRoot<I,1,W1,W,Accuracy> {
61  typedef typename CosPiFrac<I,1,Accuracy>::Result Re;
62  typedef typename SinPiFrac<I,1,Accuracy>::Result Im;
63  typedef typename RationalToDecimal<Re,Accuracy>::Result ReDec;
64  typedef typename RationalToDecimal<Im,Accuracy>::Result ImDec;
65  typedef MComplex<ReDec,ImDec> Result;
66 };
67 */
68 
69 template<class W1, int_t N, int Accuracy, class W, int_t Count, int_t I = 2>
70 struct __RootListLoop {
71  typedef typename Simplify<SRational<SInt<2*I>,SInt<N> > >::Result SF;
72 //typedef typename NL::Print<SF>::Result TTT;
73  typedef typename GetNextRoot<SF::Numer::value,SF::Denom::value,W1,W,Accuracy>::Result WW;
74  typedef Compute<typename WW::Re,Accuracy> CRe;
75  typedef Compute<typename WW::Im,Accuracy> CIm;
76  typedef typename __RootListLoop<W1,N,Accuracy,WW,Count,I+1>::Result Next;
77  typedef Loki::Typelist<Pair<CRe,CIm>,Next> Result;
78 };
79 
80 template<class W1, int_t N, int Accuracy, class W, int_t Count>
81 struct __RootListLoop<W1,N,Accuracy,W,Count,Count> {
82  typedef Loki::NullType Result;
83 };
84 
85 template<class RList>
86 struct GenerateSymmetricPart;
87 
88 template<class H, class T>
89 struct GenerateSymmetricPart<Loki::Typelist<H,T> > {
90  typedef typename H::first T1;
91  typedef typename Negate<typename H::second::BigInt>::Result T2;
92  typedef typename GenerateSymmetricPart<T>::Result Next;
93  typedef Loki::Typelist<Pair<T1,T2>,Next> Result;
94 };
95 
96 template<>
97 struct GenerateSymmetricPart<Loki::NullType> {
98  typedef Loki::NullType Result;
99 };
100 
101 
102 template<int_t N, int S, int Accuracy>
103 class GetFirstRoot {
104  //typedef typename SinPiDecimal<1,N,Accuracy>::Result Sin1;
105  typedef typename SinPiDecimal<2,N,Accuracy>::Result Sin2;
106 
107  typedef typename Loki::Select<(S<0),Sin2,
108  typename Negate<Sin2>::Result>::Result WI;
109  //typedef typename RationalToDecimal<WI,Accuracy>::Result WIDec;
110 
111 // typedef typename Sub<SInt<1>,typename Mult<SInt<2>,
112 // typename Mult<Sin1,Sin1>::Result>::Result>::Result WR;
113  typedef typename CosPiDecimal<2,N,Accuracy>::Result WR;
114  //typedef typename RationalToDecimal<WR,Accuracy>::Result WRDec;
115 
116 public:
117  typedef MComplex<WR,WI> Result;
118 };
119 
120 
121 
122 template<int_t N, int S, int Accuracy>
123 class GenerateRootList
124 {
125  typedef typename GetFirstRoot<N,-S,Accuracy>::Result W1;
126 
127 public:
128  typedef Compute<typename W1::Re,Accuracy> CRe;
129  typedef Compute<typename W1::Im,Accuracy> CIm;
130  typedef Loki::Typelist<Pair<CRe,CIm>,typename __RootListLoop<W1,N,Accuracy,W1,(N%2==0) ? N/2 : N/2+1>::Result> FirstHalf;
131  typedef typename Loki::Select<(N%2==0),
132  typename Loki::TL::Append<FirstHalf,typename GenerateRootList<2,S,Accuracy>::Result>::Result,FirstHalf>::Result FirstHalfMod;
133 // typedef typename Loki::TL::Reverse<typename GenerateSymmetricPart<FirstHalf>::Result>::Result SecondHalf;
134 
135 //public:
136 // typedef typename Loki::TL::Append<FirstHalfMod,SecondHalf>::Result Result;
137  typedef FirstHalf Result;
138 };
139 
140 template<int S, int Accuracy>
141 class GenerateRootList<2,S,Accuracy> {
142  typedef Compute<SInt<-1>,Accuracy> CRe;
143  typedef Compute<SInt<0>, Accuracy> CIm;
144 public:
145  typedef Loki::Typelist<Pair<CRe,CIm>,Loki::NullType> Result;
146 };
147 
148 template<int S, int Accuracy>
149 class GenerateRootList<1,S,Accuracy> {
150 public:
151  typedef Loki::NullType Result;
152 };
153 
154 } // namespace
155 
156 #endif /*__metaroot_h*/

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