Skip to content

Commit 243d90c

Browse files
committed
Merge remote-tracking branch 'origin' into 5.0-breaking-changes
2 parents 429dbc8 + 87bb8a7 commit 243d90c

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

stan/math/prim/constraint/lub_constrain.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,33 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub,
401401
}
402402
}
403403

404+
/**
405+
* Wrapper for tuple of bounds, simply delegates to the appropriate overload
406+
*/
407+
template <typename T, typename L, typename U>
408+
inline auto lub_constrain(const T& x, const std::tuple<L, U>& bounds) {
409+
return lub_constrain(x, std::get<0>(bounds), std::get<1>(bounds));
410+
}
411+
412+
/**
413+
* Wrapper for tuple of bounds, simply delegates to the appropriate overload
414+
*/
415+
template <typename T, typename L, typename U>
416+
inline auto lub_constrain(const T& x, const std::tuple<L, U>& bounds,
417+
return_type_t<T, L, U>& lp) {
418+
return lub_constrain(x, std::get<0>(bounds), std::get<1>(bounds), lp);
419+
}
420+
421+
/**
422+
* Wrapper for tuple of bounds, simply delegates to the appropriate overload
423+
*/
424+
template <bool Jacobian, typename T, typename L, typename U>
425+
inline auto lub_constrain(const T& x, const std::tuple<L, U>& bounds,
426+
return_type_t<T, L, U>& lp) {
427+
return lub_constrain<Jacobian>(x, std::get<0>(bounds), std::get<1>(bounds),
428+
lp);
429+
}
430+
404431
} // namespace math
405432
} // namespace stan
406433

stan/math/prim/constraint/lub_free.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ inline auto lub_free(const std::vector<T> y, const std::vector<L>& lb,
180180
}
181181
return ret;
182182
}
183+
184+
/**
185+
* Wrapper for tuple of bounds, simply delegates to the appropriate overload
186+
*/
187+
template <typename T, typename L, typename U>
188+
inline auto lub_free(T&& y, const std::tuple<L, U>& bounds) {
189+
return lub_free(std::forward<T>(y), std::get<0>(bounds), std::get<1>(bounds));
190+
}
183191
///@}
184192

185193
} // namespace math

test/unit/math/mix/constraint/lub_constrain_helpers.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ void expect(const T1& x, const T2& lb, const T3& ub) {
2222
auto xx = stan::math::lub_constrain<true>(x, lb, ub, lp);
2323
return stan::math::add(lp, stan::math::sum(xx));
2424
};
25+
auto f5 = [](const auto& x, const auto& lb, const auto& ub) {
26+
stan::return_type_t<decltype(x), decltype(lb), decltype(ub)> lp = 0;
27+
return stan::math::lub_constrain<false>(x, std::make_tuple(lb, ub), lp);
28+
};
29+
auto f6 = [](const auto& x, const auto& lb, const auto& ub) {
30+
stan::return_type_t<decltype(x), decltype(lb), decltype(ub)> lp = 0;
31+
return stan::math::lub_constrain<true>(x, std::make_tuple(lb, ub), lp);
32+
};
2533

2634
stan::test::expect_ad(f1, x, lb, ub);
2735
stan::test::expect_ad(f2, x, lb, ub);
2836
stan::test::expect_ad(f3, x, lb, ub);
2937
stan::test::expect_ad(f4, x, lb, ub);
38+
stan::test::expect_ad(f5, x, lb, ub);
39+
stan::test::expect_ad(f6, x, lb, ub);
3040
}
3141
template <typename T1, typename T2, typename T3>
3242
void expect_vec(const T1& x, const T2& lb, const T3& ub) {
@@ -52,11 +62,21 @@ void expect_vec(const T1& x, const T2& lb, const T3& ub) {
5262
}
5363
return stan::math::add(lp, xx_acc);
5464
};
65+
auto f5 = [](const auto& x, const auto& lb, const auto& ub) {
66+
stan::return_type_t<decltype(x), decltype(lb), decltype(ub)> lp = 0;
67+
return stan::math::lub_constrain<false>(x, std::make_tuple(lb, ub), lp);
68+
};
69+
auto f6 = [](const auto& x, const auto& lb, const auto& ub) {
70+
stan::return_type_t<decltype(x), decltype(lb), decltype(ub)> lp = 0;
71+
return stan::math::lub_constrain<true>(x, std::make_tuple(lb, ub), lp);
72+
};
5573

5674
stan::test::expect_ad(f1, x, lb, ub);
5775
stan::test::expect_ad(f2, x, lb, ub);
5876
stan::test::expect_ad(f3, x, lb, ub);
5977
stan::test::expect_ad(f4, x, lb, ub);
78+
stan::test::expect_ad(f5, x, lb, ub);
79+
stan::test::expect_ad(f6, x, lb, ub);
6080
}
6181
} // namespace lub_constrain_tests
6282

0 commit comments

Comments
 (0)