Skip to content

Commit ce63b87

Browse files
authored
Merge pull request #3077 from stan-dev/fix/3075-hcubature-bad-moves
Remove problematic calls to std::move in hcubature
2 parents d99f263 + 9575d1a commit ce63b87

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

stan/math/prim/functor/hcubature.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ inline auto hcubature(const F& integrand, const ParsTuple& pars, const int dim,
479479
std::tie(result_2, err_2, kdivide_2) = internal::integrate_GenzMalik(
480480
integrand, genz_malik, dim, box.a_, mb, pars);
481481
}
482-
box_t box1(std::move(ma), std::move(box.b_), result_1, kdivide_1);
483-
box_t box2(std::move(box.a_), std::move(mb), result_2, kdivide_2);
482+
box_t box1(std::move(ma), box.b_, result_1, kdivide_1);
483+
box_t box2(box.a_, std::move(mb), result_2, kdivide_2);
484484
result += result_1 + result_2 - box.I_;
485485
err += err_1 + err_2 - err_vec[err_idx];
486486
ms[err_idx].I_ = 0;

test/unit/math/prim/functor/hcubature_test.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stan/math/prim/functor.hpp>
22
#include <stan/math/prim/fun.hpp>
3+
#include <stan/math/prim/prob/wiener_full_lpdf.hpp>
34

45
#include <gtest/gtest.h>
56
#include <vector>
@@ -163,3 +164,22 @@ TEST(StanMath_hcubature_prim, test1) {
163164
std::make_tuple((1 + sqrt(10.0)) / 9.0), dim, a_4, b_4,
164165
20000, 0.0, reqRelError_3, 0.999998);
165166
}
167+
168+
TEST(StanMath_hcubature_prim, test_issue_3075) {
169+
// test for regressions against issue
170+
// https://github.com/stan-dev/math/issues/3075
171+
using stan::math::internal::GradientCalc;
172+
using stan::math::internal::wiener5_density;
173+
using stan::math::internal::wiener7_integrate;
174+
175+
auto params_st = std::make_tuple(0.553273, 1, -3.5, 0.55, 0.553161, 1.06423,
176+
0.0941929, 0.0, -28.3242);
177+
Eigen::VectorXd xmin = Eigen::VectorXd::Zero(2);
178+
Eigen::VectorXd xmax = Eigen::VectorXd::Ones(2);
179+
180+
auto f = wiener7_integrate<GradientCalc::OFF, GradientCalc::OFF>(
181+
[](auto&&... args) { return wiener5_density<GradientCalc::ON>(args...); },
182+
-18.3029, params_st, 1, xmin, xmax, 6000, 0, 4.5e-05);
183+
184+
ASSERT_FLOAT_EQ(f, 4.97571e-312);
185+
}

0 commit comments

Comments
 (0)