13#ifndef INCLUDE_OPTIMIST_HH
14#define INCLUDE_OPTIMIST_HH
33#include <Eigen/Sparse>
34#include <Eigen/SparseLU>
38#define OPTIMIST_ERROR(MSG) \
40 std::ostringstream os; \
42 throw std::runtime_error(os.str()); \
47#ifndef OPTIMIST_ASSERT
48#define OPTIMIST_ASSERT(COND, MSG) \
50 OPTIMIST_ERROR(MSG); \
55#ifndef OPTIMIST_WARNING
56#define OPTIMIST_WARNING(MSG) \
57 { std::cout << MSG << std::endl; }
61#ifndef OPTIMIST_ASSERT_WARNING
62#define OPTIMIST_ASSERT_WARNING(COND, MSG) \
64 OPTIMIST_WARNING(MSG); \
69#ifndef OPTIMIST_BASIC_CONSTANTS
70#define OPTIMIST_BASIC_CONSTANTS(Scalar) \
71 static constexpr Scalar EPSILON{ \
72 std::numeric_limits<Scalar>::epsilon()}; \
74 static constexpr Scalar INFTY{ \
75 std::numeric_limits<Scalar>::infinity()}; \
77 static constexpr Scalar QUIET_NAN{ \
78 std::numeric_limits<Scalar>::quiet_NaN()}; \
80 inline static const Scalar SQRT_EPSILON{ \
81 std::sqrt(EPSILON)}; \
82 inline static const Scalar CBRT_EPSILON{ \
86#ifndef OPTIMIST_DEFAULT_INTEGER_TYPE
87#define OPTIMIST_DEFAULT_INTEGER_TYPE int
116 template <
typename T,
typename Enable =
void>
123 template <
typename ScalarType>
126 std::enable_if_t<std::is_floating_point<ScalarType>::value>> {
132 static constexpr bool IsFixed{
false};
133 static constexpr bool IsDynamic{
false};
134 static constexpr bool IsSparse{
false};
143 template <
typename ScalarType, Integer N, Integer M>
145 std::enable_if_t<(N > 0 && M > 0)>> {
147 using Type = Eigen::Matrix<ScalarType, N, M>;
151 static constexpr bool IsFixed{
true};
152 static constexpr bool IsDynamic{
false};
153 static constexpr bool IsSparse{
false};
160 template <
typename ScalarType>
161 struct TypeTrait<Eigen::Matrix<ScalarType, Eigen::Dynamic, 1>> {
163 using Type = Eigen::Matrix<ScalarType, Eigen::Dynamic, 1>;
167 static constexpr bool IsFixed{
false};
168 static constexpr bool IsDynamic{
true};
169 static constexpr bool IsSparse{
false};
176 template <
typename ScalarType>
177 struct TypeTrait<Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic>> {
179 using Type = Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic>;
183 static constexpr bool IsFixed{
false};
184 static constexpr bool IsDynamic{
true};
185 static constexpr bool IsSparse{
false};
192 template <
typename ScalarType>
195 using Type = Eigen::SparseVector<ScalarType>;
199 static constexpr bool IsFixed{
false};
200 static constexpr bool IsDynamic{
false};
201 static constexpr bool IsSparse{
true};
208 template <
typename ScalarType, Integer Options,
typename StorageIndex>
209 struct TypeTrait<Eigen::SparseMatrix<ScalarType, Options, StorageIndex>> {
211 using Type = Eigen::SparseMatrix<ScalarType, Options, StorageIndex>;
215 static constexpr bool IsFixed{
false};
216 static constexpr bool IsDynamic{
false};
217 static constexpr bool IsSparse{
true};
231 template <
typename T>
234 template <
template <
typename,
auto...>
class BaseType,
238 using Full = BaseType<FirstType, Rest...>;
239 using First = FirstType;
341 for (
Integer i{0}; i < N; ++i) {
#define OPTIMIST_DEFAULT_INTEGER_TYPE
Definition Optimist.hh:84
Namespace for the Optimist library.
Definition Optimist.hh:90
static constexpr std::string_view table_horizontal_line()
Retrieve the Unicode character for the horizontal line of a table.
Definition Optimist.hh:325
static constexpr std::string_view table_top_left_corner()
Retrieve the Unicode character for the top-left corner of a table.
Definition Optimist.hh:251
static constexpr std::string_view table_top_junction()
Retrieve the Unicode character for the top junction of a table.
Definition Optimist.hh:301
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:98
static constexpr std::string_view table_center_cross()
Retrieve the Unicode character for the center cross of a table.
Definition Optimist.hh:317
static constexpr std::string_view table_bottom_right_corner()
Retrieve the Unicode character for the bottom-right corner of a table.
Definition Optimist.hh:277
static constexpr std::string_view table_right_junction()
Retrieve the Unicode character for the right junction of a table.
Definition Optimist.hh:293
static constexpr std::string_view table_bottom_left_corner()
Retrieve the Unicode character for the bottom-left corner of a table.
Definition Optimist.hh:268
static constexpr std::string_view table_vertical_line()
Retrieve the Unicode character for the vertical line of a table.
Definition Optimist.hh:348
static constexpr std::string_view table_bottom_junction()
Retrieve the Unicode character for the bottom junction of a table.
Definition Optimist.hh:309
static constexpr std::string_view table_top_right_corner()
Retrieve the Unicode character for the top-right corner of a table.
Definition Optimist.hh:259
static constexpr std::string_view table_left_junction()
Retrieve the Unicode character for the left junction of a table.
Definition Optimist.hh:285
BaseType< FirstType, Rest... > Full
Definition Optimist.hh:235
FirstType First
Definition Optimist.hh:236
Definition Optimist.hh:229
static constexpr bool IsScalar
Definition Optimist.hh:162
ScalarType Scalar
Definition Optimist.hh:159
Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > Type
Definition Optimist.hh:160
static constexpr bool IsEigen
Definition Optimist.hh:163
static constexpr Integer Dimension
Definition Optimist.hh:161
static constexpr Integer Dimension
Definition Optimist.hh:177
ScalarType Scalar
Definition Optimist.hh:175
static constexpr bool IsScalar
Definition Optimist.hh:178
static constexpr bool IsEigen
Definition Optimist.hh:179
Eigen::Matrix< ScalarType, Eigen::Dynamic, Eigen::Dynamic > Type
Definition Optimist.hh:176
static constexpr bool IsEigen
Definition Optimist.hh:147
ScalarType Scalar
Definition Optimist.hh:143
static constexpr Integer Dimension
Definition Optimist.hh:145
Eigen::Matrix< ScalarType, N, M > Type
Definition Optimist.hh:144
static constexpr bool IsScalar
Definition Optimist.hh:146
Eigen::SparseMatrix< ScalarType, Options, StorageIndex > Type
Definition Optimist.hh:208
ScalarType Scalar
Definition Optimist.hh:207
static constexpr bool IsEigen
Definition Optimist.hh:211
static constexpr Integer Dimension
Definition Optimist.hh:209
static constexpr bool IsScalar
Definition Optimist.hh:210
Eigen::SparseVector< ScalarType > Type
Definition Optimist.hh:192
ScalarType Scalar
Definition Optimist.hh:191
static constexpr Integer Dimension
Definition Optimist.hh:193
static constexpr bool IsEigen
Definition Optimist.hh:195
static constexpr bool IsScalar
Definition Optimist.hh:194
ScalarType Type
Definition Optimist.hh:125
static constexpr Integer Dimension
Definition Optimist.hh:126
ScalarType Scalar
Definition Optimist.hh:124
static constexpr bool IsScalar
Definition Optimist.hh:127
static constexpr bool IsEigen
Definition Optimist.hh:128
Definition Optimist.hh:114