gtsam
Loading...
Searching...
No Matches
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
19
20#pragma once
21
22#include <gtsam/config.h> // for GTSAM_USE_TBB
23#include <gtsam/dllexport.h>
24
25#include <cstddef>
26#include <cstdint>
27#include <string>
28
29#ifdef GTSAM_USE_TBB
30#include <tbb/scalable_allocator.h>
31#endif
32
33#ifdef GTSAM_USE_EIGEN_MKL_OPENMP
34#include <omp.h>
35#endif
36
37namespace gtsam {
38
40 std::string GTSAM_EXPORT demangle(const char* name);
41
43 typedef std::uint64_t Key;
44
46 typedef std::uint64_t FactorIndex;
47
49 typedef ptrdiff_t DenseIndex;
50
51 /* ************************************************************************* */
57 template<typename T, T defaultValue>
59 T value;
60
62 ValueWithDefault() : value(defaultValue) {}
63
65 ValueWithDefault(const T& _value) : value(_value) {}
66
68 T& operator*() { return value; }
69
71 const T& operator*() const { return value; }
72
74 operator T() const { return value; }
75 };
76
77 /* ************************************************************************* */
78#ifdef __clang__
79# pragma clang diagnostic push
80# pragma clang diagnostic ignored "-Wunused-private-field" // Clang complains that previousOpenMPThreads is unused in the #else case below
81#endif
82
86 class TbbOpenMPMixedScope
87 {
88 int previousOpenMPThreads;
89
90 public:
91#if defined GTSAM_USE_TBB && defined GTSAM_USE_EIGEN_MKL_OPENMP
92 TbbOpenMPMixedScope() :
93 previousOpenMPThreads(omp_get_num_threads())
94 {
95 omp_set_num_threads(omp_get_num_procs() / 4);
96 }
97
98 ~TbbOpenMPMixedScope()
99 {
100 omp_set_num_threads(previousOpenMPThreads);
101 }
102#else
103 TbbOpenMPMixedScope() : previousOpenMPThreads(-1) {}
104 ~TbbOpenMPMixedScope() {}
105#endif
106 };
107
108#ifdef __clang__
109# pragma clang diagnostic pop
110#endif
111
112}
113
114/* ************************************************************************* */
117#ifdef NDEBUG
118#define assert_throw(CONDITION, EXCEPTION) ((void)0)
119#else
120#define assert_throw(CONDITION, EXCEPTION) \
121 if (!(CONDITION)) { \
122 throw (EXCEPTION); \
123 }
124#endif
125
126#ifdef min
127#undef min
128#endif
129
130#ifdef max
131#undef max
132#endif
133
134#ifdef ERROR
135#undef ERROR
136#endif
Global functions in a separate testing namespace.
Definition chartTesting.h:28
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:46
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition types.h:49
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
T & operator*()
Operator to access the value.
Definition types.h:68
const T & operator*() const
Operator to access the value.
Definition types.h:71
ValueWithDefault()
Default constructor, initialize to default value supplied in template argument.
Definition types.h:62
ValueWithDefault(const T &_value)
Initialize to the given value.
Definition types.h:65