From ed0449a8cc556eefd07c0dbf952cc899e64de706 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Fri, 5 Jan 2024 14:58:18 -0500 Subject: [PATCH] add signatures for blocks --- src/stan/callbacks/unique_stream_writer.hpp | 33 +++++++++++++++++++++ src/stan/callbacks/writer.hpp | 21 +++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/stan/callbacks/unique_stream_writer.hpp b/src/stan/callbacks/unique_stream_writer.hpp index 24df4d9a4a..7fe4f3b594 100644 --- a/src/stan/callbacks/unique_stream_writer.hpp +++ b/src/stan/callbacks/unique_stream_writer.hpp @@ -127,6 +127,39 @@ class unique_stream_writer final : public writer { ", ", "", "", "\n", "", ""); *output_ << values.transpose().format(CommaInitFmt); } + /** + * Writes a set of values in csv format followed by a newline. + * + * Note: the precision of the output is determined by the settings + * of the stream on construction. + * + * @param[in] v Values in a block representing an Eigen column vector + */ + virtual void operator()(const Eigen::Block, -1, 1, true>) { + if (output_ == nullptr) + return; + Eigen::IOFormat CommaInitFmt(Eigen::StreamPrecision, Eigen::DontAlignCols, + ", ", "", "", "\n", "", ""); + *output_ << values.transpose().format(CommaInitFmt); + } + + /** + * Writes a set of values in csv format followed by a newline. + * + * Note: the precision of the output is determined by the settings + * of the stream on construction. + * + * @param[in] v Values in a block representing an Eigen row vector + */ + virtual void operator()(const Eigen::Block, 1, -1, true>) { + if (output_ == nullptr) + return; + Eigen::IOFormat CommaInitFmt(Eigen::StreamPrecision, Eigen::DontAlignCols, + ", ", "", "", "\n", "", ""); + *output_ << values.format(CommaInitFmt); + + } + /** * Writes the comment_prefix to the stream followed by a newline. diff --git a/src/stan/callbacks/writer.hpp b/src/stan/callbacks/writer.hpp index e893b0c4de..be7cabc656 100644 --- a/src/stan/callbacks/writer.hpp +++ b/src/stan/callbacks/writer.hpp @@ -77,6 +77,27 @@ class writer { * @param[in] v Values in an Eigen row vector */ virtual void operator()(const Eigen::Matrix& values) {} + + /** + * Writes a set of values in csv format followed by a newline. + * + * Note: the precision of the output is determined by the settings + * of the stream on construction. + * + * @param[in] v Values in a block representing an Eigen column vector + */ + virtual void operator()(const Eigen::Block, -1, 1, true>) {} + + /** + * Writes a set of values in csv format followed by a newline. + * + * Note: the precision of the output is determined by the settings + * of the stream on construction. + * + * @param[in] v Values in a block representing an Eigen row vector + */ + virtual void operator()(const Eigen::Block, 1, -1, true>) {} + }; } // namespace callbacks