28#include <lagrange/utils/warnoff.h>
29#include <spdlog/spdlog.h>
30#include <spdlog/fmt/fmt.h>
31#include <spdlog/fmt/ranges.h>
32#include <lagrange/utils/warnon.h>
37#ifdef LA_FMT_EIGEN_FORMATTER
40 #include LA_FMT_EIGEN_FORMATTER
42#elif defined(SPDLOG_USE_STD_FORMAT)
45 #include <type_traits>
48struct std::formatter<T, std::enable_if_t<std::is_base_of_v<Eigen::DenseBase<T>, T>, char>>
50 std::formatter<typename T::Scalar, char> m_scalar;
52 constexpr auto parse(std::format_parse_context& ctx) {
return m_scalar.parse(ctx); }
54 auto format(T
const& a, std::format_context& ctx)
const
57 for (Eigen::Index ir = 0; ir < a.rows(); ir++) {
58 for (Eigen::Index ic = 0; ic < a.cols(); ic++) {
59 out = m_scalar.format(a(ir, ic), ctx);
62 if (ir + 1 < a.rows()) {
73 #if FMT_VERSION >= 100200
77 #include <type_traits>
80struct fmt::formatter<T, std::enable_if_t<std::is_base_of<Eigen::DenseBase<T>, T>::value, char>>
81 : fmt::nested_formatter<typename T::Scalar>
83 auto format(T
const& a, format_context& ctx)
const
85 return this->write_padded(ctx, [&](
auto out) {
86 for (Eigen::Index ir = 0; ir < a.rows(); ir++) {
87 for (Eigen::Index ic = 0; ic < a.cols(); ic++) {
88 out = fmt::format_to(out,
"{} ", this->nested(a(ir, ic)));
90 if (ir + 1 < a.rows()) {
91 out = fmt::format_to(out,
"\n");
99template <
typename Derived>
102 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>
107 #elif (FMT_VERSION >= 100000) || (FMT_VERSION >= 90000 && !defined(FMT_DEPRECATED_OSTREAM)) || \
108 (defined(LAGRANGE_FMT_EIGEN_FIX) && defined(_MSC_VER))
125 #include <type_traits>
127template <
typename Derived>
128struct fmt::formatter<
130 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>
132 template <
typename ParseContext>
133 constexpr auto parse(ParseContext& ctx)
135 return m_underlying.parse(ctx);
138 template <
typename FormatContext>
139 auto format(
const Derived& mat, FormatContext& ctx)
const
141 auto out = ctx.out();
143 for (Eigen::Index row = 0; row < mat.rows(); ++row) {
144 for (Eigen::Index col = 0; col < mat.cols(); ++col) {
145 out = fmt::format_to(out,
" ");
146 out = m_underlying.format(mat.coeff(row, col), ctx);
149 if (row < mat.rows() - 1) {
150 out = fmt::format_to(out,
"\n");
158 fmt::formatter<typename Derived::Scalar, char> m_underlying;
161template <
typename Derived>
164 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>
174 #include <lagrange/utils/warnoff.h>
175 #include <spdlog/fmt/ostr.h>
176 #include <lagrange/utils/warnon.h>
179template <
typename Derived>
182 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>