gtsam 4.1.1
gtsam
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#if defined(__GNUC__) || defined(__clang__)
38#define GTSAM_DEPRECATED __attribute__((deprecated))
39#elif defined(_MSC_VER)
40#define GTSAM_DEPRECATED __declspec(deprecated)
41#else
42#define GTSAM_DEPRECATED
43#endif
44
45#ifdef GTSAM_USE_EIGEN_MKL_OPENMP
46#include <omp.h>
47#endif
48
49#ifdef __clang__
50# define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag) \
51 _Pragma("clang diagnostic push") \
52 _Pragma("clang diagnostic ignored \"" diag "\"")
53#else
54# define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag)
55#endif
56
57#ifdef __clang__
58# define CLANG_DIAGNOSTIC_POP() _Pragma("clang diagnostic pop")
59#else
60# define CLANG_DIAGNOSTIC_POP()
61#endif
62
63namespace gtsam {
64
66 std::string GTSAM_EXPORT demangle(const char* name);
67
69 typedef std::uint64_t Key;
70
72 typedef std::uint64_t FactorIndex;
73
75 typedef ptrdiff_t DenseIndex;
76
77 /* ************************************************************************* */
82 template<typename TEST_TYPE, typename BASIC_TYPE, typename AS_NON_CONST,
83 typename AS_CONST>
85 };
86
88 template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
89 struct const_selector<BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
90 typedef AS_NON_CONST type;
91 };
92
94 template<typename BASIC_TYPE, typename AS_NON_CONST, typename AS_CONST>
95 struct const_selector<const BASIC_TYPE, BASIC_TYPE, AS_NON_CONST, AS_CONST> {
96 typedef AS_CONST type;
97 };
98
99 /* ************************************************************************* */
105 template<typename T, T defaultValue>
107 T value;
108
110 ValueWithDefault() : value(defaultValue) {}
111
113 ValueWithDefault(const T& _value) : value(_value) {}
114
116 T& operator*() { return value; }
117
119 const T& operator*() const { return value; }
120
122 operator T() const { return value; }
123 };
124
125 /* ************************************************************************* */
128 template<typename T>
130 T element_;
131 public:
132 typedef T value_type;
133 typedef const T* const_iterator;
134 typedef T* iterator;
135 ListOfOneContainer(const T& element) : element_(element) {}
136 const T* begin() const { return &element_; }
137 const T* end() const { return &element_ + 1; }
138 T* begin() { return &element_; }
139 T* end() { return &element_ + 1; }
140 size_t size() const { return 1; }
141 };
142
143 BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<ListOfOneContainer<int> >));
144
146 template<typename T>
148 return ListOfOneContainer<T>(element);
149 }
150
151 /* ************************************************************************* */
152#ifdef __clang__
153# pragma clang diagnostic push
154# pragma clang diagnostic ignored "-Wunused-private-field" // Clang complains that previousOpenMPThreads is unused in the #else case below
155#endif
156
161 {
162 int previousOpenMPThreads;
163
164 public:
165#if defined GTSAM_USE_TBB && defined GTSAM_USE_EIGEN_MKL_OPENMP
167 previousOpenMPThreads(omp_get_num_threads())
168 {
169 omp_set_num_threads(omp_get_num_procs() / 4);
170 }
171
173 {
174 omp_set_num_threads(previousOpenMPThreads);
175 }
176#else
177 TbbOpenMPMixedScope() : previousOpenMPThreads(-1) {}
179#endif
180 };
181
182#ifdef __clang__
183# pragma clang diagnostic pop
184#endif
185
186}
187
188/* ************************************************************************* */
191#ifdef NDEBUG
192#define assert_throw(CONDITION, EXCEPTION) ((void)0)
193#else
194#define assert_throw(CONDITION, EXCEPTION) \
195 if (!(CONDITION)) { \
196 throw (EXCEPTION); \
197 }
198#endif
199
200#ifdef _MSC_VER
201
202// Define some common g++ functions and macros we use that MSVC does not have
203
204#if (_MSC_VER < 1800)
205
206#include <boost/math/special_functions/fpclassify.hpp>
207namespace std {
208 template<typename T> inline int isfinite(T a) {
209 return (int)boost::math::isfinite(a); }
210 template<typename T> inline int isnan(T a) {
211 return (int)boost::math::isnan(a); }
212 template<typename T> inline int isinf(T a) {
213 return (int)boost::math::isinf(a); }
214}
215
216#endif
217
218#include <boost/math/constants/constants.hpp>
219#ifndef M_PI
220#define M_PI (boost::math::constants::pi<double>())
221#endif
222#ifndef M_PI_2
223#define M_PI_2 (boost::math::constants::pi<double>() / 2.0)
224#endif
225#ifndef M_PI_4
226#define M_PI_4 (boost::math::constants::pi<double>() / 4.0)
227#endif
228
229#endif
230
231#ifdef min
232#undef min
233#endif
234
235#ifdef max
236#undef max
237#endif
238
239#ifdef ERROR
240#undef ERROR
241#endif
242
243namespace gtsam {
244
246 template<typename ...> using void_t = void;
247
263 template<typename, typename = void_t<>>
264 struct needs_eigen_aligned_allocator : std::false_type {
265 };
266 template<typename T>
268 };
269
270}
271
277#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW \
278 EIGEN_MAKE_ALIGNED_OPERATOR_NEW \
279 using _eigen_aligned_allocator_trait = void;
280
286#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
287 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
288 using _eigen_aligned_allocator_trait = void;
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
ListOfOneContainer< T > ListOfOne(const T &element)
Factory function for ListOfOneContainer to enable ListOfOne(e) syntax.
Definition: types.h:147
std::string demangle(const char *name)
Pretty print Value type name.
Definition: types.cpp:37
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Definition: types.h:72
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:75
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:246
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
Helper class that uses templates to select between two types based on whether TEST_TYPE is const or n...
Definition: types.h:84
Helper struct that encapsulates a value with a default, this is just used as a member object so you d...
Definition: types.h:106
T & operator*()
Operator to access the value.
Definition: types.h:116
ValueWithDefault()
Default constructor, initialize to default value supplied in template argument.
Definition: types.h:110
ValueWithDefault(const T &_value)
Initialize to the given value.
Definition: types.h:113
A helper class that behaves as a container with one element, and works with boost::range.
Definition: types.h:129
An object whose scope defines a block where TBB and OpenMP parallelism are mixed.
Definition: types.h:161
A SFINAE trait to mark classes that need special alignment.
Definition: types.h:264