glucat  0.8.2
global.h
Go to the documentation of this file.
1 #ifndef _GLUCAT_GLOBAL_H
2 #define _GLUCAT_GLOBAL_H
3 /***************************************************************************
4  GluCat : Generic library of universal Clifford algebra templates
5  global.h : Global declarations
6  -------------------
7  begin : Sun 2001-12-09
8  copyright : (C) 2001-2016 by Paul C. Leopardi
9  ***************************************************************************
10 
11  This library is free software: you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with this library. If not, see <http://www.gnu.org/licenses/>.
23 
24  ***************************************************************************
25  This library is based on a prototype written by Arvind Raja and was
26  licensed under the LGPL with permission of the author. See Arvind Raja,
27  "Object-oriented implementations of Clifford algebras in C++: a prototype",
28  in Ablamowicz, Lounesto and Parra (eds.)
29  "Clifford algebras with numeric and symbolic computations, Birkhauser, 1996."
30  ***************************************************************************
31  See also Arvind Raja's original header comments and references in glucat.h
32  ***************************************************************************/
33 
34 #include "glucat/portability.h"
35 
36 #include <limits>
37 #include <climits>
38 
39 namespace glucat
40 {
41  // References:
42  // [AA]: A. Alexandrescu, "Modern C++ Design", Addison-Wesley, 2001.
43 
45  // Reference: [AA], p. 25
46  template<bool> struct CTAssertion;
47  template<> struct CTAssertion<true> { };
48  #define _GLUCAT_CTAssert(expr, msg) \
49  namespace { struct msg { glucat::CTAssertion<(expr)> ERROR_##msg; }; }
50 
52  // Reference: [AA], pp. 34--37
53  template < typename LHS_T, typename RHS_T >
55  {
56  public:
57  enum { are_same = false };
58  };
59  template < typename T >
60  class compare_types<T, T>
61  {
62  public:
63  enum { are_same = true };
64  };
65 
67  // Reference: [AA], 2.4, p. 29
68  template< bool truth_value >
70  {
71  private:
72  enum { value = truth_value };
73  };
74 
75  // Global types which determine sizes
77  typedef int index_t;
79  typedef unsigned long set_value_t;
80 
81  // Global constants
83  const double MS_PER_S = 1000.0;
84 
85  // Constants which determine sizes
86 
87  // Bits per unsigned long
88  #if (ULONG_MAX == (4294967295UL))
89  #define _GLUCAT_BITS_PER_ULONG 32
90  #elif (ULONG_MAX == (18446744073709551615UL))
91  #define _GLUCAT_BITS_PER_ULONG 64
92  #elif defined(__WORDSIZE)
93  #define _GLUCAT_BITS_PER_ULONG __WORDSIZE
94  #endif
95 
97  _GLUCAT_CTAssert(std::numeric_limits<unsigned char>::radix == 2, CannotDetermineBitsPerChar)
98 
99 
100  const index_t BITS_PER_CHAR = std::numeric_limits<unsigned char>::digits;
101 
103  const index_t BITS_PER_SET_VALUE = std::numeric_limits<set_value_t>::digits;
104 
105  _GLUCAT_CTAssert(_GLUCAT_BITS_PER_ULONG == BITS_PER_SET_VALUE, BitsPerULongDoesNotMatchSetValueT)
106 
107  // Constants which are determined by size
109  const index_t DEFAULT_LO = -index_t(BITS_PER_SET_VALUE / 2);
111  const index_t DEFAULT_HI = index_t(BITS_PER_SET_VALUE / 2);
112 
114  const double DEFAULT_TRUNCATION = std::numeric_limits<float>::epsilon();
115 
118  {
122  };
123 
124  // Tuning policy default constants
125  const unsigned int DEFAULT_Mult_Matrix_Threshold = 8;
126  const unsigned int DEFAULT_Div_Max_Steps = 4;
127  const unsigned int DEFAULT_Sqrt_Max_Steps = 256;
128  const unsigned int DEFAULT_Log_Max_Outer_Steps = 256;
129  const unsigned int DEFAULT_Log_Max_Inner_Steps = 32;
130  const unsigned int DEFAULT_Basis_Max_Count = 12;
131  const unsigned int DEFAULT_Fast_Size_Threshold = 1 << 6;
132  const unsigned int DEFAULT_Inv_Fast_Dim_Threshold = 1 << 3;
133  const unsigned int DEFAULT_Products_Size_Threshold = 1 << 22;
135 
136 
138  template
139  <
140  unsigned int Mult_Matrix_Threshold = DEFAULT_Mult_Matrix_Threshold,
141  unsigned int Div_Max_Steps = DEFAULT_Div_Max_Steps,
142  unsigned int Sqrt_Max_Steps = DEFAULT_Sqrt_Max_Steps,
143  unsigned int Log_Max_Outer_Steps = DEFAULT_Log_Max_Outer_Steps,
144  unsigned int Log_Max_Inner_Steps = DEFAULT_Log_Max_Inner_Steps,
145  unsigned int Basis_Max_Count = DEFAULT_Basis_Max_Count,
146  unsigned int Fast_Size_Threshold = DEFAULT_Fast_Size_Threshold,
147  unsigned int Inv_Fast_Dim_Threshold = DEFAULT_Inv_Fast_Dim_Threshold,
148  unsigned int Products_Size_Threshold = DEFAULT_Products_Size_Threshold,
149  precision_t Function_Precision = DEFAULT_Function_Precision
150  >
151  struct tuning
152  {
153  // Tuning for multiplication
155  enum { mult_matrix_threshold = Mult_Matrix_Threshold };
156  // Tuning for division
158  enum { div_max_steps = Div_Max_Steps };
159  // Tuning for sqrt
161  enum { sqrt_max_steps = Sqrt_Max_Steps };
162  // Tuning for log
164  enum { log_max_outer_steps = Log_Max_Outer_Steps };
166  enum { log_max_inner_steps = Log_Max_Inner_Steps };
167  // Tuning for basis cache
169  enum { basis_max_count = Basis_Max_Count };
170  // Tuning for FFT
172  enum { fast_size_threshold = Fast_Size_Threshold };
174  enum { inv_fast_dim_threshold = Inv_Fast_Dim_Threshold };
175  // Tuning for products (other than geometric product)
177  enum { products_size_threshold = Products_Size_Threshold };
178  // Tuning for precision of exp, log and sqrt functions
180  static const precision_t function_precision = Function_Precision;
181  };
182 
184  template< typename LHS_T, typename RHS_T >
185  inline
186  LHS_T
187  pos_mod(LHS_T lhs, RHS_T rhs)
188  { return lhs > 0? lhs % rhs : (-lhs) % rhs == 0 ? 0 : rhs - (-lhs) % rhs; }
189 
190 }
191 #endif // _GLUCAT_GLOBAL_H
Bool to type.
Definition: global.h:69
const double MS_PER_S
Timing constant: deprecated here - moved to test/timing.h.
Definition: global.h:83
Compile time assertion.
Definition: global.h:46
precision_t
Precision policy.
Definition: global.h:117
const unsigned int DEFAULT_Products_Size_Threshold
Definition: global.h:133
_GLUCAT_CTAssert(std::numeric_limits< unsigned char >::radix==2, CannotDetermineBitsPerChar) const index_t BITS_PER_CHAR
If radix of unsigned char is not 2, we can&#39;t easily determine number of bits from sizeof...
const index_t BITS_PER_SET_VALUE
Number of bits in set_value_t.
Definition: global.h:103
const unsigned int DEFAULT_Mult_Matrix_Threshold
Definition: global.h:125
Tuning policy.
Definition: global.h:151
const unsigned int DEFAULT_Log_Max_Outer_Steps
Definition: global.h:128
const unsigned int DEFAULT_Sqrt_Max_Steps
Definition: global.h:127
const unsigned int DEFAULT_Fast_Size_Threshold
Definition: global.h:131
const unsigned int DEFAULT_Inv_Fast_Dim_Threshold
Definition: global.h:132
const unsigned int DEFAULT_Div_Max_Steps
Definition: global.h:126
Type comparison.
Definition: global.h:54
const precision_t DEFAULT_Function_Precision
Definition: global.h:134
const unsigned int DEFAULT_Log_Max_Inner_Steps
Definition: global.h:129
const unsigned int DEFAULT_Basis_Max_Count
Definition: global.h:130
int index_t
Size of index_t should be enough to represent LO, HI.
Definition: global.h:77
unsigned long set_value_t
Size of set_value_t should be enough to contain index_set<LO,HI>
Definition: global.h:79
LHS_T pos_mod(LHS_T lhs, RHS_T rhs)
Modulo function which works reliably for lhs < 0.
Definition: global.h:187
const index_t DEFAULT_HI
Default highest index in an index set.
Definition: global.h:111
const double DEFAULT_TRUNCATION
Default for truncation.
Definition: global.h:114