From a132286f73dce497fe7cb4e039dc156fc3ed1dd1 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Fri, 30 Dec 2022 16:03:02 +0100 Subject: [PATCH] Add output for subviews --- src/utils/Array.hpp | 12 ++++++++++++ src/utils/Table.hpp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp index 7535b6735..3ee64824a 100644 --- a/src/utils/Array.hpp +++ b/src/utils/Array.hpp @@ -24,6 +24,18 @@ class [[nodiscard]] Array const size_t m_size; public: + friend std::ostream& + operator<<(std::ostream& os, const UnsafeArrayView& 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; + } + [[nodiscard]] PUGS_INLINE size_t size() const { diff --git a/src/utils/Table.hpp b/src/utils/Table.hpp index 6972ea103..a4a134dfd 100644 --- a/src/utils/Table.hpp +++ b/src/utils/Table.hpp @@ -63,6 +63,19 @@ class [[nodiscard]] Table Assert(row < table.numberOfRows(), "required row view is not contained in the Table"); } + friend std::ostream& + operator<<(std::ostream& os, const UnsafeRowView& 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; + } + // To try to keep these views close to the initial array one // forbids copy constructor and take benefits of C++-17 copy // elisions. @@ -113,6 +126,19 @@ class [[nodiscard]] Table } } + friend std::ostream& + operator<<(std::ostream& os, const RowView& 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; + } + RowView(const UnsafeTableView& table_view, index_type row) : m_table_view{table_view}, m_row{row} { Assert(row < m_table_view.numberOfRows(), "required row view is not contained in the Table view"); @@ -155,6 +181,19 @@ class [[nodiscard]] Table return m_table(m_row_begin + i, m_column_begin + j); } + friend std::ostream& + operator<<(std::ostream& os, const UnsafeTableView& t) + { + for (size_t i = 0; i < t.numberOfRows(); ++i) { + os << i << '|'; + for (size_t j = 0; j < t.numberOfColumns(); ++j) { + os << ' ' << j << ':' << NaNHelper(t(i, j)); + } + os << '\n'; + } + return os; + } + PUGS_INLINE void fill(const DataType& data) const { -- GitLab