From 290cefb46d4093a74e2646e5a783f9e6f8c4edd8 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 1 Apr 2024 14:24:12 -0700 Subject: [PATCH] [wpimath] Support formatting Eigen array types --- wpimath/src/main/native/include/frc/fmt/Eigen.h | 4 ++-- wpimath/src/test/native/cpp/FormatterTest.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/wpimath/src/main/native/include/frc/fmt/Eigen.h b/wpimath/src/main/native/include/frc/fmt/Eigen.h index 2438b9f1de6..3adfaec5695 100644 --- a/wpimath/src/main/native/include/frc/fmt/Eigen.h +++ b/wpimath/src/main/native/include/frc/fmt/Eigen.h @@ -11,11 +11,11 @@ #include /** - * Formatter for classes derived from Eigen::MatrixBase or + * Formatter for classes derived from Eigen::DenseBase or * Eigen::SparseCompressedBase. */ template - requires std::derived_from> || + requires std::derived_from> || std::derived_from> struct fmt::formatter { constexpr auto parse(fmt::format_parse_context& ctx) { diff --git a/wpimath/src/test/native/cpp/FormatterTest.cpp b/wpimath/src/test/native/cpp/FormatterTest.cpp index 0b6d5904988..f1d2d46594b 100644 --- a/wpimath/src/test/native/cpp/FormatterTest.cpp +++ b/wpimath/src/test/native/cpp/FormatterTest.cpp @@ -25,19 +25,22 @@ TEST(FormatterTest, Eigen) { " 4.000000 5.000000", fmt::format("{:f}", B)); - Eigen::SparseMatrix C{3, 2}; + Eigen::Array2d C{0.0, 1.0}; + EXPECT_EQ(" 0.000000\n 1.000000", fmt::format("{:f}", C)); + + Eigen::SparseMatrix D{3, 2}; std::vector> triplets; triplets.emplace_back(0, 1, 1.0); triplets.emplace_back(1, 0, 2.0); triplets.emplace_back(1, 1, 3.0); triplets.emplace_back(2, 0, 4.0); triplets.emplace_back(2, 1, 5.0); - C.setFromTriplets(triplets.begin(), triplets.end()); + D.setFromTriplets(triplets.begin(), triplets.end()); EXPECT_EQ( " 0.000000 1.000000\n" " 2.000000 3.000000\n" " 4.000000 5.000000", - fmt::format("{:f}", C)); + fmt::format("{:f}", D)); } TEST(FormatterTest, Units) {