Skip to content

Commit 5ae902d

Browse files
committed
Changes per @SteveBronder
1 parent 51ac4c6 commit 5ae902d

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

stan/math/prim/constraint/sum_to_zero_constrain.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y) {
4747

4848
auto&& y_ref = to_ref(y);
4949

50-
typename plain_type_t<Vec>::Scalar sum_w(0);
50+
value_type_t<Vec> sum_w(0);
5151
for (int i = N; i > 0; --i) {
52-
double n = i;
52+
double n = static_cast<double>(i);
5353
auto w = y_ref(i - 1) * inv_sqrt(n * (n + 1));
5454
sum_w += w;
5555

stan/math/prim/constraint/sum_to_zero_free.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ inline plain_type_t<Vec> sum_to_zero_free(const Vec& z) {
4949

5050
y.coeffRef(N - 1) = -z_ref(N) * sqrt(N * (N + 1)) / N;
5151

52-
typename plain_type_t<Vec>::Scalar sum_w(0);
52+
value_type_t<Vec> sum_w(0);
5353

5454
for (int i = N - 2; i >= 0; --i) {
55-
double n = i + 1;
55+
double n = static_cast<double>(i + 1);
5656
auto w = y(i + 1) / sqrt((n + 1) * (n + 2));
5757
sum_w += w;
5858
y.coeffRef(i) = (sum_w - z_ref(i + 1)) * sqrt(n * (n + 1)) / n;

stan/math/rev/constraint/sum_to_zero_constrain.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ namespace math {
3939
* @return Zero-sum vector of dimensionality K.
4040
*/
4141
template <typename T, require_rev_col_vector_t<T>* = nullptr>
42-
inline auto sum_to_zero_constrain(const T& y) {
42+
inline auto sum_to_zero_constrain(T&& y) {
4343
using ret_type = plain_type_t<T>;
4444
if (unlikely(y.size() == 0)) {
4545
return arena_t<ret_type>(Eigen::VectorXd{{0}});
4646
}
47-
auto arena_y = to_arena(y);
47+
auto arena_y = to_arena(std::forward<T>(y));
4848
arena_t<ret_type> arena_z = sum_to_zero_constrain(arena_y.val());
4949

5050
reverse_pass_callback([arena_y, arena_z]() mutable {
5151
const auto N = arena_y.size();
5252

5353
double sum_u_adj = 0;
5454
for (int i = 0; i < N; ++i) {
55-
double n = i + 1;
55+
double n = static_cast<double>(i + 1);
5656

5757
// adjoint of the reverse cumulative sum computed in the forward mode
5858
sum_u_adj += arena_z.adj()(i);
@@ -95,8 +95,8 @@ inline auto sum_to_zero_constrain(const T& y) {
9595
* @return Zero-sum vector of dimensionality K.
9696
*/
9797
template <typename T, require_rev_col_vector_t<T>* = nullptr>
98-
inline auto sum_to_zero_constrain(const T& y, scalar_type_t<T>& lp) {
99-
return sum_to_zero_constrain(y);
98+
inline auto sum_to_zero_constrain(T&& y, scalar_type_t<T>& lp) {
99+
return sum_to_zero_constrain(std::forward<T>(y));
100100
}
101101

102102
} // namespace math

0 commit comments

Comments
 (0)