From 3a76d5a768351a51fd51cac4ecf1fbbdbd0392fc Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Fri, 29 Nov 2024 10:54:40 -0500 Subject: [PATCH 1/2] Also catch exceptions in MAD calculation --- src/stan/mcmc/chainset.hpp | 6 +++++- src/test/unit/mcmc/chainset_test.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/stan/mcmc/chainset.hpp b/src/stan/mcmc/chainset.hpp index 68256b6c0d..5da70fd924 100644 --- a/src/stan/mcmc/chainset.hpp +++ b/src/stan/mcmc/chainset.hpp @@ -268,7 +268,11 @@ class chainset { auto center = median(index); Eigen::MatrixXd abs_dev = (draws.array() - center).abs(); Eigen::Map map(abs_dev.data(), abs_dev.size()); - return 1.4826 * stan::math::quantile(map, 0.5); + try { + return 1.4826 * stan::math::quantile(map, 0.5); + } catch (const std::logic_error& e) { + return std::numeric_limits::quiet_NaN(); + } } /** diff --git a/src/test/unit/mcmc/chainset_test.cpp b/src/test/unit/mcmc/chainset_test.cpp index b7ed38baa0..1c61c2c3c8 100644 --- a/src/test/unit/mcmc/chainset_test.cpp +++ b/src/test/unit/mcmc/chainset_test.cpp @@ -225,6 +225,9 @@ TEST_F(McmcChains, quantile_tests) { EXPECT_TRUE(std::isnan(stepsize_quantiles(i))); } + double stepsize_MAD = datagen_chains.med_abs_deviation("stepsize__"); + EXPECT_TRUE(std::isnan(stepsize_MAD)); + Eigen::VectorXd bad_probs(3); bad_probs << 5, 50, 95; Eigen::VectorXd y_sim_quantiles @@ -232,4 +235,5 @@ TEST_F(McmcChains, quantile_tests) { for (size_t i = 0; i < bad_probs.size(); ++i) { EXPECT_TRUE(std::isnan(y_sim_quantiles(i))); } + } From c4b2f2f584e073fd4efa23325a67c497091de89f Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Fri, 29 Nov 2024 10:56:14 -0500 Subject: [PATCH 2/2] [Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1 --- src/test/unit/mcmc/chainset_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/unit/mcmc/chainset_test.cpp b/src/test/unit/mcmc/chainset_test.cpp index 1c61c2c3c8..83b519c606 100644 --- a/src/test/unit/mcmc/chainset_test.cpp +++ b/src/test/unit/mcmc/chainset_test.cpp @@ -235,5 +235,4 @@ TEST_F(McmcChains, quantile_tests) { for (size_t i = 0; i < bad_probs.size(); ++i) { EXPECT_TRUE(std::isnan(y_sim_quantiles(i))); } - }