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)
49 #if FMT_VERSION >= 100200
53 #include <type_traits>
56struct fmt::formatter<T, std::enable_if_t<std::is_base_of<Eigen::DenseBase<T>, T>::value, char>>
57 : fmt::nested_formatter<typename T::Scalar>
59 auto format(T
const& a, format_context& ctx)
const
61 return this->write_padded(ctx, [&](
auto out) {
62 for (Eigen::Index ir = 0; ir < a.rows(); ir++) {
63 for (Eigen::Index ic = 0; ic < a.cols(); ic++) {
64 out = fmt::format_to(out,
"{} ", this->nested(a(ir, ic)));
66 if (ir + 1 < a.rows()) {
67 out = fmt::format_to(out,
"\n");
75template <
typename Derived>
78 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>
83 #elif (FMT_VERSION >= 100000) || (FMT_VERSION >= 90000 && !defined(FMT_DEPRECATED_OSTREAM)) || \
84 (defined(LAGRANGE_FMT_EIGEN_FIX) && defined(_MSC_VER))
101 #include <type_traits>
103template <
typename Derived>
104struct fmt::formatter<
106 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>
108 template <
typename ParseContext>
109 constexpr auto parse(ParseContext& ctx)
111 return m_underlying.parse(ctx);
114 template <
typename FormatContext>
115 auto format(
const Derived& mat, FormatContext& ctx)
const
117 auto out = ctx.out();
119 for (Eigen::Index row = 0; row < mat.rows(); ++row) {
120 for (Eigen::Index col = 0; col < mat.cols(); ++col) {
121 out = fmt::format_to(out,
" ");
122 out = m_underlying.format(mat.coeff(row, col), ctx);
125 if (row < mat.rows() - 1) {
126 out = fmt::format_to(out,
"\n");
134 fmt::formatter<typename Derived::Scalar, char> m_underlying;
137template <
typename Derived>
140 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>
150 #include <lagrange/utils/warnoff.h>
151 #include <spdlog/fmt/ostr.h>
152 #include <lagrange/utils/warnon.h>
155template <
typename Derived>
158 std::enable_if_t<std::is_base_of<Eigen::DenseBase<Derived>, Derived>::value, char>>