glucat  0.8.4
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 >
54  class compare_types
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 >
69  class bool_to_type
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);
112 
114  const double DEFAULT_TRUNCATION = std::numeric_limits<float>::epsilon();
115 
117  enum precision_t
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,
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
glucat::compare_types::are_same
@ are_same
Definition: global.h:86
glucat::precision_demoted
@ precision_demoted
Definition: global.h:148
glucat::precision_same
@ precision_same
Definition: global.h:149
portability.h
glucat::DEFAULT_Fast_Size_Threshold
const unsigned int DEFAULT_Fast_Size_Threshold
Definition: global.h:160
glucat::DEFAULT_Sqrt_Max_Steps
const unsigned int DEFAULT_Sqrt_Max_Steps
Definition: global.h:156
glucat::tuning::sqrt_max_steps
@ sqrt_max_steps
Definition: global.h:190
glucat::tuning
Tuning policy.
Definition: global.h:181
glucat::DEFAULT_Inv_Fast_Dim_Threshold
const unsigned int DEFAULT_Inv_Fast_Dim_Threshold
Definition: global.h:161
glucat::bool_to_type::value
@ value
Definition: global.h:101
glucat::DEFAULT_Log_Max_Inner_Steps
const unsigned int DEFAULT_Log_Max_Inner_Steps
Definition: global.h:158
glucat::DEFAULT_Div_Max_Steps
const unsigned int DEFAULT_Div_Max_Steps
Definition: global.h:155
glucat::tuning::products_size_threshold
@ products_size_threshold
Definition: global.h:206
glucat::DEFAULT_Basis_Max_Count
const unsigned int DEFAULT_Basis_Max_Count
Definition: global.h:159
glucat::DEFAULT_Function_Precision
const precision_t DEFAULT_Function_Precision
Definition: global.h:163
glucat::index_t
int index_t
Size of index_t should be enough to represent LO, HI.
Definition: global.h:106
glucat::set_value_t
unsigned long set_value_t
Size of set_value_t should be enough to contain index_set<LO,HI>
Definition: global.h:108
glucat::precision_promoted
@ precision_promoted
Definition: global.h:150
glucat::DEFAULT_HI
const index_t DEFAULT_HI
Default highest index in an index set.
Definition: global.h:140
glucat::tuning::basis_max_count
@ basis_max_count
Definition: global.h:198
glucat::DEFAULT_TRUNCATION
const double DEFAULT_TRUNCATION
Default for truncation.
Definition: global.h:143
glucat::tuning::function_precision
static const precision_t function_precision
Precision used for exp, log and sqrt functions.
Definition: global.h:209
glucat::tuning::inv_fast_dim_threshold
@ inv_fast_dim_threshold
Definition: global.h:203
glucat::pos_mod
LHS_T pos_mod(LHS_T lhs, RHS_T rhs)
Modulo function which works reliably for lhs < 0.
Definition: global.h:216
glucat::tuning::log_max_outer_steps
@ log_max_outer_steps
Definition: global.h:193
glucat::MS_PER_S
const double MS_PER_S
Timing constant: deprecated here - moved to test/timing.h.
Definition: global.h:112
glucat::tuning::fast_size_threshold
@ fast_size_threshold
Definition: global.h:201
glucat::DEFAULT_Products_Size_Threshold
const unsigned int DEFAULT_Products_Size_Threshold
Definition: global.h:162
glucat::tuning::mult_matrix_threshold
@ mult_matrix_threshold
Definition: global.h:184
glucat::precision_t
precision_t
Precision policy.
Definition: global.h:147
epsilon
const scalar_t epsilon
Definition: PyClical.h:163
glucat::BITS_PER_SET_VALUE
const index_t BITS_PER_SET_VALUE
Number of bits in set_value_t.
Definition: global.h:132
std
Definition: framed_multi.h:371
glucat
Definition: clifford_algebra.h:39
glucat::DEFAULT_Mult_Matrix_Threshold
const unsigned int DEFAULT_Mult_Matrix_Threshold
Definition: global.h:154
glucat::_GLUCAT_CTAssert
_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't easily determine number of bits from sizeof.
glucat::tuning::log_max_inner_steps
@ log_max_inner_steps
Definition: global.h:195
glucat::tuning::div_max_steps
@ div_max_steps
Definition: global.h:187
glucat::DEFAULT_Log_Max_Outer_Steps
const unsigned int DEFAULT_Log_Max_Outer_Steps
Definition: global.h:157