38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <Eigen/Dense>
|
|
// #include <Eigen/src/Core/util/ForwardDeclarations.h>
|
|
#include <spdlog/fmt/ostr.h>
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
|
/// @brief Boilerplate code to enable fmtlib to print Eigen::MatrixXd
|
|
template <>
|
|
struct fmt::formatter<Eigen::MatrixXd> : fmt::ostream_formatter {};
|
|
/// @brief Boilerplate code to enable fmtlib to print Eigen::VectorXd
|
|
template <>
|
|
struct fmt::formatter<Eigen::VectorXd> : fmt::ostream_formatter {
|
|
|
|
template <typename Context>
|
|
auto format(const Eigen::VectorXd& value, Context& ctx) const
|
|
-> decltype(ctx.out()) {
|
|
|
|
auto buffer = basic_memory_buffer<char>();
|
|
auto&& formatbuf =
|
|
detail::formatbuf<std::basic_streambuf<char>>(buffer);
|
|
auto&& output = std::basic_ostream<char>(&formatbuf);
|
|
output.imbue(std::locale::classic());
|
|
|
|
output << "[";
|
|
for (int i = 0; i < value.size(); ++i) {
|
|
output << value(i);
|
|
if (i < value.size() - 1) output << ", ";
|
|
}
|
|
output << "]";
|
|
|
|
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
|
return formatter<basic_string_view<char>, char>::format(
|
|
{buffer.data(), buffer.size()}, ctx);
|
|
}
|
|
};
|