From 41ddf6589e326625ff45a9d1b6a43a12c313d19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Tue, 23 Jul 2024 16:14:02 +0200 Subject: [PATCH] Allow output of ShrinkVectorView and ShrinkMatrixView --- src/algebra/ShrinkMatrixView.hpp | 15 +++++++++++++++ src/algebra/ShrinkVectorView.hpp | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/algebra/ShrinkMatrixView.hpp b/src/algebra/ShrinkMatrixView.hpp index a93efc07a..a41089a0a 100644 --- a/src/algebra/ShrinkMatrixView.hpp +++ b/src/algebra/ShrinkMatrixView.hpp @@ -5,6 +5,8 @@ #include <utils/PugsMacros.hpp> #include <cstddef> +#include <iostream> +#include <utils/NaNHelper.hpp> template <typename MatrixType> class ShrinkMatrixView @@ -18,6 +20,19 @@ class ShrinkMatrixView const size_t m_nb_rows; public: + friend std::ostream& + operator<<(std::ostream& os, const ShrinkMatrixView& A) + { + for (size_t i = 0; i < A.numberOfRows(); ++i) { + os << i << '|'; + for (size_t j = 0; j < A.numberOfColumns(); ++j) { + os << ' ' << j << ':' << NaNHelper(A(i, j)); + } + os << '\n'; + } + return os; + } + PUGS_INLINE size_t numberOfRows() const noexcept { diff --git a/src/algebra/ShrinkVectorView.hpp b/src/algebra/ShrinkVectorView.hpp index dc5faa800..cdf786c5a 100644 --- a/src/algebra/ShrinkVectorView.hpp +++ b/src/algebra/ShrinkVectorView.hpp @@ -5,6 +5,8 @@ #include <utils/PugsMacros.hpp> #include <cstddef> +#include <iostream> +#include <utils/NaNHelper.hpp> template <typename VectorType> class ShrinkVectorView @@ -18,6 +20,18 @@ class ShrinkVectorView const size_t m_dimension; public: + friend std::ostream& + operator<<(std::ostream& os, const ShrinkVectorView& x) + { + if (x.size() > 0) { + os << 0 << ':' << NaNHelper(x[0]); + } + for (size_t i = 1; i < x.size(); ++i) { + os << ' ' << i << ':' << NaNHelper(x[i]); + } + return os; + } + PUGS_INLINE size_t dimension() const noexcept { -- GitLab