9#ifndef INCG1cc1076600024d7ea537871be7fc1fc0
10#define INCG1cc1076600024d7ea537871be7fc1fc0
16#include <spdlog/fmt/ranges.h>
21#include "lf_exception.h"
27struct IsEigenMatrixTester {
28 template <
class SCALAR,
int ROWS,
int COLS,
int OPTIONS,
int MAX_ROWS,
31 const Eigen::Matrix<SCALAR, ROWS, COLS, OPTIONS, MAX_ROWS, MAX_COLS>&,
35 static float Test(
const T&,
long);
38struct IsEigenArrayTester {
39 template <
class SCALAR,
int ROWS,
int COLS,
int OPTIONS,
int MAX_ROWS,
42 const Eigen::Array<SCALAR, ROWS, COLS, OPTIONS, MAX_ROWS, MAX_COLS>&,
46 static float Test(
const T&,
long);
69template <
class T,
class SCALAR = void,
int ROWS = -1,
int COLS = -1>
71 std::is_same_v<
decltype(internal::IsEigenMatrixTester::Test(
72 std::declval<T>(), 0)),
74 (std::same_as<SCALAR, void> || std::same_as<typename T::Scalar, SCALAR>) &&
76 std::remove_cvref_t<T>::RowsAtCompileTime == Eigen::Dynamic ||
77 std::remove_cvref_t<T>::RowsAtCompileTime == ROWS) &&
79 std::remove_cvref_t<T>::ColsAtCompileTime == Eigen::Dynamic ||
80 std::remove_cvref_t<T>::ColsAtCompileTime == COLS);
87 decltype(internal::IsEigenArrayTester::Test(std::declval<T>(), 0)),
bool>;
95template <
class MATRIX>
96 requires(std::is_base_of_v<Eigen::DenseBase<MATRIX>, MATRIX>)
97struct fmt::is_range<MATRIX, char> {
98 static constexpr const bool value =
false;
106template <
class MATRIX>
107 requires(std::is_base_of_v<Eigen::DenseBase<MATRIX>, MATRIX>)
108struct fmt::formatter<MATRIX> {
109 constexpr auto parse(
const format_parse_context& ctx) {
110 const auto* it = ctx.begin();
111 const auto* end = ctx.end();
113 if (it != end && *it ==
'.') {
117 while (is_digit(*it) && it != end) {
120 precision = parse_unsigned_int(start, it);
125 if (it != end && *it !=
'}') {
126 throw format_error(
"invalid format");
132 template <
typename FormatContext>
133 auto format(
const MATRIX& m, FormatContext& ctx)
const {
134 std::stringstream ss;
135 const Eigen::IOFormat format(precision, 0,
", ",
"\n",
"[",
"]");
136 ss << m.format(format);
140 std::copy(str.begin(), str.end(), it);
147 constexpr bool is_digit(
char c) {
return c <=
'9' && c >=
'0'; }
148 constexpr int parse_unsigned_int(
const char* begin,
const char* end) {
150 while (begin != end) {
151 if (!is_digit(*begin)) {
152 throw "compile time error, this is not a digit.";
154 result += (*begin -
'0');
158 result = result / 10;
Check if a given type T is a Eigen::Array<...>&
Check if a given type T is an Eigen::Matrix.
Contains basic functionality that is used by other parts of LehrFEM++.