22 #include <gtsam/dllexport.h>
23 #include <gtsam/config.h>
28 #include <boost/function/function1.hpp>
29 #include <boost/range/concepts.hpp>
30 #include <boost/optional.hpp>
33 #include <tbb/task_scheduler_init.h>
34 #include <tbb/tbb_exception.h>
35 #include <tbb/scalable_allocator.h>
38 #ifdef GTSAM_USE_EIGEN_MKL_OPENMP
43 # define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag) \
44 _Pragma("clang diagnostic push") \
45 _Pragma("clang diagnostic ignored \"" diag "\"")
47 # define CLANG_DIAGNOSTIC_PUSH_IGNORE(diag)
51 # define CLANG_DIAGNOSTIC_POP() _Pragma("clang diagnostic pop")
53 # define CLANG_DIAGNOSTIC_POP()
65 GTSAM_EXPORT std::string _defaultKeyFormatter(
Key key);
70 static const KeyFormatter DefaultKeyFormatter = &_defaultKeyFormatter;
82 template<
typename TEST_TYPE,
typename BASIC_TYPE,
typename AS_NON_CONST,
88 template<
typename BASIC_TYPE,
typename AS_NON_CONST,
typename AS_CONST>
90 typedef AS_NON_CONST type;
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;
105 template<
typename T, T defaultValue>
122 operator T()
const {
return value; }
132 typedef T value_type;
133 typedef const T* const_iterator;
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; }
153 template<
class DERIVED>
156 public tbb::tbb_exception
158 public std::exception
163 typedef tbb::tbb_exception Base;
165 typedef std::basic_string<char, std::char_traits<char>, tbb::tbb_allocator<char> > String;
168 typedef std::exception Base;
170 typedef std::string String;
192 virtual tbb::tbb_exception* move() throw () {
193 void* cloneMemory = scalable_malloc(
sizeof(DERIVED));
195 std::cerr <<
"Failed allocating memory to copy thrown exception, exiting now." << std::endl;
198 DERIVED* clone = ::new(cloneMemory) DERIVED(static_cast<DERIVED&>(*this));
203 virtual
void destroy() throw() {
205 DERIVED* derivedPtr =
static_cast<DERIVED*
>(
this);
206 derivedPtr->~DERIVED();
207 scalable_free(derivedPtr);
211 virtual void throw_self() {
212 throw *
static_cast<DERIVED*
>(
this); }
214 virtual const char* name()
const throw() {
215 return typeid(DERIVED).name(); }
218 virtual const char* what()
const throw() {
251 # pragma clang diagnostic push
252 # pragma clang diagnostic ignored "-Wunused-private-field" // Clang complains that previousOpenMPThreads is unused in the #else case below
260 int previousOpenMPThreads;
263 #if defined GTSAM_USE_TBB && defined GTSAM_USE_EIGEN_MKL_OPENMP
265 previousOpenMPThreads(omp_get_num_threads())
267 omp_set_num_threads(omp_get_num_procs() / 4);
272 omp_set_num_threads(previousOpenMPThreads);
281 # pragma clang diagnostic pop
290 #define assert_throw(CONDITION, EXCEPTION) ((void)0)
292 #define assert_throw(CONDITION, EXCEPTION) \
293 if (!(CONDITION)) { \
302 #if (_MSC_VER < 1800)
304 #include <boost/math/special_functions/fpclassify.hpp>
306 template<
typename T>
inline int isfinite(T a) {
307 return (
int)boost::math::isfinite(a); }
308 template<
typename T>
inline int isnan(T a) {
309 return (
int)boost::math::isnan(a); }
310 template<
typename T>
inline int isinf(T a) {
311 return (
int)boost::math::isinf(a); }
316 #include <boost/math/constants/constants.hpp>
318 #define M_PI (boost::math::constants::pi<double>())
321 #define M_PI_2 (boost::math::constants::pi<double>() / 2.0)
324 #define M_PI_4 (boost::math::constants::pi<double>() / 4.0)
Threadsafe runtime error exception.
Definition: types.h:233
ThreadsafeException(const ThreadsafeException &other)
Copy constructor is protected - may only be created from derived classes.
Definition: types.h:181
RuntimeErrorThreadsafe(const std::string &description)
Construct with a string describing the exception.
Definition: types.h:228
A helper class that behaves as a container with one element, and works with boost::range.
Definition: types.h:129
Base exception type that uses tbb_exception if GTSAM is compiled with TBB.
Definition: types.h:154
ThreadsafeException(const std::string &description)
Construct with description string.
Definition: types.h:184
Helper class that uses templates to select between two types based on whether TEST_TYPE is const or n...
Definition: types.h:84
Threadsafe invalid argument exception.
Definition: types.h:242
const T & operator*() const
Operator to access the value.
Definition: types.h:119
Threadsafe runtime error exception.
Definition: types.h:224
size_t Key
Integer nonlinear key type.
Definition: types.h:59
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
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:74
bool dynamic_
Whether this object was moved.
Definition: types.h:174
InvalidArgumentThreadsafe(const std::string &description)
Construct with a string describing the exception.
Definition: types.h:246
boost::optional< String > description_
Optional description.
Definition: types.h:175
Helper struct that encapsulates a value with a default, this is just used as a member object so you d...
Definition: types.h:106
virtual ~ThreadsafeException()
Default destructor doesn't have the throw()
Definition: types.h:187
ValueWithDefault(const T &_value)
Initialize to the given value.
Definition: types.h:113
OutOfRangeThreadsafe(const std::string &description)
Construct with a string describing the exception.
Definition: types.h:237
ThreadsafeException()
Default constructor is protected - may only be created from derived classes.
Definition: types.h:178
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62
ListOfOneContainer< T > ListOfOne(const T &element)
Factory function for ListOfOneContainer to enable ListOfOne(e) syntax.
Definition: types.h:147
An object whose scope defines a block where TBB and OpenMP parallelism are mixed. ...
Definition: types.h:258