From 842fbbdcb520b0c6e91e6c3671482174dd48bdf2 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Fri, 22 Oct 2021 05:27:51 -0400 Subject: [PATCH 01/13] Updates the Math submodule to b13c778. --- lib/stan_math | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stan_math b/lib/stan_math index 224d38ad32b..b13c778cf74 160000 --- a/lib/stan_math +++ b/lib/stan_math @@ -1 +1 @@ -Subproject commit 224d38ad32b2ceeedf5b0955829fe435642b67b6 +Subproject commit b13c778cf7445265606184eef2e302d4194bb8bf From 7567ea5ac800e6de1b957deb30889ff355448745 Mon Sep 17 00:00:00 2001 From: Rok Cesnovar Date: Fri, 22 Oct 2021 13:35:11 +0200 Subject: [PATCH 02/13] changes for 2.28 --- .github/ISSUE_TEMPLATE.md | 2 +- RELEASE-NOTES.txt | 5 +++++ src/doxygen/doxygen.cfg | 2 +- src/stan/version.hpp | 2 +- src/test/unit/version_test.cpp | 4 ++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 012d2f03fa0..87ef047bb94 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -24,4 +24,4 @@ Describe what you expect the output to be. Knowing the correct behavior is also Provide any additional information here. #### Current Version: -v2.28.0 +v2.28.1 diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index e55db14953b..c3bff10c63e 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -5,6 +5,11 @@ Note: these are the release notes for the stan-dev/stan repository. Further changes may arise at the interface level (stan-dev/{rstan, pystan, cmdstan}) and math library level (stan-dev/math). +v2.28.1 (21 October 2021) +====================================================================== + + - Updated to Stan Math 4.2.1 + v2.28.0 (5 October 2021) ====================================================================== diff --git a/src/doxygen/doxygen.cfg b/src/doxygen/doxygen.cfg index fd656d93e04..f7186db3d71 100644 --- a/src/doxygen/doxygen.cfg +++ b/src/doxygen/doxygen.cfg @@ -38,7 +38,7 @@ PROJECT_NAME = "Stan" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 2.28.0 +PROJECT_NUMBER = 2.28.1 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/src/stan/version.hpp b/src/stan/version.hpp index 28e219e64cf..445a5ee4432 100644 --- a/src/stan/version.hpp +++ b/src/stan/version.hpp @@ -13,7 +13,7 @@ #define STAN_MAJOR 2 #define STAN_MINOR 28 -#define STAN_PATCH 0 +#define STAN_PATCH 1 namespace stan { diff --git a/src/test/unit/version_test.cpp b/src/test/unit/version_test.cpp index 1173fecd9ac..35d2e16b7bd 100644 --- a/src/test/unit/version_test.cpp +++ b/src/test/unit/version_test.cpp @@ -4,11 +4,11 @@ TEST(Stan, macro) { EXPECT_EQ(2, STAN_MAJOR); EXPECT_EQ(28, STAN_MINOR); - EXPECT_EQ(0, STAN_PATCH); + EXPECT_EQ(1, STAN_PATCH); } TEST(Stan, version) { EXPECT_EQ("2", stan::MAJOR_VERSION); EXPECT_EQ("28", stan::MINOR_VERSION); - EXPECT_EQ("0", stan::PATCH_VERSION); + EXPECT_EQ("1", stan::PATCH_VERSION); } From e2ad5eca8dd2c691042659e652764704b9fffe0a Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Sat, 23 Oct 2021 23:19:24 -0400 Subject: [PATCH 03/13] Updates the Math submodule to 49ead11. --- lib/stan_math | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stan_math b/lib/stan_math index b13c778cf74..49ead11e2c9 160000 --- a/lib/stan_math +++ b/lib/stan_math @@ -1 +1 @@ -Subproject commit b13c778cf7445265606184eef2e302d4194bb8bf +Subproject commit 49ead11e2c92be7fadd9738a5c7f99ef3af9cb3b From 274a93c2d670edea4918bb80b1f278f55a9de654 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Tue, 26 Oct 2021 09:53:33 -0400 Subject: [PATCH 04/13] Updates the Math submodule to 20224ff. --- lib/stan_math | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stan_math b/lib/stan_math index 49ead11e2c9..20224ff479c 160000 --- a/lib/stan_math +++ b/lib/stan_math @@ -1 +1 @@ -Subproject commit 49ead11e2c92be7fadd9738a5c7f99ef3af9cb3b +Subproject commit 20224ff479ca557a82a7ea3c5446d301a7d85825 From 06f50b8c44d48dab924417da8a618ffc1de9efcb Mon Sep 17 00:00:00 2001 From: rok-cesnovar Date: Sun, 31 Oct 2021 09:59:17 +0100 Subject: [PATCH 05/13] switch to stanc3 test model for integration tests --- Jenkinsfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f98ce77f417..d189bf2da08 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -263,6 +263,7 @@ pipeline { steps { sh """ git clone --recursive https://github.com/stan-dev/performance-tests-cmdstan + git clone https://github.com/stan-dev/stanc3/ performance-tests-cmdstan/stanc3 """ script { if (params.cmdstan_pr != 'downstream_tests') { @@ -303,7 +304,8 @@ pipeline { echo 'CXX=${env.CXX}' >> make/local make -j${env.PARALLEL} build cd .. - ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 cmdstan/stan/src/test/test-models/good + ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good + ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 example-models """ sh """ cd performance-tests-cmdstan/cmdstan/stan @@ -337,7 +339,8 @@ pipeline { echo 'CXX=${env.CXX}' >> make/local make -j${env.PARALLEL} build cd .. - ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 cmdstan/stan/src/test/test-models/good + ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good + ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 example-models """ sh """ cd performance-tests-cmdstan/cmdstan/stan @@ -373,7 +376,8 @@ pipeline { cd performance-tests-cmdstan/cmdstan mingw32-make -j${env.PARALLEL} build cd .. - python ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 cmdstan/stan/src/test/test-models/good + python ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good + python ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 example-models """ } bat """ From efe0ac9dbf0cea436e1e2232e3e4e3a3a760fd4a Mon Sep 17 00:00:00 2001 From: Rok Cesnovar Date: Tue, 9 Nov 2021 11:51:19 +0100 Subject: [PATCH 06/13] add std:: in tests to avoid ambiguity --- .../advi_univar_no_constraint_test.cpp | 20 ++++++++++-------- .../advi_univar_with_constraint_test.cpp | 21 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/test/unit/variational/advi_univar_no_constraint_test.cpp b/src/test/unit/variational/advi_univar_no_constraint_test.cpp index 26b9e0d483d..d6cb7f2e6d7 100644 --- a/src/test/unit/variational/advi_univar_no_constraint_test.cpp +++ b/src/test/unit/variational/advi_univar_no_constraint_test.cpp @@ -1,11 +1,13 @@ #include #include #include -#include #include -#include -#include #include // L'Ecuyer RNG +#include +#include +#include +#include + typedef boost::ecuyer1988 rng_t; typedef univariate_no_constraint_model_namespace::univariate_no_constraint_model @@ -57,14 +59,14 @@ TEST(advi_test, univar_no_constraint_fullrank) { double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0)) * exp(-0.5 - * (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2) - - pow(mu_j, 2) / sigma_j_sq)); + * (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2) + - std::pow(mu_j, 2) / sigma_j_sq)); double elbo_true = 0.0; elbo_true += log(S_j); elbo_true += log(1.0 / (sqrt(sigma_j_sq * 2.0 * stan::math::pi()))); - elbo_true += -0.5 * (pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); + elbo_true += -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi())); double const EPSILON = 0.1; @@ -182,14 +184,14 @@ TEST(advi_test, univar_no_constraint_meanfield) { double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0)) * exp(-0.5 - * (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2) - - pow(mu_j, 2) / sigma_j_sq)); + * (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2) + - std::pow(mu_j, 2) / sigma_j_sq)); double elbo_true = 0.0; elbo_true += log(S_j); elbo_true += log(1.0 / (sqrt(sigma_j_sq * 2.0 * stan::math::pi()))); - elbo_true += -0.5 * (pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); + elbo_true += -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi())); double const EPSILON = 0.1; diff --git a/src/test/unit/variational/advi_univar_with_constraint_test.cpp b/src/test/unit/variational/advi_univar_with_constraint_test.cpp index 45820c0202a..e6c83aac7f6 100644 --- a/src/test/unit/variational/advi_univar_with_constraint_test.cpp +++ b/src/test/unit/variational/advi_univar_with_constraint_test.cpp @@ -1,11 +1,14 @@ #include #include #include -#include #include -#include -#include #include // L'Ecuyer RNG +#include +#include +#include +#include + + typedef boost::ecuyer1988 rng_t; typedef univariate_with_constraint_model_namespace:: @@ -58,8 +61,8 @@ TEST(advi_test, univar_with_constraint_fullrank) { double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0)) * exp(-0.5 - * (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2) - - pow(mu_j, 2) / sigma_j_sq)); + * (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2) + - std::pow(mu_j, 2) / sigma_j_sq)); double elbo_true = 0.0; @@ -69,7 +72,7 @@ TEST(advi_test, univar_with_constraint_fullrank) { += -0.5 * one_over_sigma_j_sq * (exp(2.0 * log(1.88)) * exp(2.0 * 1.0)); elbo_true += -0.5 * one_over_sigma_j_sq * (-2.0 * mu_j * exp(log(1.88)) * exp(0.5 * 1.0)); - elbo_true += -0.5 * one_over_sigma_j_sq * (pow(mu_j, 2.0)); + elbo_true += -0.5 * one_over_sigma_j_sq * (std::pow(mu_j, 2.0)); elbo_true += log(1.88); elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi())); @@ -189,8 +192,8 @@ TEST(advi_test, univar_with_constraint_meanfield) { double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0)) * exp(-0.5 - * (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2) - - pow(mu_j, 2) / sigma_j_sq)); + * (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2) + - std::pow(mu_j, 2) / sigma_j_sq)); double elbo_true = 0.0; @@ -200,7 +203,7 @@ TEST(advi_test, univar_with_constraint_meanfield) { += -0.5 * one_over_sigma_j_sq * (exp(2.0 * log(1.88)) * exp(2.0 * 1.0)); elbo_true += -0.5 * one_over_sigma_j_sq * (-2.0 * mu_j * exp(log(1.88)) * exp(0.5 * 1.0)); - elbo_true += -0.5 * one_over_sigma_j_sq * (pow(mu_j, 2.0)); + elbo_true += -0.5 * one_over_sigma_j_sq * (std::pow(mu_j, 2.0)); elbo_true += log(1.88); elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi())); From a77b21685a9c6cbf0a3e1e89154b2a9046674978 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Tue, 9 Nov 2021 11:04:45 +0000 Subject: [PATCH 07/13] [Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final) --- .../unit/variational/advi_univar_no_constraint_test.cpp | 7 ++++--- .../unit/variational/advi_univar_with_constraint_test.cpp | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/unit/variational/advi_univar_no_constraint_test.cpp b/src/test/unit/variational/advi_univar_no_constraint_test.cpp index d6cb7f2e6d7..f1394948ff6 100644 --- a/src/test/unit/variational/advi_univar_no_constraint_test.cpp +++ b/src/test/unit/variational/advi_univar_no_constraint_test.cpp @@ -8,7 +8,6 @@ #include #include - typedef boost::ecuyer1988 rng_t; typedef univariate_no_constraint_model_namespace::univariate_no_constraint_model Model; @@ -66,7 +65,8 @@ TEST(advi_test, univar_no_constraint_fullrank) { elbo_true += log(S_j); elbo_true += log(1.0 / (sqrt(sigma_j_sq * 2.0 * stan::math::pi()))); - elbo_true += -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); + elbo_true + += -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi())); double const EPSILON = 0.1; @@ -191,7 +191,8 @@ TEST(advi_test, univar_no_constraint_meanfield) { elbo_true += log(S_j); elbo_true += log(1.0 / (sqrt(sigma_j_sq * 2.0 * stan::math::pi()))); - elbo_true += -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); + elbo_true + += -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq); elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi())); double const EPSILON = 0.1; diff --git a/src/test/unit/variational/advi_univar_with_constraint_test.cpp b/src/test/unit/variational/advi_univar_with_constraint_test.cpp index e6c83aac7f6..c12ac4f4b27 100644 --- a/src/test/unit/variational/advi_univar_with_constraint_test.cpp +++ b/src/test/unit/variational/advi_univar_with_constraint_test.cpp @@ -8,8 +8,6 @@ #include #include - - typedef boost::ecuyer1988 rng_t; typedef univariate_with_constraint_model_namespace:: univariate_with_constraint_model Model; From 6496e3cb96c68d9bc78a197af90f445de6cf7d8e Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 9 Nov 2021 09:30:53 -0500 Subject: [PATCH 08/13] bool is_empty() for not writing to files. --- src/stan/callbacks/stream_writer.hpp | 34 ++++++++---- src/stan/callbacks/tee_writer.hpp | 5 ++ src/stan/callbacks/unique_stream_writer.hpp | 55 +++++++++++-------- src/stan/callbacks/writer.hpp | 7 +++ src/stan/services/util/mcmc_writer.hpp | 22 +++++--- src/stan/variational/advi.hpp | 17 +++--- .../unit/callbacks/stream_writer_test.cpp | 13 ++++- src/test/unit/callbacks/tee_writer_test.cpp | 29 ++++++++-- .../callbacks/unique_stream_writer_test.cpp | 17 +++++- 9 files changed, 143 insertions(+), 56 deletions(-) diff --git a/src/stan/callbacks/stream_writer.hpp b/src/stan/callbacks/stream_writer.hpp index 6519531c0ac..1da036c97e7 100644 --- a/src/stan/callbacks/stream_writer.hpp +++ b/src/stan/callbacks/stream_writer.hpp @@ -24,8 +24,8 @@ class stream_writer : public writer { * each comment line. Default is "". */ explicit stream_writer(std::ostream& output, - const std::string& comment_prefix = "") - : output_(output), comment_prefix_(comment_prefix) {} + const std::string& comment_prefix = "", bool is_empty = false) + : output_(output), comment_prefix_(comment_prefix), empty_(is_empty) {} /** * Virtual destructor @@ -57,7 +57,7 @@ class stream_writer : public writer { /** * Writes the comment_prefix to the stream followed by a newline. */ - void operator()() { output_ << comment_prefix_ << std::endl; } + void operator()() { if (!empty_) {output_ << comment_prefix_ << std::endl;} } /** * Writes the comment_prefix then the message followed by a newline. @@ -65,9 +65,16 @@ class stream_writer : public writer { * @param[in] message A string */ void operator()(const std::string& message) { - output_ << comment_prefix_ << message << std::endl; + if (!empty_) { + output_ << comment_prefix_ << message << std::endl; + } } + inline bool is_empty() const { + return empty_; + } + + private: /** * Output stream @@ -79,6 +86,7 @@ class stream_writer : public writer { */ std::string comment_prefix_; + bool empty_; /** * Writes a set of values in csv format followed by a newline. * @@ -89,16 +97,18 @@ class stream_writer : public writer { */ template void write_vector(const std::vector& v) { - if (v.empty()) - return; + if (!empty_) { + if (v.empty()) + return; - typename std::vector::const_iterator last = v.end(); - --last; + typename std::vector::const_iterator last = v.end(); + --last; - for (typename std::vector::const_iterator it = v.begin(); it != last; - ++it) - output_ << *it << ","; - output_ << v.back() << std::endl; + for (typename std::vector::const_iterator it = v.begin(); it != last; + ++it) + output_ << *it << ","; + output_ << v.back() << std::endl; + } } }; diff --git a/src/stan/callbacks/tee_writer.hpp b/src/stan/callbacks/tee_writer.hpp index c491832e9ec..58d5da44492 100644 --- a/src/stan/callbacks/tee_writer.hpp +++ b/src/stan/callbacks/tee_writer.hpp @@ -49,6 +49,10 @@ class tee_writer final : public writer { writer2_(message); } + inline bool is_empty() const { + return writer1_.is_empty() && writer2_.is_empty(); + } + private: /** * The first writer @@ -58,6 +62,7 @@ class tee_writer final : public writer { * The second writer */ writer& writer2_; + }; } // namespace callbacks diff --git a/src/stan/callbacks/unique_stream_writer.hpp b/src/stan/callbacks/unique_stream_writer.hpp index 60e1c4e3843..2f22a417853 100644 --- a/src/stan/callbacks/unique_stream_writer.hpp +++ b/src/stan/callbacks/unique_stream_writer.hpp @@ -27,14 +27,14 @@ class unique_stream_writer final : public writer { * Default is "". */ explicit unique_stream_writer(std::unique_ptr&& output, - const std::string& comment_prefix = "") - : output_(std::move(output)), comment_prefix_(comment_prefix) {} + const std::string& comment_prefix = "", bool is_empty = false) + : output_(std::move(output)), comment_prefix_(comment_prefix), empty_(is_empty) {} unique_stream_writer(); unique_stream_writer(unique_stream_writer& other) = delete; unique_stream_writer(unique_stream_writer&& other) : output_(std::move(other.output_)), - comment_prefix_(std::move(other.comment_prefix_)) {} + comment_prefix_(std::move(other.comment_prefix_)), empty_(other.empty_) {} /** * Virtual destructor */ @@ -70,10 +70,12 @@ class unique_stream_writer final : public writer { * Writes the comment_prefix to the stream followed by a newline. */ void operator()() { - std::stringstream streamer; - streamer.precision(output_.get()->precision()); - streamer << comment_prefix_ << std::endl; - *output_ << streamer.str(); + if (!empty_) { + std::stringstream streamer; + streamer.precision(output_.get()->precision()); + streamer << comment_prefix_ << std::endl; + *output_ << streamer.str(); + } } /** @@ -82,10 +84,16 @@ class unique_stream_writer final : public writer { * @param[in] message A string */ void operator()(const std::string& message) { - std::stringstream streamer; - streamer.precision(output_.get()->precision()); - streamer << comment_prefix_ << message << std::endl; - *output_ << streamer.str(); + if (!empty_) { + std::stringstream streamer; + streamer.precision(output_.get()->precision()); + streamer << comment_prefix_ << message << std::endl; + *output_ << streamer.str(); + } + } + + inline bool is_empty() const { + return empty_; } private: @@ -99,6 +107,7 @@ class unique_stream_writer final : public writer { */ std::string comment_prefix_; + bool empty_{false}; /** * Writes a set of values in csv format followed by a newline. * @@ -109,18 +118,20 @@ class unique_stream_writer final : public writer { */ template void write_vector(const std::vector& v) { - if (v.empty()) - return; - using const_iter = typename std::vector::const_iterator; - const_iter last = v.end(); - --last; - std::stringstream streamer; - streamer.precision(output_.get()->precision()); - for (const_iter it = v.begin(); it != last; ++it) { - streamer << *it << ","; + if (!empty_) { + if (v.empty()) + return; + using const_iter = typename std::vector::const_iterator; + const_iter last = v.end(); + --last; + std::stringstream streamer; + streamer.precision(output_.get()->precision()); + for (const_iter it = v.begin(); it != last; ++it) { + streamer << *it << ","; + } + streamer << v.back() << std::endl; + *output_ << streamer.str(); } - streamer << v.back() << std::endl; - *output_ << streamer.str(); } }; diff --git a/src/stan/callbacks/writer.hpp b/src/stan/callbacks/writer.hpp index a12108b256f..38b20612971 100644 --- a/src/stan/callbacks/writer.hpp +++ b/src/stan/callbacks/writer.hpp @@ -45,6 +45,13 @@ class writer { * @param[in] message A string */ virtual void operator()(const std::string& message) {} + + /** + * Check if the writer is writing to an empty stream + */ + virtual bool is_empty() const { + return true; + } }; } // namespace callbacks diff --git a/src/stan/services/util/mcmc_writer.hpp b/src/stan/services/util/mcmc_writer.hpp index 22b0b4fbb94..fd712ab0103 100644 --- a/src/stan/services/util/mcmc_writer.hpp +++ b/src/stan/services/util/mcmc_writer.hpp @@ -149,17 +149,19 @@ class mcmc_writer { template void write_diagnostic_names(stan::mcmc::sample sample, stan::mcmc::base_mcmc& sampler, Model& model) { - std::vector names; + if (!diagnostic_writer_.is_empty()) { + std::vector names; - sample.get_sample_param_names(names); - sampler.get_sampler_param_names(names); + sample.get_sample_param_names(names); + sampler.get_sampler_param_names(names); - std::vector model_names; - model.unconstrained_param_names(model_names, false, false); + std::vector model_names; + model.unconstrained_param_names(model_names, false, false); - sampler.get_sampler_diagnostic_names(model_names, names); + sampler.get_sampler_diagnostic_names(model_names, names); - diagnostic_writer_(names); + diagnostic_writer_(names); + } } /** @@ -170,6 +172,7 @@ class mcmc_writer { */ void write_diagnostic_params(stan::mcmc::sample& sample, stan::mcmc::base_mcmc& sampler) { + if (!diagnostic_writer_.is_empty()) { std::vector values; sample.get_sample_params(values); @@ -177,6 +180,7 @@ class mcmc_writer { sampler.get_sampler_diagnostics(values); diagnostic_writer_(values); + } } /** @@ -247,7 +251,9 @@ class mcmc_writer { */ void write_timing(double warmDeltaT, double sampleDeltaT) { write_timing(warmDeltaT, sampleDeltaT, sample_writer_); - write_timing(warmDeltaT, sampleDeltaT, diagnostic_writer_); + if (!diagnostic_writer_.is_empty()) { + write_timing(warmDeltaT, sampleDeltaT, diagnostic_writer_); + } log_timing(warmDeltaT, sampleDeltaT); } }; diff --git a/src/stan/variational/advi.hpp b/src/stan/variational/advi.hpp index 4dca19d0335..e89ab70ac11 100644 --- a/src/stan/variational/advi.hpp +++ b/src/stan/variational/advi.hpp @@ -392,12 +392,14 @@ class advi { = std::chrono::duration_cast(end - start) .count() / 1000.0; - std::vector print_vector; - print_vector.clear(); - print_vector.push_back(iter_counter); - print_vector.push_back(delta_t); - print_vector.push_back(elbo); - diagnostic_writer(print_vector); + if (!diagnostic_writer.is_empty()) { + std::vector print_vector; + print_vector.clear(); + print_vector.push_back(iter_counter); + print_vector.push_back(delta_t); + print_vector.push_back(elbo); + diagnostic_writer(print_vector); + } if (delta_elbo_ave < tol_rel_obj) { ss << " MEAN ELBO CONVERGED"; @@ -459,8 +461,9 @@ class advi { double tol_rel_obj, int max_iterations, callbacks::logger& logger, callbacks::writer& parameter_writer, callbacks::writer& diagnostic_writer) const { + if (!diagnostic_writer.is_empty()) { diagnostic_writer("iter,time_in_seconds,ELBO"); - + } // Initialize variational approximation Q variational = Q(cont_params_); diff --git a/src/test/unit/callbacks/stream_writer_test.cpp b/src/test/unit/callbacks/stream_writer_test.cpp index e0bc01bb9be..effba2466c9 100644 --- a/src/test/unit/callbacks/stream_writer_test.cpp +++ b/src/test/unit/callbacks/stream_writer_test.cpp @@ -5,7 +5,7 @@ class StanInterfaceCallbacksStreamWriter : public ::testing::Test { public: StanInterfaceCallbacksStreamWriter() - : ss(), writer(ss), writer_prefix(ss, "# ") {} + : ss(), writer(ss), writer_prefix(ss, "# "), empty_writer(ss, "# ", true) {} void SetUp() { ss.str(std::string()); @@ -16,6 +16,7 @@ class StanInterfaceCallbacksStreamWriter : public ::testing::Test { std::stringstream ss; stan::callbacks::stream_writer writer; stan::callbacks::stream_writer writer_prefix; + stan::callbacks::stream_writer empty_writer; }; TEST_F(StanInterfaceCallbacksStreamWriter, double_vector) { @@ -28,6 +29,16 @@ TEST_F(StanInterfaceCallbacksStreamWriter, double_vector) { EXPECT_EQ("0,1,2,3,4\n", ss.str()); } +TEST_F(StanInterfaceCallbacksStreamWriter, empty_vector) { + const int N = 5; + std::vector x; + for (int n = 0; n < N; ++n) + x.push_back(n); + + EXPECT_NO_THROW(empty_writer(x)); + EXPECT_EQ("", ss.str()); +} + TEST_F(StanInterfaceCallbacksStreamWriter, string_vector) { const int N = 5; std::vector x; diff --git a/src/test/unit/callbacks/tee_writer_test.cpp b/src/test/unit/callbacks/tee_writer_test.cpp index 0dc4dbd4e2f..5a1d88eb8f8 100644 --- a/src/test/unit/callbacks/tee_writer_test.cpp +++ b/src/test/unit/callbacks/tee_writer_test.cpp @@ -5,26 +5,37 @@ namespace test { class mock_writer : public stan::callbacks::writer { public: int N; + bool empty_; mock_writer() : N(0) {} + mock_writer(bool is_empty) : N(0), empty_(is_empty) {} - void operator()(const std::vector& names) { ++N; } + void operator()(const std::vector& names) { if (!empty_) {++N;} } - void operator()(const std::vector& state) { ++N; } + void operator()(const std::vector& state) { if (!empty_) {++N;} } - void operator()() { ++N; } + void operator()() { if (!empty_) {++N;} } - void operator()(const std::string& message) { ++N; } + void operator()(const std::string& message) { + if (!empty_) {++N;} + } + + inline bool is_empty() { + return false; + } }; } // namespace test class StanCallbacksTeeWriter : public ::testing::Test { public: StanCallbacksTeeWriter() - : writer1(), writer2(), tee_writer(writer1, writer2) {} + : writer1(), writer2(), tee_writer(writer1, writer2), + empty_writer1(true), empty_writer2(true), empty_tee_writer(empty_writer1, empty_writer2) {} test::mock_writer writer1, writer2; stan::callbacks::tee_writer tee_writer; + test::mock_writer empty_writer1, empty_writer2; + stan::callbacks::tee_writer empty_tee_writer; }; TEST_F(StanCallbacksTeeWriter, names) { @@ -35,6 +46,14 @@ TEST_F(StanCallbacksTeeWriter, names) { EXPECT_EQ(1, writer2.N); } +TEST_F(StanCallbacksTeeWriter, empty_names) { + std::vector names; + + empty_tee_writer(names); + EXPECT_EQ(0, empty_writer1.N); + EXPECT_EQ(0, empty_writer2.N); +} + TEST_F(StanCallbacksTeeWriter, state) { std::vector state; diff --git a/src/test/unit/callbacks/unique_stream_writer_test.cpp b/src/test/unit/callbacks/unique_stream_writer_test.cpp index 43d783f48c4..8314aee86d3 100644 --- a/src/test/unit/callbacks/unique_stream_writer_test.cpp +++ b/src/test/unit/callbacks/unique_stream_writer_test.cpp @@ -5,15 +5,19 @@ class StanInterfaceCallbacksStreamWriter : public ::testing::Test { public: StanInterfaceCallbacksStreamWriter() - : writer(std::make_unique(std::stringstream{})) {} + : writer(std::make_unique(std::stringstream{})), + empty_writer(std::make_unique(std::stringstream{}), "#", true) {} void SetUp() { static_cast(writer.get_stream()).str(std::string()); static_cast(writer.get_stream()).clear(); + static_cast(empty_writer.get_stream()).str(std::string()); + static_cast(empty_writer.get_stream()).clear(); } void TearDown() {} stan::callbacks::unique_stream_writer writer; + stan::callbacks::unique_stream_writer empty_writer; }; TEST_F(StanInterfaceCallbacksStreamWriter, double_vector) { @@ -27,6 +31,17 @@ TEST_F(StanInterfaceCallbacksStreamWriter, double_vector) { static_cast(writer.get_stream()).str()); } +TEST_F(StanInterfaceCallbacksStreamWriter, empty_test) { + const int N = 5; + std::vector x; + for (int n = 0; n < N; ++n) + x.push_back(n); + + EXPECT_NO_THROW(empty_writer(x)); + EXPECT_EQ("", + static_cast(empty_writer.get_stream()).str()); +} + TEST_F(StanInterfaceCallbacksStreamWriter, double_vector_precision2) { const int N = 5; std::vector x{1.23456789, 2.3456789, 3.45678910, 4.567890123}; From dfe5652223ac1b728007b77406c0e0c4d1d64136 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 9 Nov 2021 09:53:04 -0500 Subject: [PATCH 09/13] add docs for empty member and member function --- src/stan/callbacks/stream_writer.hpp | 10 ++++++++-- src/stan/callbacks/tee_writer.hpp | 5 ++++- src/stan/callbacks/unique_stream_writer.hpp | 10 ++++++++-- src/stan/callbacks/writer.hpp | 2 +- src/test/unit/callbacks/tee_writer_test.cpp | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/stan/callbacks/stream_writer.hpp b/src/stan/callbacks/stream_writer.hpp index 1da036c97e7..c569723fb8d 100644 --- a/src/stan/callbacks/stream_writer.hpp +++ b/src/stan/callbacks/stream_writer.hpp @@ -70,7 +70,10 @@ class stream_writer : public writer { } } - inline bool is_empty() const { + /** + * Check if the writer is writing to an empty stream + */ + inline bool is_empty() const noexcept final { return empty_; } @@ -86,7 +89,10 @@ class stream_writer : public writer { */ std::string comment_prefix_; - bool empty_; + /** + * Used as check for whether output stream needs to be written to. + */ + bool empty_{false}; /** * Writes a set of values in csv format followed by a newline. * diff --git a/src/stan/callbacks/tee_writer.hpp b/src/stan/callbacks/tee_writer.hpp index 58d5da44492..c8620cc29e6 100644 --- a/src/stan/callbacks/tee_writer.hpp +++ b/src/stan/callbacks/tee_writer.hpp @@ -49,7 +49,10 @@ class tee_writer final : public writer { writer2_(message); } - inline bool is_empty() const { + /** + * Check if both writers are writing to an empty stream + */ + inline bool is_empty() const noexcept { return writer1_.is_empty() && writer2_.is_empty(); } diff --git a/src/stan/callbacks/unique_stream_writer.hpp b/src/stan/callbacks/unique_stream_writer.hpp index 2f22a417853..895a3465f1f 100644 --- a/src/stan/callbacks/unique_stream_writer.hpp +++ b/src/stan/callbacks/unique_stream_writer.hpp @@ -54,7 +54,7 @@ class unique_stream_writer final : public writer { /** * Get the underlying stream */ - auto& get_stream() { return *output_; } + inline auto& get_stream() noexcept { return *output_; } /** * Writes a set of values in csv format followed by a newline. @@ -92,7 +92,10 @@ class unique_stream_writer final : public writer { } } - inline bool is_empty() const { + /** + * Check if the writer is writing to an empty stream + */ + inline bool is_empty() const noexcept { return empty_; } @@ -107,6 +110,9 @@ class unique_stream_writer final : public writer { */ std::string comment_prefix_; + /** + * Used as check for whether output stream needs to be written to. + */ bool empty_{false}; /** * Writes a set of values in csv format followed by a newline. diff --git a/src/stan/callbacks/writer.hpp b/src/stan/callbacks/writer.hpp index 38b20612971..36433f10402 100644 --- a/src/stan/callbacks/writer.hpp +++ b/src/stan/callbacks/writer.hpp @@ -49,7 +49,7 @@ class writer { /** * Check if the writer is writing to an empty stream */ - virtual bool is_empty() const { + virtual bool is_empty() const noexcept { return true; } }; diff --git a/src/test/unit/callbacks/tee_writer_test.cpp b/src/test/unit/callbacks/tee_writer_test.cpp index 5a1d88eb8f8..9440ac0f36f 100644 --- a/src/test/unit/callbacks/tee_writer_test.cpp +++ b/src/test/unit/callbacks/tee_writer_test.cpp @@ -20,7 +20,7 @@ class mock_writer : public stan::callbacks::writer { if (!empty_) {++N;} } - inline bool is_empty() { + inline bool is_empty() const noexcept { return false; } }; From bd8e0601240f2eee0150a988417db2d88821f3f8 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Tue, 9 Nov 2021 14:57:25 +0000 Subject: [PATCH 10/13] [Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final) --- src/stan/callbacks/stream_writer.hpp | 14 ++++---- src/stan/callbacks/tee_writer.hpp | 1 - src/stan/callbacks/unique_stream_writer.hpp | 16 +++++---- src/stan/callbacks/writer.hpp | 4 +-- src/stan/services/util/mcmc_writer.hpp | 14 ++++---- src/stan/variational/advi.hpp | 4 +-- .../unit/callbacks/stream_writer_test.cpp | 5 ++- src/test/unit/callbacks/tee_writer_test.cpp | 34 ++++++++++++++----- .../callbacks/unique_stream_writer_test.cpp | 6 ++-- 9 files changed, 60 insertions(+), 38 deletions(-) diff --git a/src/stan/callbacks/stream_writer.hpp b/src/stan/callbacks/stream_writer.hpp index c569723fb8d..35a06a3e64b 100644 --- a/src/stan/callbacks/stream_writer.hpp +++ b/src/stan/callbacks/stream_writer.hpp @@ -24,7 +24,8 @@ class stream_writer : public writer { * each comment line. Default is "". */ explicit stream_writer(std::ostream& output, - const std::string& comment_prefix = "", bool is_empty = false) + const std::string& comment_prefix = "", + bool is_empty = false) : output_(output), comment_prefix_(comment_prefix), empty_(is_empty) {} /** @@ -57,7 +58,11 @@ class stream_writer : public writer { /** * Writes the comment_prefix to the stream followed by a newline. */ - void operator()() { if (!empty_) {output_ << comment_prefix_ << std::endl;} } + void operator()() { + if (!empty_) { + output_ << comment_prefix_ << std::endl; + } + } /** * Writes the comment_prefix then the message followed by a newline. @@ -73,10 +78,7 @@ class stream_writer : public writer { /** * Check if the writer is writing to an empty stream */ - inline bool is_empty() const noexcept final { - return empty_; - } - + inline bool is_empty() const noexcept final { return empty_; } private: /** diff --git a/src/stan/callbacks/tee_writer.hpp b/src/stan/callbacks/tee_writer.hpp index c8620cc29e6..d0acd77baf4 100644 --- a/src/stan/callbacks/tee_writer.hpp +++ b/src/stan/callbacks/tee_writer.hpp @@ -65,7 +65,6 @@ class tee_writer final : public writer { * The second writer */ writer& writer2_; - }; } // namespace callbacks diff --git a/src/stan/callbacks/unique_stream_writer.hpp b/src/stan/callbacks/unique_stream_writer.hpp index 895a3465f1f..44fe778bbba 100644 --- a/src/stan/callbacks/unique_stream_writer.hpp +++ b/src/stan/callbacks/unique_stream_writer.hpp @@ -27,14 +27,18 @@ class unique_stream_writer final : public writer { * Default is "". */ explicit unique_stream_writer(std::unique_ptr&& output, - const std::string& comment_prefix = "", bool is_empty = false) - : output_(std::move(output)), comment_prefix_(comment_prefix), empty_(is_empty) {} + const std::string& comment_prefix = "", + bool is_empty = false) + : output_(std::move(output)), + comment_prefix_(comment_prefix), + empty_(is_empty) {} unique_stream_writer(); unique_stream_writer(unique_stream_writer& other) = delete; unique_stream_writer(unique_stream_writer&& other) : output_(std::move(other.output_)), - comment_prefix_(std::move(other.comment_prefix_)), empty_(other.empty_) {} + comment_prefix_(std::move(other.comment_prefix_)), + empty_(other.empty_) {} /** * Virtual destructor */ @@ -75,7 +79,7 @@ class unique_stream_writer final : public writer { streamer.precision(output_.get()->precision()); streamer << comment_prefix_ << std::endl; *output_ << streamer.str(); - } + } } /** @@ -95,9 +99,7 @@ class unique_stream_writer final : public writer { /** * Check if the writer is writing to an empty stream */ - inline bool is_empty() const noexcept { - return empty_; - } + inline bool is_empty() const noexcept { return empty_; } private: /** diff --git a/src/stan/callbacks/writer.hpp b/src/stan/callbacks/writer.hpp index 36433f10402..41a8a2327fc 100644 --- a/src/stan/callbacks/writer.hpp +++ b/src/stan/callbacks/writer.hpp @@ -49,9 +49,7 @@ class writer { /** * Check if the writer is writing to an empty stream */ - virtual bool is_empty() const noexcept { - return true; - } + virtual bool is_empty() const noexcept { return true; } }; } // namespace callbacks diff --git a/src/stan/services/util/mcmc_writer.hpp b/src/stan/services/util/mcmc_writer.hpp index fd712ab0103..77e7e9d2b4c 100644 --- a/src/stan/services/util/mcmc_writer.hpp +++ b/src/stan/services/util/mcmc_writer.hpp @@ -172,15 +172,15 @@ class mcmc_writer { */ void write_diagnostic_params(stan::mcmc::sample& sample, stan::mcmc::base_mcmc& sampler) { - if (!diagnostic_writer_.is_empty()) { - std::vector values; + if (!diagnostic_writer_.is_empty()) { + std::vector values; - sample.get_sample_params(values); - sampler.get_sampler_params(values); - sampler.get_sampler_diagnostics(values); + sample.get_sample_params(values); + sampler.get_sampler_params(values); + sampler.get_sampler_diagnostics(values); - diagnostic_writer_(values); - } + diagnostic_writer_(values); + } } /** diff --git a/src/stan/variational/advi.hpp b/src/stan/variational/advi.hpp index e89ab70ac11..35fdc19be67 100644 --- a/src/stan/variational/advi.hpp +++ b/src/stan/variational/advi.hpp @@ -462,8 +462,8 @@ class advi { callbacks::writer& parameter_writer, callbacks::writer& diagnostic_writer) const { if (!diagnostic_writer.is_empty()) { - diagnostic_writer("iter,time_in_seconds,ELBO"); - } + diagnostic_writer("iter,time_in_seconds,ELBO"); + } // Initialize variational approximation Q variational = Q(cont_params_); diff --git a/src/test/unit/callbacks/stream_writer_test.cpp b/src/test/unit/callbacks/stream_writer_test.cpp index effba2466c9..18f7839362f 100644 --- a/src/test/unit/callbacks/stream_writer_test.cpp +++ b/src/test/unit/callbacks/stream_writer_test.cpp @@ -5,7 +5,10 @@ class StanInterfaceCallbacksStreamWriter : public ::testing::Test { public: StanInterfaceCallbacksStreamWriter() - : ss(), writer(ss), writer_prefix(ss, "# "), empty_writer(ss, "# ", true) {} + : ss(), + writer(ss), + writer_prefix(ss, "# "), + empty_writer(ss, "# ", true) {} void SetUp() { ss.str(std::string()); diff --git a/src/test/unit/callbacks/tee_writer_test.cpp b/src/test/unit/callbacks/tee_writer_test.cpp index 9440ac0f36f..276f2c618ad 100644 --- a/src/test/unit/callbacks/tee_writer_test.cpp +++ b/src/test/unit/callbacks/tee_writer_test.cpp @@ -10,27 +10,43 @@ class mock_writer : public stan::callbacks::writer { mock_writer() : N(0) {} mock_writer(bool is_empty) : N(0), empty_(is_empty) {} - void operator()(const std::vector& names) { if (!empty_) {++N;} } + void operator()(const std::vector& names) { + if (!empty_) { + ++N; + } + } - void operator()(const std::vector& state) { if (!empty_) {++N;} } + void operator()(const std::vector& state) { + if (!empty_) { + ++N; + } + } - void operator()() { if (!empty_) {++N;} } + void operator()() { + if (!empty_) { + ++N; + } + } void operator()(const std::string& message) { - if (!empty_) {++N;} + if (!empty_) { + ++N; + } } - inline bool is_empty() const noexcept { - return false; - } + inline bool is_empty() const noexcept { return false; } }; } // namespace test class StanCallbacksTeeWriter : public ::testing::Test { public: StanCallbacksTeeWriter() - : writer1(), writer2(), tee_writer(writer1, writer2), - empty_writer1(true), empty_writer2(true), empty_tee_writer(empty_writer1, empty_writer2) {} + : writer1(), + writer2(), + tee_writer(writer1, writer2), + empty_writer1(true), + empty_writer2(true), + empty_tee_writer(empty_writer1, empty_writer2) {} test::mock_writer writer1, writer2; stan::callbacks::tee_writer tee_writer; diff --git a/src/test/unit/callbacks/unique_stream_writer_test.cpp b/src/test/unit/callbacks/unique_stream_writer_test.cpp index 8314aee86d3..7505e63e3e6 100644 --- a/src/test/unit/callbacks/unique_stream_writer_test.cpp +++ b/src/test/unit/callbacks/unique_stream_writer_test.cpp @@ -6,12 +6,14 @@ class StanInterfaceCallbacksStreamWriter : public ::testing::Test { public: StanInterfaceCallbacksStreamWriter() : writer(std::make_unique(std::stringstream{})), - empty_writer(std::make_unique(std::stringstream{}), "#", true) {} + empty_writer(std::make_unique(std::stringstream{}), + "#", true) {} void SetUp() { static_cast(writer.get_stream()).str(std::string()); static_cast(writer.get_stream()).clear(); - static_cast(empty_writer.get_stream()).str(std::string()); + static_cast(empty_writer.get_stream()) + .str(std::string()); static_cast(empty_writer.get_stream()).clear(); } void TearDown() {} From f9e2aaae0ac3ba929e1aee4e02376bc88da5918e Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 9 Nov 2021 12:56:41 -0500 Subject: [PATCH 11/13] fix instrumented_writer --- src/stan/callbacks/writer.hpp | 2 +- src/test/unit/callbacks/tee_writer_test.cpp | 4 +++- src/test/unit/services/experimental/advi/meanfield_test.cpp | 2 +- src/test/unit/services/instrumented_callbacks.hpp | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/stan/callbacks/writer.hpp b/src/stan/callbacks/writer.hpp index 41a8a2327fc..cd2454e1019 100644 --- a/src/stan/callbacks/writer.hpp +++ b/src/stan/callbacks/writer.hpp @@ -49,7 +49,7 @@ class writer { /** * Check if the writer is writing to an empty stream */ - virtual bool is_empty() const noexcept { return true; } + virtual bool is_empty() const noexcept =0; }; } // namespace callbacks diff --git a/src/test/unit/callbacks/tee_writer_test.cpp b/src/test/unit/callbacks/tee_writer_test.cpp index 276f2c618ad..50a4e9f4d00 100644 --- a/src/test/unit/callbacks/tee_writer_test.cpp +++ b/src/test/unit/callbacks/tee_writer_test.cpp @@ -34,7 +34,9 @@ class mock_writer : public stan::callbacks::writer { } } - inline bool is_empty() const noexcept { return false; } + inline bool is_empty() const noexcept { + return false; + } }; } // namespace test diff --git a/src/test/unit/services/experimental/advi/meanfield_test.cpp b/src/test/unit/services/experimental/advi/meanfield_test.cpp index 118b497922f..cf820561d32 100644 --- a/src/test/unit/services/experimental/advi/meanfield_test.cpp +++ b/src/test/unit/services/experimental/advi/meanfield_test.cpp @@ -1,8 +1,8 @@ #include -#include #include #include #include +#include class ServicesExperimentalAdvi : public testing::Test { public: diff --git a/src/test/unit/services/instrumented_callbacks.hpp b/src/test/unit/services/instrumented_callbacks.hpp index 797959ef0ee..3e04157ee89 100644 --- a/src/test/unit/services/instrumented_callbacks.hpp +++ b/src/test/unit/services/instrumented_callbacks.hpp @@ -41,6 +41,10 @@ class instrumented_writer : public stan::callbacks::writer { public: instrumented_writer() {} + inline bool is_empty() const noexcept { + return false; + } + void operator()(const std::string& key, double value) { counter_["string_double"]++; string_double.push_back(std::make_pair(key, value)); From 60448fbf2075ca1f886e5933ea9f4be628324f3a Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Tue, 9 Nov 2021 18:00:33 +0000 Subject: [PATCH 12/13] [Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final) --- src/stan/callbacks/writer.hpp | 2 +- src/test/unit/callbacks/tee_writer_test.cpp | 4 +--- src/test/unit/services/instrumented_callbacks.hpp | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/stan/callbacks/writer.hpp b/src/stan/callbacks/writer.hpp index cd2454e1019..13f366a2282 100644 --- a/src/stan/callbacks/writer.hpp +++ b/src/stan/callbacks/writer.hpp @@ -49,7 +49,7 @@ class writer { /** * Check if the writer is writing to an empty stream */ - virtual bool is_empty() const noexcept =0; + virtual bool is_empty() const noexcept = 0; }; } // namespace callbacks diff --git a/src/test/unit/callbacks/tee_writer_test.cpp b/src/test/unit/callbacks/tee_writer_test.cpp index 50a4e9f4d00..276f2c618ad 100644 --- a/src/test/unit/callbacks/tee_writer_test.cpp +++ b/src/test/unit/callbacks/tee_writer_test.cpp @@ -34,9 +34,7 @@ class mock_writer : public stan::callbacks::writer { } } - inline bool is_empty() const noexcept { - return false; - } + inline bool is_empty() const noexcept { return false; } }; } // namespace test diff --git a/src/test/unit/services/instrumented_callbacks.hpp b/src/test/unit/services/instrumented_callbacks.hpp index 3e04157ee89..61d7ced0e10 100644 --- a/src/test/unit/services/instrumented_callbacks.hpp +++ b/src/test/unit/services/instrumented_callbacks.hpp @@ -41,9 +41,7 @@ class instrumented_writer : public stan::callbacks::writer { public: instrumented_writer() {} - inline bool is_empty() const noexcept { - return false; - } + inline bool is_empty() const noexcept { return false; } void operator()(const std::string& key, double value) { counter_["string_double"]++; From 904dbe66abba3ab82750eb7e82a0530b09274001 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Tue, 9 Nov 2021 13:07:46 -0500 Subject: [PATCH 13/13] make is_empty() non-pure --- src/stan/callbacks/writer.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stan/callbacks/writer.hpp b/src/stan/callbacks/writer.hpp index cd2454e1019..41a8a2327fc 100644 --- a/src/stan/callbacks/writer.hpp +++ b/src/stan/callbacks/writer.hpp @@ -49,7 +49,7 @@ class writer { /** * Check if the writer is writing to an empty stream */ - virtual bool is_empty() const noexcept =0; + virtual bool is_empty() const noexcept { return true; } }; } // namespace callbacks