// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. #pragma once #include #include #include "Eigen/Core" #include "Eigen/SparseCore" /** * Formatter for classes derived from Eigen::MatrixBase or * Eigen::SparseCompressedBase. */ template requires std::derived_from> || std::derived_from> struct fmt::formatter { constexpr auto parse(fmt::format_parse_context& ctx) { return m_underlying.parse(ctx); } auto format(const Derived& mat, fmt::format_context& ctx) const { auto out = ctx.out(); for (int row = 0; row < mat.rows(); ++row) { for (int col = 0; col < mat.cols(); ++col) { out = fmt::format_to(out, " "); out = m_underlying.format(mat.coeff(row, col), ctx); } if (row < mat.rows() - 1) { out = fmt::format_to(out, "\n"); } } return out; } private: fmt::formatter m_underlying; };