polynomdefs.h

Go to the documentation of this file.
00001 
00002 
00003 #pragma once
00004 
00005 #include "CompileFunctions.h"
00006 
00007 #include <assert.h>
00008 
00009 enum P_or_QPolynom
00010     {
00011       PCoefficient,
00012       QCoefficient,
00013 };
00014 
00015 
00016 // siehe zum besseren Verstaendnis "Aspektorientierte Programmierung in C++: Teil 2, Multiple Aussichten"
00017 // http://www.heise.de/ix/artikel/2001/09/142/09.shtml
00018 // Traits heisst uebrigens Charakterzuege
00019 // see also http://www.oonumerics.org/tmpw00/
00020 // http://www.it.neclab.eu/~berti/generic/
00021 
00055 
00056 
00057 
00058 //polynomdefs und MAtrixDefs sind genau gleich -> Eine der Definitionen koennte wegfallen!
00059 template <int DEGREE>
00060 class polynomdefs
00061 {
00063 private:
00064         enum { 
00065                 pshift_m = needbits<DEGREE>::value
00066         };
00067 public:
00068         enum {  
00069                 maxdegree_m     = nextpow2num<DEGREE>::value - 1
00070         };
00071         int getSize()  const { return size_m; }
00072         enum {
00073 
00074                 size_m          = (nextpow2num<DEGREE>::value)*(nextpow2num<DEGREE>::value)
00075         };
00076         inline  static bool wellDefined()
00077         {
00078                 return (DEGREE<128);
00079         };
00081         inline  static short getPairIndex(const short a, const short b) 
00082         {
00083                 #ifdef COUNT
00084                         bitwiseShift    += 1;
00085                         bitwiseOR       += 1;
00086                 #endif  
00087                 
00088                 //return (((int)a<<pshift)|(int)b);
00089                 return ( ((int)a<<needbits<DEGREE>::value) | (int)b );
00090         }
00091 };
00092 
00097 template <int DEGREE>
00098 class polynomdefsNoShift
00099 {
00101 private:
00102          
00103 public:
00104         enum {  
00105                 maxdegree_m     = DEGREE
00106         };
00107 
00108         enum {
00109                 size_m  =  (DEGREE+1)*(DEGREE+1)
00110         };
00111         int getSize()  const { return size_m; }
00113         inline  static short getPairIndex(const short a, const short b) 
00114         {
00115                 return ( ( (int)(a+b)*(DEGREE+1)) + (int)b );
00116         }
00117 };
00118 
00119 class dynamicQuadraticMatrixDefsNoShift
00120 {
00121 private:
00122         int     size_m; 
00123 
00124         dynamicQuadraticMatrixDefsNoShift();
00125  
00126 public:
00127         const int       dim_m;
00128         
00129 
00130         inline int getSize()  const { return size_m; }
00131 
00132         dynamicQuadraticMatrixDefsNoShift(int dimension):       size_m((dimension+1)*(dimension+1) ) ,
00133                                                                                 dim_m(dimension+1)      
00134                                                                                 
00135         {
00136         }
00137 
00138         inline  short getPairIndex(const short a, const short b) const
00139         {
00140                 return (  (int)(a*dim_m) + (int)b );
00141         }
00142 };
00143 
00144 
00145 class dynamicPolynomdefsNoShift
00146 {
00147 
00148 private:
00149           int   size_m;
00150         dynamicPolynomdefsNoShift();
00151 public:
00152          int    maxdegree_m;
00153          int    maxdegreePlusOne_m;
00154         
00155 
00156         inline int getSize()  const { return size_m; }
00157 
00158         dynamicPolynomdefsNoShift(int degree):  size_m((degree+1)*(degree+1) ),
00159                                                                 maxdegree_m(degree),
00160                                                                 maxdegreePlusOne_m(degree+1)
00161         {
00162         }
00163 
00164         inline  short getPairIndex(const short a, const short b) const
00165         {
00166                 return ( ( (int)(a+b)*maxdegreePlusOne_m) + (int)b );
00167         }
00168 };
00169 
00170 
00172 class dynamicPolynomdefsNoShiftNoMemoryHoles
00173 {
00174 private:
00176         int*    offsets_m;
00177         int     size_m;
00178         dynamicPolynomdefsNoShiftNoMemoryHoles();
00179         
00180         
00181 
00182 public:
00183          int    maxdegree_m;
00184          int    maxdegreePlusOne_m;
00185         
00186         // wegen short getIndex()
00187         bool wellDefined()
00188         {
00189                 assert(size_m<32000);
00190         }
00191 
00192         inline int getSize()  const { return size_m; }
00193 
00194         int computeSize(int degree)
00195         {
00196                 int size=0;
00197                 for (int currDegree=0;currDegree<=degree; currDegree++)
00198                 {
00199                         offsets_m[currDegree] = size;
00200                         for (int yExp=0;yExp<=currDegree; yExp++)
00201                                 size++;
00202                 }
00203                 return size;
00204         }
00205 
00206         dynamicPolynomdefsNoShiftNoMemoryHoles(int degree):     
00207                                                         offsets_m(new int[degree+1]),
00208                                                         size_m(computeSize(degree)),            
00209                                                         maxdegree_m(degree),
00210                                                         maxdegreePlusOne_m(degree+1)
00211         {
00212         }
00213 
00214         inline  short getPairIndex(const short a, const short b) const
00215         {
00216 
00217                 int offset=0;
00218                 int monomDegree = a+b;
00219                 for (int currDegree=0; currDegree< monomDegree; currDegree++)
00220                 {
00221                         for (int yExp=0;yExp<=currDegree; yExp++)
00222                                 offset++;
00223                 }
00224                 assert( offsets_m[ monomDegree ] == offset );
00225                 offset = offset + b;
00226                 return offset;
00227         }
00228 };
00229 
00231 
00232 
00233 
00234 template <int DEGREE>
00235 class polynomdefsNew
00236 {
00238 private:
00239         enum { 
00240                 pshift_m = needbits<DEGREE>::value
00241         };
00242 public:
00243         enum {  
00244                 maxdegree_m     = DEGREE
00245         };
00246 
00247         enum {
00248                 size_m          = (nextpow2num<DEGREE>::value)*(nextpow2num<DEGREE>::value)
00249         };
00250 
00251         inline static unsigned short getSize()
00252         {
00253                 return (nextpow2num<DEGREE>::value)*(nextpow2num<DEGREE>::value);
00254         }
00256         inline  static size_t getPairIndex(const unsigned short a, const unsigned short b) 
00257         {
00258                 #ifdef COUNT
00259                         bitwiseShift    += 1;
00260                         bitwiseOR       += 1;
00261                 #endif  
00262                 // Vorsicht bein shiften! muss ich pshift sicherheitshalber in ein int konvertieren ja/nein?
00263                 //return (((int)a<<pshift)|(int)b);
00264                 return ( ((int)(a+b)<<needbits<DEGREE>::value) | (int)b );
00265         }
00266 };
00267 
00268 
00269 
00272 template <int DEGREE>
00273 class polynompairdefs
00274 {
00276 private:
00277         enum { 
00278                 pshift_m = needbits<DEGREE>::valueplusone
00279         };
00280 public:
00281         enum {  
00282                 maxdegree_m     = DEGREE
00283         };
00284 
00285         enum {
00286                 size_m          = 2*(nextpow2num<DEGREE>::value) * (nextpow2num<DEGREE>::value) 
00287         };
00288 
00289         int getSize()  const { return size_m; }
00291         inline  static short    getPairIndex(const short a, const short b) 
00292         {
00293                 #ifdef COUNT
00294                         bitwiseShift    += 1;
00295                         bitwiseOR       += 1;
00296                 #endif  
00297                 // Vorsicht bein shiften! muss ich pshift sicherheitshalber in ein int konvertieren ja/nein?
00298                 //return (((int)a<<pshift)|(int)b);
00299                 return ( ((int)(a+b) << (needbits<DEGREE>::valueplusone)) | (int)(b<<1) );
00300         }
00301 
00302 
00303         inline  static short    getGroupIndex(const short a) 
00304         {
00305                 #ifdef COUNT
00306                         bitwiseShift    += 1;
00307                         bitwiseOR       += 1;
00308                 #endif  
00309                 // Vorsicht bein shiften! muss ich pshift sicherheitshalber in ein int konvertieren ja/nein?
00310                 //return (((int)a<<pshift)|(int)b);
00311                 return ( (int) a << (needbits<DEGREE>::valueplusone) );
00312         }
00313 };
00314 
00315 
00316 
00317 //maxdegree mei Matrixdef
00318 // haengt nicht vom unteren Datenyp der MAtrix ab, aber legt wohl die 
00319 // maximale groesse fest
00324 template <short CHAR>
00325 class matrixdefs
00326 {
00327 private:
00328         enum {
00329                 pshift_m = needbits<CHAR>::value
00330         };
00331 public:
00333         enum {
00334                 maxdegree_m = nextpow2num<CHAR>::value - 1
00335         };
00336         enum {
00337                 size_m  = (nextpow2num<CHAR>::value)*(nextpow2num<CHAR>::value)
00338         };
00339         int getSize()  const { return size_m; }
00341                 inline static  short getPairIndex(short a, short b) 
00342                 {
00343                         #ifdef COUNT
00344                                 bitwiseShift+=1;
00345                                 bitwiseOR+=1;
00346                         #endif
00347                         // Vorsicht bein shiften! muss ich pshift sicherheitshalber in ein int konvertieren ja/nein?
00348                         return ( ((int)a<<needbits<CHAR>::value) | (int)b );
00349 
00350                 }
00351 };
00352 
00353 
00362 template <unsigned int CHAR, unsigned short EPSPREC>
00363 class kdefs_zahl_x
00364 {
00365         public:
00366         /*      static  const  short charakteristik;
00367                 static  const  short epsPrecision; // umbenennen in base_num_epsPrecision???
00368         */
00369                         
00370         enum {          
00371                 charakteristik_m = CHAR 
00372         };
00373         enum {          
00374                 charakteristik_minus_one_m = CHAR-1
00375         };
00376         enum {
00377                 epsPrecision_m   = EPSPREC
00378         };
00379 };
00380 
00381 /* // this implementation does not compile with some compilers, therefore the 'enum' approach is used - leave it as syntax example!
00382 template <int CHAR>
00383 const  short kdefs_zahl_x<CHAR>::charakteristik(CHAR);
00384 
00385 template <int CHAR>
00386 const  short kdefs_zahl_x<CHAR>::epsPrecision(EPSPRECISION);
00387 */
00388 
Generated on Tue Nov 23 13:10:52 2010 for centerfocus by  doxygen 1.6.3