types.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #pragma once
21 
22 #include <gtsam/dllexport.h>
23 #include <boost/concept/assert.hpp>
24 #include <boost/range/concepts.hpp>
25 #include <gtsam/config.h> // for GTSAM_USE_TBB
26 
27 #include <cstddef>
28 #include <cstdint>
29 
30 #include <exception>
31 #include <string>
32 
33 #ifdef GTSAM_USE_TBB
34 #include <tbb/scalable_allocator.h>
35 #endif
36 
37 #ifdef GTSAM_USE_EIGEN_MKL_OPENMP
38 #include <omp.h>
39 #endif
40 
41 #ifdef __clang__
42 # define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag) \
43  _Pragma("clang diagnostic push") \
44  _Pragma("clang diagnostic ignored \"" diag "\"")
45 #else
46 # define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag)
47 #endif
48 
49 #ifdef __clang__
50 # define CLANG_DIAGNOSTIC_POP() _Pragma("clang diagnostic pop")
51 #else
52 # define CLANG_DIAGNOSTIC_POP()
53 #endif
54 
55 namespace gtsam {
56 
58  std::string GTSAM_EXPORT demangle(const char* name);
59 
61  typedef std::uint64_t Key;
62 
65 
67  typedef ptrdiff_t DenseIndex;
68 
69  /* ************************************************************************* */
74  template<typename TEST_TYPE, typename BASIC_TYPE, typename AS_NON_CONST,
75  typename AS_CONST>
76  struct const_selector {
77  };
78 
80  template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
81  struct const_selector<BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
82  typedef AS_NON_CONST type;
83  };
84 
86  template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
87  struct const_selector<const BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
88  typedef AS_CONST type;
89  };
90 
91  /* ************************************************************************* */
97  template<typename T, T defaultValue>
100 
102  ValueWithDefault() : value(defaultValue) {}
103 
105  ValueWithDefault(const T& _value) : value(_value) {}
106 
108  T& operator*() { return value; }
109 
111  const T& operator*() const { return value; }
112 
114  operator T() const { return value; }
115  };
116 
117  /* ************************************************************************* */
120  template<typename T>
123  public:
124  typedef T value_type;
125  typedef const T* const_iterator;
126  typedef T* iterator;
127  ListOfOneContainer(const T& element) : element_(element) {}
128  const T* begin() const { return &element_; }
129  const T* end() const { return &element_ + 1; }
130  T* begin() { return &element_; }
131  T* end() { return &element_ + 1; }
132  size_t size() const { return 1; }
133  };
134 
135  BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<ListOfOneContainer<int> >));
136 
138  template<typename T>
140  return ListOfOneContainer<T>(element);
141  }
142 
143  /* ************************************************************************* */
144 #ifdef __clang__
145 # pragma clang diagnostic push
146 # pragma clang diagnostic ignored "-Wunused-private-field" // Clang complains that previousOpenMPThreads is unused in the #else case below
147 #endif
148 
153  {
155 
156  public:
157 #if defined GTSAM_USE_TBB && defined GTSAM_USE_EIGEN_MKL_OPENMP
159  previousOpenMPThreads(omp_get_num_threads())
160  {
162  }
163 
165  {
166  omp_set_num_threads(previousOpenMPThreads);
167  }
168 #else
169  TbbOpenMPMixedScope() : previousOpenMPThreads(-1) {}
171 #endif
172  };
173 
174 #ifdef __clang__
175 # pragma clang diagnostic pop
176 #endif
177 
178 }
179 
180 /* ************************************************************************* */
183 #ifdef NDEBUG
184 #define assert_throw(CONDITION, EXCEPTION) ((void)0)
185 #else
186 #define assert_throw(CONDITION, EXCEPTION) \
187  if (!(CONDITION)) { \
188  throw (EXCEPTION); \
189  }
190 #endif
191 
192 #ifdef _MSC_VER
193 
194 // Define some common g++ functions and macros we use that MSVC does not have
195 
196 #if (_MSC_VER < 1800)
197 
198 #include <boost/math/special_functions/fpclassify.hpp>
199 namespace std {
200  template<typename T> inline int isfinite(T a) {
201  return (int)boost::math::isfinite(a); }
202  template<typename T> inline int isnan(T a) {
203  return (int)boost::math::isnan(a); }
204  template<typename T> inline int isinf(T a) {
205  return (int)boost::math::isinf(a); }
206 }
207 
208 #endif
209 
210 #include <boost/math/constants/constants.hpp>
211 #ifndef M_PI
212 #define M_PI (boost::math::constants::pi<double>())
213 #endif
214 #ifndef M_PI_2
215 #define M_PI_2 (boost::math::constants::pi<double>() / 2.0)
216 #endif
217 #ifndef M_PI_4
218 #define M_PI_4 (boost::math::constants::pi<double>() / 4.0)
219 #endif
220 
221 #endif
222 
223 #ifdef min
224 #undef min
225 #endif
226 
227 #ifdef max
228 #undef max
229 #endif
230 
231 #ifdef ERROR
232 #undef ERROR
233 #endif
234 
235 namespace gtsam {
236 
238  template<typename ...> using void_t = void;
239 
255  template<typename, typename = void_t<>>
256  struct needs_eigen_aligned_allocator : std::false_type {
257  };
258  template<typename T>
260  };
261 
262 }
263 
269 #define GTSAM_MAKE_ALIGNED_OPERATOR_NEW \
270  EIGEN_MAKE_ALIGNED_OPERATOR_NEW \
271  using _eigen_aligned_allocator_trait = void;
272 
278 #define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
279  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
280  using _eigen_aligned_allocator_trait = void;
const T * begin() const
Definition: types.h:128
BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept< ListOfOneContainer< int > >))
Definition: Half.h:150
#define isfinite(X)
Definition: main.h:74
#define isinf(X)
Definition: main.h:73
ListOfOneContainer< T > ListOfOne(const T &element)
Definition: types.h:139
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:67
int omp_get_num_threads(void)
Array33i a
std::string demangle(const char *name)
Pretty print Value type name.
Definition: types.cpp:37
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
void omp_set_num_threads(int num_threads)
Eigen::Triplet< double > T
const T * end() const
Definition: types.h:129
traits
Definition: chartTesting.h:28
size_t size() const
Definition: types.h:132
ValueWithDefault(const T &_value)
Definition: types.h:105
ListOfOneContainer(const T &element)
Definition: types.h:127
int omp_get_num_procs(void)
const T & operator*() const
Definition: types.h:111
const T * const_iterator
Definition: types.h:125
Annotation for function names.
Definition: attr.h:36
void void_t
Convenience void_t as we assume C++11, it will not conflict the std one in C++17 as this is in gtsam:...
Definition: types.h:238
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Definition: types.h:64
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
#define isnan(X)
Definition: main.h:72


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:51:19