@@ -95,21 +95,39 @@ cholesky_factor_constrain(const T& x, int M, int N, Lp& lp) {
9595 * @tparam T A standard vector with inner type inheriting from
9696 * `Eigen::DenseBase` or a `var_value` with inner type inheriting from
9797 * `Eigen::DenseBase` with compile time dynamic rows and 1 column
98- * @tparam Lp A pack that is either empty, or exactly one scalar type for the lp
99- * argument. The scalar type of T should be convertable to this.
10098 * @param x Vector of unconstrained values
10199 * @param M number of rows
102100 * @param N number of columns
103- * @param[in,out] lp log density accumulator or empty
104101 * @return Cholesky factor
105102 */
106- template <typename T, typename ... Lp, require_std_vector_t <T>* = nullptr >
107- inline auto cholesky_factor_constrain (const T& x, int M, int N, Lp&... lp) {
108- static_assert (sizeof ...(lp) == 0 || sizeof ...(lp) == 1 ,
109- " cholesky_factor_constrain should be called with either "
110- " three or four arguments" );
111- return apply_vector_unary<T>::apply (x, [&lp..., M, N](auto && v) {
112- return cholesky_factor_constrain (v, M, N, lp...);
103+ template <typename T, , require_std_vector_t <T>* = nullptr >
104+ inline auto cholesky_factor_constrain (const T& x, int M, int N) {
105+ return apply_vector_unary<T>::apply (
106+ x, [M, N](auto && v) { return cholesky_factor_constrain (v, M, N); });
107+ }
108+
109+ /* *
110+ * Return the Cholesky factor of the specified size read from the specified
111+ * vector. A total of (N choose 2) + N + N * (M - N) free parameters are
112+ * required to read an M by N Cholesky factor.
113+ * This overload handles looping over the elements of a standard vector.
114+ *
115+ * @tparam T A standard vector with inner type inheriting from
116+ * `Eigen::DenseBase` or a `var_value` with inner type inheriting from
117+ * `Eigen::DenseBase` with compile time dynamic rows and 1 column
118+ * @tparam Lp Scalar type for the lp argument. The scalar type of T should be
119+ * convertable to this.
120+ * @param x Vector of unconstrained values
121+ * @param M number of rows
122+ * @param N number of columns
123+ * @param[in,out] lp log density accumulator
124+ * @return Cholesky factor
125+ */
126+ template <typename T, typename Lp, require_std_vector_t <T>* = nullptr ,
127+ require_convertible_t <return_type_t <T>, Lp>* = nullptr >
128+ inline auto cholesky_factor_constrain (const T& x, int M, int N, Lp& lp) {
129+ return apply_vector_unary<T>::apply (x, [&lp, M, N](auto && v) {
130+ return cholesky_factor_constrain (v, M, N, lp);
113131 });
114132}
115133
0 commit comments