From 522b9602922edd7faa06513ec974cbe20480305e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 26 Aug 2020 15:55:24 -0400 Subject: [PATCH 01/12] Fix probability framework allocations (Issue #2036) --- test/prob/test_fixture_ccdf_log.hpp | 18 ++++++++++++------ test/prob/test_fixture_cdf.hpp | 18 ++++++++++++------ test/prob/test_fixture_cdf_log.hpp | 18 ++++++++++++------ test/prob/test_fixture_distr.hpp | 18 ++++++++++++------ 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index aec6a15b431..84799e50160 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -257,8 +257,8 @@ class AgradCcdfLogTestFixture : public ::testing::Test { // works for double calculate_gradients_1storder(vector& grad, var& ccdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); ccdf_log.grad(x, grad); - stan::math::recover_memory(); return ccdf_log.val(); } double calculate_gradients_2ndorder(vector& grad, var& ccdf_log, @@ -306,14 +306,14 @@ class AgradCcdfLogTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& ccdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); ccdf_log.val_.grad(x, grad); - stan::math::recover_memory(); return ccdf_log.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar& ccdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); ccdf_log.d_.grad(x, grad); - stan::math::recover_memory(); return ccdf_log.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar& ccdf_log, @@ -325,22 +325,22 @@ class AgradCcdfLogTestFixture : public ::testing::Test { double calculate_gradients_1storder(vector& grad, fvar>& ccdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); ccdf_log.val_.val_.grad(x, grad); - stan::math::recover_memory(); return ccdf_log.val_.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& ccdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); ccdf_log.d_.val_.grad(x, grad); - stan::math::recover_memory(); return ccdf_log.val_.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar>& ccdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); ccdf_log.d_.d_.grad(x, grad); - stan::math::recover_memory(); return ccdf_log.val_.val_.val(); } @@ -408,6 +408,8 @@ class AgradCcdfLogTestFixture : public ::testing::Test { calculate_gradients_1storder(gradients, ccdf_log, x1); test_finite_diffs_equal(parameters[n], finite_diffs, gradients); + + stan::math::recover_memory(); } } } @@ -484,6 +486,8 @@ class AgradCcdfLogTestFixture : public ::testing::Test { test_gradients_equal(expected_gradients1, gradients1); test_gradients_equal(expected_gradients2, gradients2); test_gradients_equal(expected_gradients3, gradients3); + + stan::math::recover_memory(); } } @@ -575,6 +579,8 @@ class AgradCcdfLogTestFixture : public ::testing::Test { calculate_gradients_1storder(multiple_gradients2, multiple_ccdf_log, x1); calculate_gradients_1storder(multiple_gradients3, multiple_ccdf_log, x1); + stan::math::recover_memory(); + EXPECT_NEAR(stan::math::value_of_rec(single_ccdf_log * N_REPEAT), stan::math::value_of_rec(multiple_ccdf_log), 1e-8) << "ccdf_log with repeated vector input should match " diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index b64f1400ca4..17bc4ac68f1 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -256,8 +256,8 @@ class AgradCdfTestFixture : public ::testing::Test { // works for double calculate_gradients_1storder(vector& grad, var& cdf, vector& x) { + stan::math::set_zero_all_adjoints(); cdf.grad(x, grad); - stan::math::recover_memory(); return cdf.val(); } double calculate_gradients_2ndorder(vector& grad, var& cdf, @@ -302,14 +302,14 @@ class AgradCdfTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& cdf, vector& x) { + stan::math::set_zero_all_adjoints(); cdf.val_.grad(x, grad); - stan::math::recover_memory(); return cdf.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar& cdf, vector& x) { + stan::math::set_zero_all_adjoints(); cdf.d_.grad(x, grad); - stan::math::recover_memory(); return cdf.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar& cdf, @@ -320,20 +320,20 @@ class AgradCdfTestFixture : public ::testing::Test { // works for fvar > double calculate_gradients_1storder(vector& grad, fvar>& cdf, vector& x) { + stan::math::set_zero_all_adjoints(); cdf.val_.val_.grad(x, grad); - stan::math::recover_memory(); return cdf.val_.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& cdf, vector& x) { + stan::math::set_zero_all_adjoints(); cdf.d_.val_.grad(x, grad); - stan::math::recover_memory(); return cdf.val_.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar>& cdf, vector& x) { + stan::math::set_zero_all_adjoints(); cdf.d_.d_.grad(x, grad); - stan::math::recover_memory(); return cdf.val_.val_.val(); } @@ -399,6 +399,8 @@ class AgradCdfTestFixture : public ::testing::Test { calculate_gradients_1storder(gradients, cdf, x1); test_finite_diffs_equal(parameters[n], finite_diffs, gradients); + + stan::math::recover_memory(); } } } @@ -474,6 +476,8 @@ class AgradCdfTestFixture : public ::testing::Test { test_gradients_equal(expected_gradients1, gradients1); test_gradients_equal(expected_gradients2, gradients2); test_gradients_equal(expected_gradients3, gradients3); + + stan::math::recover_memory(); } } @@ -566,6 +570,8 @@ class AgradCdfTestFixture : public ::testing::Test { calculate_gradients_1storder(multiple_gradients2, multiple_cdf, x1); calculate_gradients_1storder(multiple_gradients3, multiple_cdf, x1); + stan::math::recover_memory(); + EXPECT_NEAR(stan::math::value_of_rec(pow(single_cdf, N_REPEAT)), stan::math::value_of_rec(multiple_cdf), 1e-8) << "cdf with repeated vector input should match " diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index 786691d8e83..68e4feb299b 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -259,8 +259,8 @@ class AgradCdfLogTestFixture : public ::testing::Test { // works for double calculate_gradients_1storder(vector& grad, var& cdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); cdf_log.grad(x, grad); - stan::math::recover_memory(); return cdf_log.val(); } double calculate_gradients_2ndorder(vector& grad, var& cdf_log, @@ -308,14 +308,14 @@ class AgradCdfLogTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& cdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); cdf_log.val_.grad(x, grad); - stan::math::recover_memory(); return cdf_log.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar& cdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); cdf_log.d_.grad(x, grad); - stan::math::recover_memory(); return cdf_log.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar& cdf_log, @@ -327,22 +327,22 @@ class AgradCdfLogTestFixture : public ::testing::Test { double calculate_gradients_1storder(vector& grad, fvar>& cdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); cdf_log.val_.val_.grad(x, grad); - stan::math::recover_memory(); return cdf_log.val_.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& cdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); cdf_log.d_.val_.grad(x, grad); - stan::math::recover_memory(); return cdf_log.val_.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar>& cdf_log, vector& x) { + stan::math::set_zero_all_adjoints(); cdf_log.d_.d_.grad(x, grad); - stan::math::recover_memory(); return cdf_log.val_.val_.val(); } @@ -409,6 +409,8 @@ class AgradCdfLogTestFixture : public ::testing::Test { calculate_gradients_1storder(gradients, cdf_log, x1); test_finite_diffs_equal(parameters[n], finite_diffs, gradients); + + stan::math::recover_memory(); } } } @@ -485,6 +487,8 @@ class AgradCdfLogTestFixture : public ::testing::Test { test_gradients_equal(expected_gradients1, gradients1); test_gradients_equal(expected_gradients2, gradients2); test_gradients_equal(expected_gradients3, gradients3); + + stan::math::recover_memory(); } } @@ -576,6 +580,8 @@ class AgradCdfLogTestFixture : public ::testing::Test { calculate_gradients_1storder(multiple_gradients2, multiple_cdf_log, x1); calculate_gradients_1storder(multiple_gradients3, multiple_cdf_log, x1); + stan::math::recover_memory(); + EXPECT_NEAR(stan::math::value_of_rec(N_REPEAT * single_cdf_log), stan::math::value_of_rec(multiple_cdf_log), 1e-8) << "cdf_log with repeated vector input should match " diff --git a/test/prob/test_fixture_distr.hpp b/test/prob/test_fixture_distr.hpp index 1449340e439..9dce59a2199 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -319,8 +319,8 @@ class AgradDistributionTestFixture : public ::testing::Test { // works for double calculate_gradients_1storder(vector& grad, var& logprob, vector& x) { + stan::math::set_zero_all_adjoints(); logprob.grad(x, grad); - stan::math::recover_memory(); return logprob.val(); } double calculate_gradients_2ndorder(vector& grad, var& logprob, @@ -368,14 +368,14 @@ class AgradDistributionTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& logprob, vector& x) { + stan::math::set_zero_all_adjoints(); logprob.val_.grad(x, grad); - stan::math::recover_memory(); return logprob.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar& logprob, vector& x) { + stan::math::set_zero_all_adjoints(); logprob.d_.grad(x, grad); - stan::math::recover_memory(); return logprob.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar& logprob, @@ -387,22 +387,22 @@ class AgradDistributionTestFixture : public ::testing::Test { double calculate_gradients_1storder(vector& grad, fvar>& logprob, vector& x) { + stan::math::set_zero_all_adjoints(); logprob.val_.val_.grad(x, grad); - stan::math::recover_memory(); return logprob.val_.val_.val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& logprob, vector& x) { + stan::math::set_zero_all_adjoints(); logprob.d_.val_.grad(x, grad); - stan::math::recover_memory(); return logprob.val_.val_.val(); } double calculate_gradients_3rdorder(vector& grad, fvar>& logprob, vector& x) { + stan::math::set_zero_all_adjoints(); logprob.d_.d_.grad(x, grad); - stan::math::recover_memory(); return logprob.val_.val_.val(); } @@ -472,6 +472,8 @@ class AgradDistributionTestFixture : public ::testing::Test { test_finite_diffs_equal(parameters[n], finite_diffs, gradients); } } + + stan::math::recover_memory(); } void test_gradients_equal(const vector& expected_gradients, @@ -547,6 +549,8 @@ class AgradDistributionTestFixture : public ::testing::Test { test_gradients_equal(expected_gradients1, gradients1); test_gradients_equal(expected_gradients2, gradients2); test_gradients_equal(expected_gradients3, gradients3); + + stan::math::recover_memory(); } } @@ -641,6 +645,8 @@ class AgradDistributionTestFixture : public ::testing::Test { calculate_gradients_1storder(multiple_gradients2, multiple_lp, x1); calculate_gradients_1storder(multiple_gradients3, multiple_lp, x1); + stan::math::recover_memory(); + EXPECT_NEAR(stan::math::value_of_rec(N_REPEAT * single_lp), stan::math::value_of_rec(multiple_lp), 1e-8) << "log prob with repeated vector input should match " From 26b33a5f94d90497e7771beb090810985adaa4b2 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Wed, 26 Aug 2020 20:14:50 +0000 Subject: [PATCH 02/12] [Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final) --- test/prob/test_fixture_ccdf_log.hpp | 2 +- test/prob/test_fixture_cdf.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index 84799e50160..56770a8da20 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -409,7 +409,7 @@ class AgradCcdfLogTestFixture : public ::testing::Test { test_finite_diffs_equal(parameters[n], finite_diffs, gradients); - stan::math::recover_memory(); + stan::math::recover_memory(); } } } diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 17bc4ac68f1..f8beff3c239 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -400,7 +400,7 @@ class AgradCdfTestFixture : public ::testing::Test { test_finite_diffs_equal(parameters[n], finite_diffs, gradients); - stan::math::recover_memory(); + stan::math::recover_memory(); } } } From af06de77ce28ac3c99e8bea41b8d2f9bc3ebc4da Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 26 Aug 2020 16:31:08 -0400 Subject: [PATCH 03/12] Make probability unit tests work better with higher order gradients (Issue #2037 #2038) --- test/prob/test_fixture_ccdf_log.hpp | 9 ++- test/prob/test_fixture_cdf.hpp | 5 +- test/prob/test_fixture_cdf_log.hpp | 5 +- test/prob/test_fixture_distr.hpp | 5 +- test/prob/utility.hpp | 118 ++++++++++++++-------------- 5 files changed, 74 insertions(+), 68 deletions(-) diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index 84799e50160..efb860408e0 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -273,7 +273,7 @@ class AgradCcdfLogTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& ccdf_log, vector& x) { - x.push_back(ccdf_log.d_); + grad.push_back(ccdf_log.d_); return ccdf_log.val(); } double calculate_gradients_2ndorder(vector& grad, @@ -289,12 +289,13 @@ class AgradCcdfLogTestFixture : public ::testing::Test { double calculate_gradients_1storder(vector& grad, fvar>& ccdf_log, vector& x) { - x.push_back(ccdf_log.d_.val_); + grad.push_back(ccdf_log.d_.val_); return ccdf_log.val().val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& ccdf_log, vector& x) { + grad.push_back(ccdf_log.d_.d_); return ccdf_log.val().val(); } double calculate_gradients_3rdorder(vector& grad, @@ -576,8 +577,8 @@ class AgradCcdfLogTestFixture : public ::testing::Test { add_vars(x3, p0, p1, p2, p3, p4, p5); calculate_gradients_1storder(multiple_gradients1, multiple_ccdf_log, x1); - calculate_gradients_1storder(multiple_gradients2, multiple_ccdf_log, x1); - calculate_gradients_1storder(multiple_gradients3, multiple_ccdf_log, x1); + calculate_gradients_2ndorder(multiple_gradients2, multiple_ccdf_log, x1); + calculate_gradients_3rdorder(multiple_gradients3, multiple_ccdf_log, x1); stan::math::recover_memory(); diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 17bc4ac68f1..6b6656b06cb 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -272,7 +272,7 @@ class AgradCdfTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& cdf, vector& x) { - x.push_back(cdf.d_); + grad.push_back(cdf.d_); return cdf.val(); } double calculate_gradients_2ndorder(vector& grad, fvar& cdf, @@ -287,11 +287,12 @@ class AgradCdfTestFixture : public ::testing::Test { // works for fvar > double calculate_gradients_1storder(vector& grad, fvar>& cdf, vector& x) { - x.push_back(cdf.d_.val_); + grad.push_back(cdf.d_.val_); return cdf.val().val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& cdf, vector& x) { + grad.push_back(cdf.d_.d_); return cdf.val().val(); } double calculate_gradients_3rdorder(vector& grad, diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index 68e4feb299b..e4c552d411c 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -275,7 +275,7 @@ class AgradCdfLogTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& cdf_log, vector& x) { - x.push_back(cdf_log.d_); + grad.push_back(cdf_log.d_); return cdf_log.val(); } double calculate_gradients_2ndorder(vector& grad, @@ -291,12 +291,13 @@ class AgradCdfLogTestFixture : public ::testing::Test { double calculate_gradients_1storder(vector& grad, fvar>& cdf_log, vector& x) { - x.push_back(cdf_log.d_.val_); + grad.push_back(cdf_log.d_.val_); return cdf_log.val().val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& cdf_log, vector& x) { + grad.push_back(cdf_log.d_.d_); return cdf_log.val().val(); } double calculate_gradients_3rdorder(vector& grad, diff --git a/test/prob/test_fixture_distr.hpp b/test/prob/test_fixture_distr.hpp index 9dce59a2199..d28b9b4e646 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -335,7 +335,7 @@ class AgradDistributionTestFixture : public ::testing::Test { // works for fvar double calculate_gradients_1storder(vector& grad, fvar& logprob, vector& x) { - x.push_back(logprob.d_); + grad.push_back(logprob.d_); return logprob.val(); } double calculate_gradients_2ndorder(vector& grad, @@ -351,12 +351,13 @@ class AgradDistributionTestFixture : public ::testing::Test { double calculate_gradients_1storder(vector& grad, fvar>& logprob, vector& x) { - x.push_back(logprob.d_.val_); + grad.push_back(logprob.d_.val_); return logprob.val().val(); } double calculate_gradients_2ndorder(vector& grad, fvar>& logprob, vector& x) { + grad.push_back(logprob.d_.d_); return logprob.val().val(); } double calculate_gradients_3rdorder(vector& grad, diff --git a/test/prob/utility.hpp b/test/prob/utility.hpp index 53f9e966d0f..14376e04f38 100644 --- a/test/prob/utility.hpp +++ b/test/prob/utility.hpp @@ -54,13 +54,69 @@ std::ostream& operator<<(std::ostream& os, const vector& param) { } // namespace std // ------------------------------------------------------------ + +template +T get_param(const vector& params, const size_t n) { + T param = 0; + if (n < params.size()) + param = params[n]; + return param; +} + +template <> +empty get_param(const vector& /*params*/, const size_t /*n*/) { + return empty(); +} + +template <> +fvar get_param>(const vector& params, + const size_t n) { + fvar param = 0; + if (n < params.size()) { + param = params[n]; + param.d_ = 1.0; + } + return param; +} +template <> +fvar get_param>(const vector& params, const size_t n) { + fvar param = 0; + if (n < params.size()) { + param = params[n]; + param.d_ = 1.0; + } + return param; +} +template <> +fvar> get_param>>(const vector& params, + const size_t n) { + fvar> param = 0; + if (n < params.size()) { + param = params[n]; + param.d_ = 1.0; + } + return param; +} +template <> +fvar> get_param>>(const vector& params, + const size_t n) { + fvar> param = 0; + if (n < params.size()) { + param = params[n]; + param.d_ = 1.0; + } + return param; +} + +// ------------------------------------------------------------ + // default template handles Eigen::Matrix template T get_params(const vector>& parameters, const size_t p) { T param(parameters.size()); for (size_t n = 0; n < parameters.size(); n++) if (p < parameters[0].size()) - param(n) = parameters[n][p]; + param(n) = get_param>(parameters[n], p); return param; } @@ -215,7 +271,7 @@ T get_params(const vector>& parameters, const size_t /*n*/, T param(parameters.size()); for (size_t i = 0; i < parameters.size(); i++) if (p < parameters[0].size()) - param(i) = parameters[i][p]; + param(i) = get_param>(parameters[i], p); return param; } @@ -376,9 +432,9 @@ T get_repeated_params(const vector& parameters, const size_t p, T param(N_REPEAT); for (size_t n = 0; n < N_REPEAT; n++) { if (p < parameters.size()) - param(n) = parameters[p]; + param(n) = get_param>(parameters, p); else - param(0) = 0; + param(n) = 0; } return param; } @@ -537,60 +593,6 @@ vector>> get_repeated_params>>>( // ------------------------------------------------------------ -template -T get_param(const vector& params, const size_t n) { - T param = 0; - if (n < params.size()) - param = params[n]; - return param; -} - -template <> -empty get_param(const vector& /*params*/, const size_t /*n*/) { - return empty(); -} -template <> -fvar get_param>(const vector& params, - const size_t n) { - fvar param = 0; - if (n < params.size()) { - param = params[n]; - param.d_ = 1.0; - } - return param; -} -template <> -fvar get_param>(const vector& params, const size_t n) { - fvar param = 0; - if (n < params.size()) { - param = params[n]; - param.d_ = 1.0; - } - return param; -} -template <> -fvar> get_param>>(const vector& params, - const size_t n) { - fvar> param = 0; - if (n < params.size()) { - param = params[n]; - param.d_ = 1.0; - } - return param; -} -template <> -fvar> get_param>>(const vector& params, - const size_t n) { - fvar> param = 0; - if (n < params.size()) { - param = params[n]; - param.d_ = 1.0; - } - return param; -} - -// ------------------------------------------------------------ - template typename scalar_type::type select_var_param( const vector>& parameters, const size_t n, const size_t p) { From 80c540be612a9a48b26a4788e49eb791d962db86 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 27 Aug 2020 19:05:03 -0400 Subject: [PATCH 04/12] Fixed high order gradients in `test_repeat_as_vector` test (Issue #2038) --- test/prob/test_fixture_ccdf_log.hpp | 4 ++-- test/prob/test_fixture_cdf.hpp | 15 +++++++-------- test/prob/test_fixture_cdf_log.hpp | 4 ++-- test/prob/test_fixture_distr.hpp | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index 3a2ef290fd3..11d755d62e8 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -577,8 +577,8 @@ class AgradCcdfLogTestFixture : public ::testing::Test { add_vars(x3, p0, p1, p2, p3, p4, p5); calculate_gradients_1storder(multiple_gradients1, multiple_ccdf_log, x1); - calculate_gradients_2ndorder(multiple_gradients2, multiple_ccdf_log, x1); - calculate_gradients_3rdorder(multiple_gradients3, multiple_ccdf_log, x1); + calculate_gradients_2ndorder(multiple_gradients2, multiple_ccdf_log, x2); + calculate_gradients_3rdorder(multiple_gradients3, multiple_ccdf_log, x3); stan::math::recover_memory(); diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 8c786ba31fc..410b60daf6b 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -491,7 +491,7 @@ class AgradCdfTestFixture : public ::testing::Test { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_FLOAT_EQ( - single_gradients[pos_single] * pow(single_cdf, N_REPEAT - 1), + single_gradients[pos_single] / N_REPEAT, multiple_gradients[pos_multiple]) << "Comparison of single_gradient value to vectorized gradient " "failed"; @@ -499,8 +499,7 @@ class AgradCdfTestFixture : public ::testing::Test { } pos_single++; } else { - EXPECT_FLOAT_EQ(N_REPEAT * single_gradients[pos_single] - * pow(single_cdf, N_REPEAT - 1), + EXPECT_FLOAT_EQ(single_gradients[pos_single], multiple_gradients[pos_multiple]) << "Comparison of single_gradient value to vectorized gradient " "failed"; @@ -539,8 +538,8 @@ class AgradCdfTestFixture : public ::testing::Test { add_vars(s3, p0_, p1_, p2_, p3_, p4_, p5_); T_return_type cdf - = TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_); + = stan::math::pow(TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_), N_REPEAT); double single_cdf = calculate_gradients_1storder(single_gradients1, cdf, s1); @@ -568,12 +567,12 @@ class AgradCdfTestFixture : public ::testing::Test { add_vars(x3, p0, p1, p2, p3, p4, p5); calculate_gradients_1storder(multiple_gradients1, multiple_cdf, x1); - calculate_gradients_1storder(multiple_gradients2, multiple_cdf, x1); - calculate_gradients_1storder(multiple_gradients3, multiple_cdf, x1); + calculate_gradients_2ndorder(multiple_gradients2, multiple_cdf, x2); + calculate_gradients_3rdorder(multiple_gradients3, multiple_cdf, x3); stan::math::recover_memory(); - EXPECT_NEAR(stan::math::value_of_rec(pow(single_cdf, N_REPEAT)), + EXPECT_NEAR(stan::math::value_of_rec(single_cdf), stan::math::value_of_rec(multiple_cdf), 1e-8) << "cdf with repeated vector input should match " << "a multiple of cdf of single input"; diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index e4c552d411c..3ce26fc4ef2 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -578,8 +578,8 @@ class AgradCdfLogTestFixture : public ::testing::Test { add_vars(x3, p0, p1, p2, p3, p4, p5); calculate_gradients_1storder(multiple_gradients1, multiple_cdf_log, x1); - calculate_gradients_1storder(multiple_gradients2, multiple_cdf_log, x1); - calculate_gradients_1storder(multiple_gradients3, multiple_cdf_log, x1); + calculate_gradients_2ndorder(multiple_gradients2, multiple_cdf_log, x2); + calculate_gradients_3rdorder(multiple_gradients3, multiple_cdf_log, x3); stan::math::recover_memory(); diff --git a/test/prob/test_fixture_distr.hpp b/test/prob/test_fixture_distr.hpp index d28b9b4e646..29619d108cb 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -643,8 +643,8 @@ class AgradDistributionTestFixture : public ::testing::Test { add_vars(x3, p0, p1, p2, p3, p4, p5); calculate_gradients_1storder(multiple_gradients1, multiple_lp, x1); - calculate_gradients_1storder(multiple_gradients2, multiple_lp, x1); - calculate_gradients_1storder(multiple_gradients3, multiple_lp, x1); + calculate_gradients_2ndorder(multiple_gradients2, multiple_lp, x2); + calculate_gradients_3rdorder(multiple_gradients3, multiple_lp, x3); stan::math::recover_memory(); From 204dd7b796b236f1cdfbfdd5dad257a9a946d1a7 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Thu, 27 Aug 2020 23:10:49 +0000 Subject: [PATCH 05/12] [Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final) --- test/prob/test_fixture_cdf.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 410b60daf6b..98b6a2376e2 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -490,9 +490,8 @@ class AgradCdfTestFixture : public ::testing::Test { const size_t N_REPEAT) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { - EXPECT_FLOAT_EQ( - single_gradients[pos_single] / N_REPEAT, - multiple_gradients[pos_multiple]) + EXPECT_FLOAT_EQ(single_gradients[pos_single] / N_REPEAT, + multiple_gradients[pos_multiple]) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; @@ -537,9 +536,10 @@ class AgradCdfTestFixture : public ::testing::Test { add_vars(s2, p0_, p1_, p2_, p3_, p4_, p5_); add_vars(s3, p0_, p1_, p2_, p3_, p4_, p5_); - T_return_type cdf - = stan::math::pow(TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_), N_REPEAT); + T_return_type cdf = stan::math::pow( + TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_), + N_REPEAT); double single_cdf = calculate_gradients_1storder(single_gradients1, cdf, s1); From afdd7ceb5973fff04ab53a3c1fa71d2181c72648 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 27 Aug 2020 19:27:45 -0400 Subject: [PATCH 06/12] Added using statements to avoid pow ambiguities (Issue #2038) --- test/prob/test_fixture_cdf.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 410b60daf6b..259ef5cc0c0 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -509,6 +509,9 @@ class AgradCdfTestFixture : public ::testing::Test { } void test_repeat_as_vector() { + using std::pow; + using stan::math::pow; + if (!any_vector::value) { SUCCEED() << "No test for non-vector arguments"; return; @@ -538,8 +541,8 @@ class AgradCdfTestFixture : public ::testing::Test { add_vars(s3, p0_, p1_, p2_, p3_, p4_, p5_); T_return_type cdf - = stan::math::pow(TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_), N_REPEAT); + = pow(TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_), N_REPEAT); double single_cdf = calculate_gradients_1storder(single_gradients1, cdf, s1); From 97a83bb9d2e74de49c633a8dac1892cf71470a2d Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Thu, 27 Aug 2020 19:29:48 -0400 Subject: [PATCH 07/12] [Jenkins] auto-formatting by clang-format version 6.0.1-14 (tags/RELEASE_601/final) --- test/prob/test_fixture_cdf.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 2e3ed49560b..82aeae097b9 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -508,8 +508,8 @@ class AgradCdfTestFixture : public ::testing::Test { } void test_repeat_as_vector() { - using std::pow; using stan::math::pow; + using std::pow; if (!any_vector::value) { SUCCEED() << "No test for non-vector arguments"; @@ -539,9 +539,10 @@ class AgradCdfTestFixture : public ::testing::Test { add_vars(s2, p0_, p1_, p2_, p3_, p4_, p5_); add_vars(s3, p0_, p1_, p2_, p3_, p4_, p5_); - T_return_type cdf - = pow(TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_), N_REPEAT); + T_return_type cdf = pow( + TestClass.template cdf(p0_, p1_, p2_, p3_, p4_, p5_), + N_REPEAT); double single_cdf = calculate_gradients_1storder(single_gradients1, cdf, s1); From bb234732c09a51633162a74248265714cb2a0faa Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 28 Aug 2020 17:24:31 -0400 Subject: [PATCH 08/12] Fixed a few tests and update tolerances (Issue #2037) --- stan/math/prim/prob/frechet_lpdf.hpp | 7 +++---- test/prob/binomial/binomial_cdf_test.hpp | 4 ++-- test/prob/gamma/gamma_ccdf_log_test.hpp | 16 ++++++++-------- test/prob/gumbel/gumbel_test.hpp | 2 +- .../inv_chi_square_ccdf_log_test.hpp | 2 +- test/prob/test_fixture_ccdf_log.hpp | 10 +++++----- test/prob/test_fixture_cdf.hpp | 10 +++++----- test/prob/test_fixture_cdf_log.hpp | 10 +++++----- test/prob/test_fixture_distr.hpp | 10 +++++----- 9 files changed, 35 insertions(+), 36 deletions(-) diff --git a/stan/math/prim/prob/frechet_lpdf.hpp b/stan/math/prim/prob/frechet_lpdf.hpp index 2f9d4105f83..6e9ae9238e5 100644 --- a/stan/math/prim/prob/frechet_lpdf.hpp +++ b/stan/math/prim/prob/frechet_lpdf.hpp @@ -81,7 +81,7 @@ return_type_t frechet_lpdf(const T_y& y, T_partials_return, T_y> inv_y(size(y)); for (size_t i = 0; i < stan::math::size(y); i++) { - inv_y[i] = 1.0 / value_of(y_vec[i]); + inv_y[i] = inv(value_of(y_vec[i])); } VectorBuilder::value, @@ -107,10 +107,9 @@ return_type_t frechet_lpdf(const T_y& y, logp -= sigma_div_y_pow_alpha[n]; if (!is_constant_all::value) { - const T_partials_return inv_y_dbl = value_of(inv_y[n]); ops_partials.edge1_.partials_[n] - += -(alpha_dbl + 1.0) * inv_y_dbl - + alpha_dbl * sigma_div_y_pow_alpha[n] * inv_y_dbl; + += -(alpha_dbl + 1.0) * inv_y[n] + + alpha_dbl * sigma_div_y_pow_alpha[n] * inv_y[n]; } if (!is_constant_all::value) { ops_partials.edge2_.partials_[n] diff --git a/test/prob/binomial/binomial_cdf_test.hpp b/test/prob/binomial/binomial_cdf_test.hpp index b12ebab1650..d4ed2ebda8e 100644 --- a/test/prob/binomial/binomial_cdf_test.hpp +++ b/test/prob/binomial/binomial_cdf_test.hpp @@ -52,10 +52,10 @@ class AgradCdfBinomial : public AgradCdfTest { using std::exp; using std::log; - stan::return_type_t cdf(1); + stan::return_type_t cdf(0); for (int i = 0; i <= n; i++) { - cdf *= binomial_coefficient(N, i) + cdf += binomial_coefficient(N, i) * exp(i * log(theta) + (N - i) * log(1 - theta)); } diff --git a/test/prob/gamma/gamma_ccdf_log_test.hpp b/test/prob/gamma/gamma_ccdf_log_test.hpp index 239a0dc2c1a..b041962a3e7 100644 --- a/test/prob/gamma/gamma_ccdf_log_test.hpp +++ b/test/prob/gamma/gamma_ccdf_log_test.hpp @@ -32,11 +32,11 @@ class AgradCcdfLogGamma : public AgradCcdfLogTest { ccdf_log.push_back( std::log(1.0 - 0.6321205588285576659757)); // expected ccdf_log - param[0] = 16.0; // y - param[1] = 3.0; // alpha - param[2] = 3.0; // beta + param[0] = 9.0; // y + param[1] = 1.2; // alpha + param[2] = 1.2; // beta parameters.push_back(param); - ccdf_log.push_back(std::log(1.7116220633718619e-18)); // expected ccdf_log + ccdf_log.push_back(-10.221534317077268); // expected ccdf_log } void invalid_values(vector& index, vector& value) { @@ -90,10 +90,10 @@ class AgradCcdfLogGamma : public AgradCcdfLogTest { stan::return_type_t ccdf_log_function( const T_y& y, const T_shape& alpha, const T_inv_scale& beta, const T3&, const T4&, const T5&) { - using boost::math::gamma_q; - using stan::math::gamma_q; - using std::log; + using boost::math::gamma_p; + using stan::math::gamma_p; + using stan::math::log1m; - return log(gamma_q(alpha, beta * y)); + return log1m(gamma_p(alpha, beta * y)); } }; diff --git a/test/prob/gumbel/gumbel_test.hpp b/test/prob/gumbel/gumbel_test.hpp index 285fcbec812..e4134f3a200 100644 --- a/test/prob/gumbel/gumbel_test.hpp +++ b/test/prob/gumbel/gumbel_test.hpp @@ -88,6 +88,6 @@ class AgradDistributionGumbel : public AgradDistributionTest { stan::return_type_t log_prob_function( const T_y& y, const T_loc& mu, const T_scale& beta, const T3&, const T4&, const T5&) { - return -log(beta) - (y - mu) / beta + exp((mu - y) / beta); + return -log(beta) - (y - mu) / beta - exp((mu - y) / beta); } }; diff --git a/test/prob/inv_chi_square/inv_chi_square_ccdf_log_test.hpp b/test/prob/inv_chi_square/inv_chi_square_ccdf_log_test.hpp index d9ea63b2e82..f57a7baffae 100644 --- a/test/prob/inv_chi_square/inv_chi_square_ccdf_log_test.hpp +++ b/test/prob/inv_chi_square/inv_chi_square_ccdf_log_test.hpp @@ -56,6 +56,6 @@ class AgradCcdfLogInvChiSquare : public AgradCcdfLogTest { const T5&) { using stan::math::gamma_p; - return log(1.0 - gamma_p(0.5 * nu, 0.5 / y)); + return log(gamma_p(0.5 * nu, 0.5 / y)); } }; diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index 11d755d62e8..5d116a9de5c 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -421,7 +421,7 @@ class AgradCcdfLogTestFixture : public ::testing::Test { << "Number of expected gradients and calculated gradients must match " "-- error in test fixture"; for (size_t i = 0; i < expected_gradients.size(); i++) { - EXPECT_FLOAT_EQ(expected_gradients[i], gradients[i]) + EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-4) << "Comparison of expected gradient to calculated gradient failed"; } } @@ -501,16 +501,16 @@ class AgradCcdfLogTestFixture : public ::testing::Test { const size_t N_REPEAT) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { - EXPECT_FLOAT_EQ(single_gradients[pos_single], - multiple_gradients[pos_multiple]) + EXPECT_NEAR(single_gradients[pos_single], + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; } pos_single++; } else { - EXPECT_FLOAT_EQ(N_REPEAT * single_gradients[pos_single], - multiple_gradients[pos_multiple]) + EXPECT_NEAR(N_REPEAT * single_gradients[pos_single], + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 2e3ed49560b..1db989dc251 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -412,7 +412,7 @@ class AgradCdfTestFixture : public ::testing::Test { << "Number of expected gradients and calculated gradients must match " "-- error in test fixture"; for (size_t i = 0; i < expected_gradients.size(); i++) { - EXPECT_FLOAT_EQ(expected_gradients[i], gradients[i]) + EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-7) << "Comparison of expected gradient to calculated gradient failed"; } } @@ -490,16 +490,16 @@ class AgradCdfTestFixture : public ::testing::Test { const size_t N_REPEAT) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { - EXPECT_FLOAT_EQ(single_gradients[pos_single] / N_REPEAT, - multiple_gradients[pos_multiple]) + EXPECT_NEAR(single_gradients[pos_single] / N_REPEAT, + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; } pos_single++; } else { - EXPECT_FLOAT_EQ(single_gradients[pos_single], - multiple_gradients[pos_multiple]) + EXPECT_NEAR(single_gradients[pos_single], + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index 3ce26fc4ef2..1f2910b3447 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -422,7 +422,7 @@ class AgradCdfLogTestFixture : public ::testing::Test { << "Number of expected gradients and calculated gradients must match " "-- error in test fixture"; for (size_t i = 0; i < expected_gradients.size(); i++) { - EXPECT_FLOAT_EQ(expected_gradients[i], gradients[i]) + EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-7) << "Comparison of expected gradient to calculated gradient failed"; } } @@ -502,16 +502,16 @@ class AgradCdfLogTestFixture : public ::testing::Test { const size_t N_REPEAT) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { - EXPECT_FLOAT_EQ(single_gradients[pos_single], - multiple_gradients[pos_multiple]) + EXPECT_NEAR(single_gradients[pos_single], + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; } pos_single++; } else { - EXPECT_FLOAT_EQ(N_REPEAT * single_gradients[pos_single], - multiple_gradients[pos_multiple]) + EXPECT_NEAR(N_REPEAT * single_gradients[pos_single], + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; diff --git a/test/prob/test_fixture_distr.hpp b/test/prob/test_fixture_distr.hpp index 29619d108cb..c0dffa6cc14 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -483,7 +483,7 @@ class AgradDistributionTestFixture : public ::testing::Test { << "Number of expected gradients and calculated gradients must match " "-- error in test fixture"; for (size_t i = 0; i < expected_gradients.size(); i++) { - EXPECT_FLOAT_EQ(expected_gradients[i], gradients[i]) + EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-7) << "Comparison of expected gradient to calculated gradient failed"; } } @@ -563,16 +563,16 @@ class AgradDistributionTestFixture : public ::testing::Test { const size_t N_REPEAT) { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { - EXPECT_FLOAT_EQ(single_gradients[pos_single], - multiple_gradients[pos_multiple]) + EXPECT_NEAR(single_gradients[pos_single], + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; } pos_single++; } else { - EXPECT_FLOAT_EQ(single_gradients[pos_single] * double(N_REPEAT), - multiple_gradients[pos_multiple]) + EXPECT_NEAR(single_gradients[pos_single] * double(N_REPEAT), + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; From 13221caf383cbce4f8584e4bce23064967a8086d Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Fri, 28 Aug 2020 17:32:03 -0400 Subject: [PATCH 09/12] [Jenkins] auto-formatting by clang-format version 6.0.1-14 (tags/RELEASE_601/final) --- test/prob/gamma/gamma_ccdf_log_test.hpp | 4 ++-- test/prob/test_fixture_ccdf_log.hpp | 4 ++-- test/prob/test_fixture_cdf.hpp | 4 ++-- test/prob/test_fixture_cdf_log.hpp | 4 ++-- test/prob/test_fixture_distr.hpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/prob/gamma/gamma_ccdf_log_test.hpp b/test/prob/gamma/gamma_ccdf_log_test.hpp index b041962a3e7..3f5bb385edd 100644 --- a/test/prob/gamma/gamma_ccdf_log_test.hpp +++ b/test/prob/gamma/gamma_ccdf_log_test.hpp @@ -33,8 +33,8 @@ class AgradCcdfLogGamma : public AgradCcdfLogTest { std::log(1.0 - 0.6321205588285576659757)); // expected ccdf_log param[0] = 9.0; // y - param[1] = 1.2; // alpha - param[2] = 1.2; // beta + param[1] = 1.2; // alpha + param[2] = 1.2; // beta parameters.push_back(param); ccdf_log.push_back(-10.221534317077268); // expected ccdf_log } diff --git a/test/prob/test_fixture_ccdf_log.hpp b/test/prob/test_fixture_ccdf_log.hpp index 5d116a9de5c..afb7595b672 100644 --- a/test/prob/test_fixture_ccdf_log.hpp +++ b/test/prob/test_fixture_ccdf_log.hpp @@ -502,7 +502,7 @@ class AgradCcdfLogTestFixture : public ::testing::Test { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single], - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; @@ -510,7 +510,7 @@ class AgradCcdfLogTestFixture : public ::testing::Test { pos_single++; } else { EXPECT_NEAR(N_REPEAT * single_gradients[pos_single], - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 455b4a47355..802d66b715b 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -491,7 +491,7 @@ class AgradCdfTestFixture : public ::testing::Test { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single] / N_REPEAT, - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; @@ -499,7 +499,7 @@ class AgradCdfTestFixture : public ::testing::Test { pos_single++; } else { EXPECT_NEAR(single_gradients[pos_single], - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index 1f2910b3447..920caba71d5 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -503,7 +503,7 @@ class AgradCdfLogTestFixture : public ::testing::Test { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single], - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; @@ -511,7 +511,7 @@ class AgradCdfLogTestFixture : public ::testing::Test { pos_single++; } else { EXPECT_NEAR(N_REPEAT * single_gradients[pos_single], - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; diff --git a/test/prob/test_fixture_distr.hpp b/test/prob/test_fixture_distr.hpp index c0dffa6cc14..311c649667b 100644 --- a/test/prob/test_fixture_distr.hpp +++ b/test/prob/test_fixture_distr.hpp @@ -564,7 +564,7 @@ class AgradDistributionTestFixture : public ::testing::Test { if (is_vec) { for (size_t i = 0; i < N_REPEAT; i++) { EXPECT_NEAR(single_gradients[pos_single], - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_multiple++; @@ -572,7 +572,7 @@ class AgradDistributionTestFixture : public ::testing::Test { pos_single++; } else { EXPECT_NEAR(single_gradients[pos_single] * double(N_REPEAT), - multiple_gradients[pos_multiple], 1e-7) + multiple_gradients[pos_multiple], 1e-7) << "Comparison of single_gradient value to vectorized gradient " "failed"; pos_single++; From cb7830677a3ac5c2d35c87cc0c7f7dd8bb70ab47 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 31 Aug 2020 23:56:34 -0400 Subject: [PATCH 10/12] Loosened tolerances in probability cdf and cdf log gradient tests (Issue #2037) --- test/prob/test_fixture_cdf.hpp | 2 +- test/prob/test_fixture_cdf_log.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/prob/test_fixture_cdf.hpp b/test/prob/test_fixture_cdf.hpp index 455b4a47355..d7ed2ced9e9 100644 --- a/test/prob/test_fixture_cdf.hpp +++ b/test/prob/test_fixture_cdf.hpp @@ -412,7 +412,7 @@ class AgradCdfTestFixture : public ::testing::Test { << "Number of expected gradients and calculated gradients must match " "-- error in test fixture"; for (size_t i = 0; i < expected_gradients.size(); i++) { - EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-7) + EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-4) << "Comparison of expected gradient to calculated gradient failed"; } } diff --git a/test/prob/test_fixture_cdf_log.hpp b/test/prob/test_fixture_cdf_log.hpp index 1f2910b3447..c9280fac84e 100644 --- a/test/prob/test_fixture_cdf_log.hpp +++ b/test/prob/test_fixture_cdf_log.hpp @@ -422,7 +422,7 @@ class AgradCdfLogTestFixture : public ::testing::Test { << "Number of expected gradients and calculated gradients must match " "-- error in test fixture"; for (size_t i = 0; i < expected_gradients.size(); i++) { - EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-7) + EXPECT_NEAR(expected_gradients[i], gradients[i], 1e-4) << "Comparison of expected gradient to calculated gradient failed"; } } From 320132e778478c4d7221025724ece3627db548e4 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 1 Sep 2020 14:17:08 -0400 Subject: [PATCH 11/12] Picked an easier set of parameters for normal cdf log test instead of making the tolerances bigger (Issue #2037) --- test/prob/normal/normal_cdf_log_test.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/prob/normal/normal_cdf_log_test.hpp b/test/prob/normal/normal_cdf_log_test.hpp index bbf60239432..7798ad38867 100644 --- a/test/prob/normal/normal_cdf_log_test.hpp +++ b/test/prob/normal/normal_cdf_log_test.hpp @@ -26,9 +26,9 @@ class AgradCdfLogNormal : public AgradCdfLogTest { param[0] = -2; // y param[1] = 0; // mu - param[2] = 1; // sigma + param[2] = 1.5; // sigma parameters.push_back(param); - cdf_log.push_back(-3.78318433368203166367); // expected cdf_log + cdf_log.push_back(-2.3945773661586438052); // expected cdf_log param[0] = -3.5; // y param[1] = 1.9; // mu From 3c42e1f825e89e9daf1fa63bbeaaef53ba5ac607 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Tue, 1 Sep 2020 14:19:28 -0400 Subject: [PATCH 12/12] [Jenkins] auto-formatting by clang-format version 6.0.1-14 (tags/RELEASE_601/final) --- test/prob/normal/normal_cdf_log_test.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/prob/normal/normal_cdf_log_test.hpp b/test/prob/normal/normal_cdf_log_test.hpp index 7798ad38867..2e67ca3f0e5 100644 --- a/test/prob/normal/normal_cdf_log_test.hpp +++ b/test/prob/normal/normal_cdf_log_test.hpp @@ -24,9 +24,9 @@ class AgradCdfLogNormal : public AgradCdfLogTest { parameters.push_back(param); cdf_log.push_back(-0.1727537790234499326392); // expected cdf_log - param[0] = -2; // y - param[1] = 0; // mu - param[2] = 1.5; // sigma + param[0] = -2; // y + param[1] = 0; // mu + param[2] = 1.5; // sigma parameters.push_back(param); cdf_log.push_back(-2.3945773661586438052); // expected cdf_log