Skip to content

Commit 051ec0b

Browse files
committed
Merge branch 'develop' of github.com:stan-dev/math into develop
2 parents 0a85ce9 + ecfe6cb commit 051ec0b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

stan/math/prim/fun/promote_scalar.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace math {
2020
*/
2121
template <typename PromotionScalar, typename UnPromotedType,
2222
require_constructible_t<PromotionScalar, UnPromotedType>* = nullptr,
23-
require_not_same_t<PromotionScalar, UnPromotedType>* = nullptr>
23+
require_not_same_t<PromotionScalar, UnPromotedType>* = nullptr,
24+
require_all_not_tuple_t<PromotionScalar, UnPromotedType>* = nullptr>
2425
inline constexpr auto promote_scalar(UnPromotedType&& x) {
2526
return PromotionScalar(std::forward<UnPromotedType>(x));
2627
}

test/unit/math/mix/fun/promote_scalar_test.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void test_promote_scalar() {
6565
inner_promo_type>>(tester);
6666
stan::math::test::expect_same_value_of_rec(tester, result);
6767
}
68+
6869
TEST(mixFun, promote_scalar_tuple) {
6970
using stan::math::fvar;
7071
using stan::math::var;
@@ -83,3 +84,22 @@ TEST(mixFun, promote_scalar_tuple) {
8384
test_promote_scalar<std::complex<var>, double>();
8485
test_promote_scalar<std::complex<fvar<var>>, double>();
8586
}
87+
88+
template <typename UnPromotedType>
89+
void test_promote_scalar_basic() {
90+
std::tuple<UnPromotedType, UnPromotedType> x{UnPromotedType(3.5),
91+
UnPromotedType(4.5)};
92+
std::tuple<std::complex<UnPromotedType>, UnPromotedType> z
93+
= stan::math::promote_scalar<
94+
std::tuple<std::complex<UnPromotedType>, UnPromotedType>>(x);
95+
stan::math::test::expect_same_value_of_rec(x, z);
96+
}
97+
98+
TEST(mixFun, promote_scalar_tuple_basic) {
99+
using stan::math::fvar;
100+
using stan::math::var;
101+
test_promote_scalar_basic<double>();
102+
test_promote_scalar_basic<var>();
103+
test_promote_scalar_basic<fvar<double>>();
104+
test_promote_scalar_basic<fvar<var>>();
105+
}

0 commit comments

Comments
 (0)