From 972556be0878bc9c211e7664e4c6f525542abb0b Mon Sep 17 00:00:00 2001 From: Sean Talts Date: Sat, 19 Oct 2019 11:26:01 -0400 Subject: [PATCH 1/2] Fix integrate_1d to use msgs ostream pointer like all other functions --- stan/math/prim/arr/functor/integrate_1d.hpp | 4 ++-- stan/math/rev/arr/functor/integrate_1d.hpp | 14 +++++++------- .../math/prim/arr/functor/integrate_1d_test.cpp | 2 +- .../math/rev/arr/functor/integrate_1d_test.cpp | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/stan/math/prim/arr/functor/integrate_1d.hpp b/stan/math/prim/arr/functor/integrate_1d.hpp index ed6f3788c4f..97a416572d8 100644 --- a/stan/math/prim/arr/functor/integrate_1d.hpp +++ b/stan/math/prim/arr/functor/integrate_1d.hpp @@ -195,7 +195,7 @@ template inline double integrate_1d( const F& f, const double a, const double b, const std::vector& theta, const std::vector& x_r, - const std::vector& x_i, std::ostream& msgs, + const std::vector& x_i, std::ostream* msgs, const double relative_tolerance = std::sqrt(std::numeric_limits::epsilon())) { static const char* function = "integrate_1d"; @@ -209,7 +209,7 @@ inline double integrate_1d( } else { return integrate( std::bind(f, std::placeholders::_1, std::placeholders::_2, - theta, x_r, x_i, &msgs), + theta, x_r, x_i, msgs), a, b, relative_tolerance); } } diff --git a/stan/math/rev/arr/functor/integrate_1d.hpp b/stan/math/rev/arr/functor/integrate_1d.hpp index 1426e73f5fc..b68a8727a9e 100644 --- a/stan/math/rev/arr/functor/integrate_1d.hpp +++ b/stan/math/rev/arr/functor/integrate_1d.hpp @@ -32,7 +32,7 @@ inline double gradient_of_f(const F &f, const double &x, const double &xc, const std::vector &theta_vals, const std::vector &x_r, const std::vector &x_i, size_t n, - std::ostream &msgs) { + std::ostream* msgs) { double gradient = 0.0; start_nested(); std::vector theta_var(theta_vals.size()); @@ -40,7 +40,7 @@ inline double gradient_of_f(const F &f, const double &x, const double &xc, for (size_t i = 0; i < theta_vals.size(); i++) { theta_var[i] = theta_vals[i]; } - var fx = f(x, xc, theta_var, x_r, x_i, &msgs); + var fx = f(x, xc, theta_var, x_r, x_i, msgs); fx.grad(); gradient = theta_var[n].adj(); if (is_nan(gradient)) { @@ -119,7 +119,7 @@ template integrate_1d( const F &f, const T_a &a, const T_b &b, const std::vector &theta, const std::vector &x_r, const std::vector &x_i, - std::ostream &msgs, + std::ostream *msgs, const double relative_tolerance = std::sqrt(std::numeric_limits::epsilon())) { static const char *function = "integrate_1d"; @@ -134,7 +134,7 @@ inline return_type_t integrate_1d( } else { double integral = integrate( std::bind(f, std::placeholders::_1, std::placeholders::_2, - value_of(theta), x_r, x_i, &msgs), + value_of(theta), x_r, x_i, msgs), value_of(a), value_of(b), relative_tolerance); size_t N_theta_vars = is_var::value ? theta.size() : 0; @@ -148,7 +148,7 @@ inline return_type_t integrate_1d( dintegral_dtheta[n] = integrate( std::bind(gradient_of_f, f, std::placeholders::_1, std::placeholders::_2, theta_vals, x_r, x_i, n, - std::ref(msgs)), + msgs), value_of(a), value_of(b), relative_tolerance); theta_concat[n] = theta[n]; } @@ -157,13 +157,13 @@ inline return_type_t integrate_1d( if (!is_inf(a) && is_var::value) { theta_concat.push_back(a); dintegral_dtheta.push_back( - -value_of(f(value_of(a), 0.0, theta, x_r, x_i, &msgs))); + -value_of(f(value_of(a), 0.0, theta, x_r, x_i, msgs))); } if (!is_inf(b) && is_var::value) { theta_concat.push_back(b); dintegral_dtheta.push_back( - value_of(f(value_of(b), 0.0, theta, x_r, x_i, &msgs))); + value_of(f(value_of(b), 0.0, theta, x_r, x_i, msgs))); } return precomputed_gradients(integral, theta_concat, dintegral_dtheta); diff --git a/test/unit/math/prim/arr/functor/integrate_1d_test.cpp b/test/unit/math/prim/arr/functor/integrate_1d_test.cpp index 5eedf20e313..b004b0f8388 100644 --- a/test/unit/math/prim/arr/functor/integrate_1d_test.cpp +++ b/test/unit/math/prim/arr/functor/integrate_1d_test.cpp @@ -6,7 +6,7 @@ #include #include -std::ostringstream msgs; +std::ostringstream* msgs = nullptr; struct f1 { template diff --git a/test/unit/math/rev/arr/functor/integrate_1d_test.cpp b/test/unit/math/rev/arr/functor/integrate_1d_test.cpp index 9cc5710d980..694eee5f66a 100644 --- a/test/unit/math/rev/arr/functor/integrate_1d_test.cpp +++ b/test/unit/math/rev/arr/functor/integrate_1d_test.cpp @@ -8,7 +8,7 @@ #include #include -std::ostringstream msgs; +std::ostringstream* msgs = nullptr; struct f1 { template From fe103359853bd0a12648179c137b34d264935820 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Sat, 19 Oct 2019 11:28:30 -0400 Subject: [PATCH 2/2] [Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/stable/2017-11-14) --- stan/math/rev/arr/functor/integrate_1d.hpp | 2 +- test/unit/math/prim/arr/functor/integrate_1d_test.cpp | 2 +- test/unit/math/rev/arr/functor/integrate_1d_test.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stan/math/rev/arr/functor/integrate_1d.hpp b/stan/math/rev/arr/functor/integrate_1d.hpp index b68a8727a9e..1356c40f799 100644 --- a/stan/math/rev/arr/functor/integrate_1d.hpp +++ b/stan/math/rev/arr/functor/integrate_1d.hpp @@ -32,7 +32,7 @@ inline double gradient_of_f(const F &f, const double &x, const double &xc, const std::vector &theta_vals, const std::vector &x_r, const std::vector &x_i, size_t n, - std::ostream* msgs) { + std::ostream *msgs) { double gradient = 0.0; start_nested(); std::vector theta_var(theta_vals.size()); diff --git a/test/unit/math/prim/arr/functor/integrate_1d_test.cpp b/test/unit/math/prim/arr/functor/integrate_1d_test.cpp index b004b0f8388..bd1f0986def 100644 --- a/test/unit/math/prim/arr/functor/integrate_1d_test.cpp +++ b/test/unit/math/prim/arr/functor/integrate_1d_test.cpp @@ -6,7 +6,7 @@ #include #include -std::ostringstream* msgs = nullptr; +std::ostringstream *msgs = nullptr; struct f1 { template diff --git a/test/unit/math/rev/arr/functor/integrate_1d_test.cpp b/test/unit/math/rev/arr/functor/integrate_1d_test.cpp index 694eee5f66a..ed50b98093e 100644 --- a/test/unit/math/rev/arr/functor/integrate_1d_test.cpp +++ b/test/unit/math/rev/arr/functor/integrate_1d_test.cpp @@ -8,7 +8,7 @@ #include #include -std::ostringstream* msgs = nullptr; +std::ostringstream *msgs = nullptr; struct f1 { template