Skip to content

Commit

Permalink
Merge pull request #3077 from stan-dev/fix/3075-hcubature-bad-moves
Browse files Browse the repository at this point in the history
Remove problematic calls to std::move in hcubature
  • Loading branch information
WardBrian authored May 22, 2024
2 parents d99f263 + 9575d1a commit ce63b87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stan/math/prim/functor/hcubature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ inline auto hcubature(const F& integrand, const ParsTuple& pars, const int dim,
std::tie(result_2, err_2, kdivide_2) = internal::integrate_GenzMalik(
integrand, genz_malik, dim, box.a_, mb, pars);
}
box_t box1(std::move(ma), std::move(box.b_), result_1, kdivide_1);
box_t box2(std::move(box.a_), std::move(mb), result_2, kdivide_2);
box_t box1(std::move(ma), box.b_, result_1, kdivide_1);
box_t box2(box.a_, std::move(mb), result_2, kdivide_2);
result += result_1 + result_2 - box.I_;
err += err_1 + err_2 - err_vec[err_idx];
ms[err_idx].I_ = 0;
Expand Down
20 changes: 20 additions & 0 deletions test/unit/math/prim/functor/hcubature_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stan/math/prim/functor.hpp>
#include <stan/math/prim/fun.hpp>
#include <stan/math/prim/prob/wiener_full_lpdf.hpp>

#include <gtest/gtest.h>
#include <vector>
Expand Down Expand Up @@ -163,3 +164,22 @@ TEST(StanMath_hcubature_prim, test1) {
std::make_tuple((1 + sqrt(10.0)) / 9.0), dim, a_4, b_4,
20000, 0.0, reqRelError_3, 0.999998);
}

TEST(StanMath_hcubature_prim, test_issue_3075) {
// test for regressions against issue
// https://github.com/stan-dev/math/issues/3075
using stan::math::internal::GradientCalc;
using stan::math::internal::wiener5_density;
using stan::math::internal::wiener7_integrate;

auto params_st = std::make_tuple(0.553273, 1, -3.5, 0.55, 0.553161, 1.06423,
0.0941929, 0.0, -28.3242);
Eigen::VectorXd xmin = Eigen::VectorXd::Zero(2);
Eigen::VectorXd xmax = Eigen::VectorXd::Ones(2);

auto f = wiener7_integrate<GradientCalc::OFF, GradientCalc::OFF>(
[](auto&&... args) { return wiener5_density<GradientCalc::ON>(args...); },
-18.3029, params_st, 1, xmin, xmax, 6000, 0, 4.5e-05);

ASSERT_FLOAT_EQ(f, 4.97571e-312);
}

0 comments on commit ce63b87

Please sign in to comment.