Skip to content

Commit e76cca4

Browse files
committed
Missed one Lp...
1 parent bf77776 commit e76cca4

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

stan/math/prim/constraint/sum_to_zero_constrain.hpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y, Lp& lp) {
9292
return sum_to_zero_constrain(y);
9393
}
9494

95+
/**
96+
* Return a vector with sum zero corresponding to the specified
97+
* free vector.
98+
* This overload handles looping over the elements of a standard vector.
99+
*
100+
* @tparam Vec A standard vector with inner type inheriting from
101+
* `Eigen::DenseBase` or a `var_value` with inner type inheriting from
102+
* `Eigen::DenseBase` with compile time dynamic rows and 1 column
103+
* @param[in] y free vector
104+
* @return Zero-sum vectors of dimensionality one greater than `y`
105+
*/
106+
template <typename T, require_std_vector_t<T>* = nullptr>
107+
inline auto sum_to_zero_constrain(const T& y) {
108+
return apply_vector_unary<T>::apply(
109+
y, [](auto&& v) { return sum_to_zero_constrain(v); });
110+
}
111+
95112
/**
96113
* Return a vector with sum zero corresponding to the specified
97114
* free vector.
@@ -105,11 +122,9 @@ inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y, Lp& lp) {
105122
* @param[in, out] lp unused
106123
* @return Zero-sum vectors of dimensionality one greater than `y`
107124
*/
108-
template <typename T, typename... Lp, require_std_vector_t<T>* = nullptr>
109-
inline auto sum_to_zero_constrain(const T& y, Lp&... lp) {
110-
static_assert(sizeof...(lp) == 0 || sizeof...(lp) == 1,
111-
"sum_to_zero_constrain should be called with either "
112-
"one or two arguments");
125+
template <typename T, typename Lp, require_std_vector_t<T>* = nullptr,
126+
require_convertible_t<return_type_t<T>, Lp>* = nullptr>
127+
inline auto sum_to_zero_constrain(const T& y, Lp& lp) {
113128
return apply_vector_unary<T>::apply(
114129
y, [](auto&& v) { return sum_to_zero_constrain(v); });
115130
}

0 commit comments

Comments
 (0)