13#ifndef INCLUDE_OPTIMIST_HH
14#define INCLUDE_OPTIMIST_HH
32#include <Eigen/Sparse>
33#include <Eigen/SparseLU>
37#define OPTIMIST_ERROR(MSG) \
39 std::ostringstream os; \
41 throw std::runtime_error(os.str()); \
46#ifndef OPTIMIST_ASSERT
47#define OPTIMIST_ASSERT(COND, MSG) \
49 OPTIMIST_ERROR(MSG); \
54#ifndef OPTIMIST_WARNING
55#define OPTIMIST_WARNING(MSG) \
56 { std::cout << MSG << std::endl; }
60#ifndef OPTIMIST_ASSERT_WARNING
61#define OPTIMIST_ASSERT_WARNING(COND, MSG) \
63 OPTIMIST_WARNING(MSG); \
68#ifndef OPTIMIST_BASIC_CONSTANTS
69#define OPTIMIST_BASIC_CONSTANTS(Scalar) \
70 static constexpr Scalar EPSILON{ \
71 std::numeric_limits<Scalar>::epsilon()}; \
73 static constexpr Scalar INFTY{ \
74 std::numeric_limits<Scalar>::infinity()}; \
76 static constexpr Scalar QUIET_NAN{ \
77 std::numeric_limits<Scalar>::quiet_NaN()}; \
79 inline static const Scalar SQRT_EPSILON{ \
80 std::sqrt(EPSILON)}; \
81 inline static const Scalar CBRT_EPSILON{ \
85#ifndef OPTIMIST_DEFAULT_INTEGER_TYPE
86#define OPTIMIST_DEFAULT_INTEGER_TYPE int
115 template <
typename T,
typename Enable =
void>
122 template <
typename ScalarType>
125 std::enable_if_t<std::is_floating_point<ScalarType>::value>> {
131 static constexpr bool IsFixed{
false};
132 static constexpr bool IsDynamic{
false};
133 static constexpr bool IsSparse{
false};
142 template <
typename ScalarType, Integer N, Integer M>
144 std::enable_if_t<(N > 0 && M > 0)>> {
146 using Type = Eigen::Matrix<ScalarType, N, M>;
150 static constexpr bool IsFixed{
true};
151 static constexpr bool IsDynamic{
false};
152 static constexpr bool IsSparse{
false};
159 template <
typename ScalarType>
160 struct TypeTrait<Eigen::Matrix<ScalarType, Eigen::Dynamic, 1>> {
162 using Type = Eigen::Matrix<ScalarType, Eigen::Dynamic, 1>;
166 static constexpr bool IsFixed{
false};
167 static constexpr bool IsDynamic{
true};
168 static constexpr bool IsSparse{
false};
175 template <
typename ScalarType>
176 struct TypeTrait<Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic>> {
178 using Type = Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic>;
182 static constexpr bool IsFixed{
false};
183 static constexpr bool IsDynamic{
true};
184 static constexpr bool IsSparse{
false};
191 template <
typename ScalarType>
194 using Type = Eigen::SparseVector<ScalarType>;
198 static constexpr bool IsFixed{
false};
199 static constexpr bool IsDynamic{
false};
200 static constexpr bool IsSparse{
true};
207 template <
typename ScalarType, Integer Options,
typename StorageIndex>
208 struct TypeTrait<Eigen::SparseMatrix<ScalarType, Options, StorageIndex>> {
210 using Type = Eigen::SparseMatrix<ScalarType, Options, StorageIndex>;
214 static constexpr bool IsFixed{
false};
215 static constexpr bool IsDynamic{
false};
216 static constexpr bool IsSparse{
true};
230 template <
typename T>
233 template <
template <
typename,
auto...>
class BaseType,
237 using Full = BaseType<FirstType, Rest...>;
238 using First = FirstType;
254 return std::string(
"┌");
262 return std::string(
"┐");
271 return std::string(
"└");
280 return std::string(
"┘");
288 return std::string(
"├");
296 return std::string(
"┤");
304 return std::string(
"┬");
312 return std::string(
"┴");
320 return std::string(
"┼");
328 return std::string(
"─");
340 for (
Integer i{0}; i < N; ++i) {
351 return std::string(
"│");
#define OPTIMIST_DEFAULT_INTEGER_TYPE
Definition Optimist.hh:83
Namespace for the Optimist library.
Definition Optimist.hh:89
static constexpr std::string table_top_right_corner()
Retrieve the Unicode character for the top-right corner of a table.
Definition Optimist.hh:258
static constexpr std::string table_top_junction()
Retrieve the Unicode character for the top junction of a table.
Definition Optimist.hh:300
static constexpr std::string table_center_cross()
Retrieve the Unicode character for the center cross of a table.
Definition Optimist.hh:316
static constexpr std::string table_top_left_corner()
Retrieve the Unicode character for the top-left corner of a table.
Definition Optimist.hh:250
static constexpr std::string table_vertical_line()
Retrieve the Unicode character for the vertical line of a table.
Definition Optimist.hh:347
static constexpr std::string table_bottom_junction()
Retrieve the Unicode character for the bottom junction of a table.
Definition Optimist.hh:308
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:97
static constexpr std::string table_left_junction()
Retrieve the Unicode character for the left junction of a table.
Definition Optimist.hh:284
static constexpr std::string table_bottom_right_corner()
Retrieve the Unicode character for the bottom-right corner of a table.
Definition Optimist.hh:276
static constexpr std::string table_right_junction()
Retrieve the Unicode character for the right junction of a table.
Definition Optimist.hh:292
static constexpr std::string table_bottom_left_corner()
Retrieve the Unicode character for the bottom-left corner of a table.
Definition Optimist.hh:267
static constexpr std::string table_horizontal_line()
Retrieve the Unicode character for the horizontal line of a table.
Definition Optimist.hh:324
BaseType< FirstType, Rest... > Full
Definition Optimist.hh:234
FirstType First
Definition Optimist.hh:235
Definition Optimist.hh:228
static constexpr bool IsScalar
Definition Optimist.hh:161
ScalarType Scalar
Definition Optimist.hh:158
Eigen::Matrix< ScalarType, Eigen::Dynamic, 1 > Type
Definition Optimist.hh:159
static constexpr bool IsEigen
Definition Optimist.hh:162
static constexpr Integer Dimension
Definition Optimist.hh:160
static constexpr Integer Dimension
Definition Optimist.hh:176
ScalarType Scalar
Definition Optimist.hh:174
static constexpr bool IsScalar
Definition Optimist.hh:177
static constexpr bool IsEigen
Definition Optimist.hh:178
Eigen::Matrix< ScalarType, Eigen::Dynamic, Eigen::Dynamic > Type
Definition Optimist.hh:175
static constexpr bool IsEigen
Definition Optimist.hh:146
ScalarType Scalar
Definition Optimist.hh:142
static constexpr Integer Dimension
Definition Optimist.hh:144
Eigen::Matrix< ScalarType, N, M > Type
Definition Optimist.hh:143
static constexpr bool IsScalar
Definition Optimist.hh:145
Eigen::SparseMatrix< ScalarType, Options, StorageIndex > Type
Definition Optimist.hh:207
ScalarType Scalar
Definition Optimist.hh:206
static constexpr bool IsEigen
Definition Optimist.hh:210
static constexpr Integer Dimension
Definition Optimist.hh:208
static constexpr bool IsScalar
Definition Optimist.hh:209
Eigen::SparseVector< ScalarType > Type
Definition Optimist.hh:191
ScalarType Scalar
Definition Optimist.hh:190
static constexpr Integer Dimension
Definition Optimist.hh:192
static constexpr bool IsEigen
Definition Optimist.hh:194
static constexpr bool IsScalar
Definition Optimist.hh:193
ScalarType Type
Definition Optimist.hh:124
static constexpr Integer Dimension
Definition Optimist.hh:125
ScalarType Scalar
Definition Optimist.hh:123
static constexpr bool IsScalar
Definition Optimist.hh:126
static constexpr bool IsEigen
Definition Optimist.hh:127
Definition Optimist.hh:113