WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
Eigen.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <concepts>
8
9#include <Eigen/Core>
10#include <Eigen/SparseCore>
11#include <fmt/format.h>
12
13// FIXME: Doxygen gives internal inconsistency errors:
14
15//! @cond Doxygen_Suppress
16
17/**
18 * Formatter for classes derived from Eigen::DenseBase<Derived> or
19 * Eigen::SparseCompressedBase<Derived>.
20 */
21template <typename Derived, typename CharT>
22 requires std::derived_from<Derived, Eigen::DenseBase<Derived>> ||
23 std::derived_from<Derived, Eigen::SparseCompressedBase<Derived>>
24struct fmt::formatter<Derived, CharT> {
25 template <typename ParseContext>
26 constexpr auto parse(ParseContext& ctx) {
27 return m_underlying.parse(ctx);
28 }
29
30 template <typename FmtContext>
31 auto format(const Derived& mat, FmtContext& ctx) const {
32 auto out = ctx.out();
33
34 for (int row = 0; row < mat.rows(); ++row) {
35 for (int col = 0; col < mat.cols(); ++col) {
36 out = fmt::format_to(out, " ");
37 out = m_underlying.format(mat.coeff(row, col), ctx);
38 }
39
40 if (row < mat.rows() - 1) {
41 out = fmt::format_to(out, "\n");
42 }
43 }
44
45 return out;
46 }
47
48 private:
49 fmt::formatter<typename Derived::Scalar, CharT> m_underlying;
50};
51//! @endcond
FMT_INLINE auto format(detail::locale_ref loc, format_string< T... > fmt, T &&... args) -> std::string
Definition format.h:4146