@@ -583,20 +583,19 @@ class deserializer {
583583
584584 /* *
585585 * Return the next zero sum vector of the specified size (using one fewer
586- * unconstrained scalars), incrementing the specified reference with the
587- * log absolute Jacobian determinant (no adjustment, in this case) .
586+ * unconstrained scalars). This particular transformation is linear, not
587+ * requiring a Jacobian adjustment.
588588 *
589- * <p>See <code>stan::math::sum_to_zero_constrain(Eigen::Matrix,T&)</code>.
589+ * <p>See <code>stan::math::sum_to_zero_constrain(Eigen::Matrix, T&)</code>.
590590 *
591591 * @tparam Ret The type to return.
592592 * @tparam Jacobian Whether to increment the log of the absolute Jacobian
593593 * determinant of the transform.
594594 * @tparam LP Type of log probability.
595- * @tparam Sizes A parameter pack of integral types.
596- * @param lp The reference to the variable holding the log
595+ * @param lp (Unused) The reference to the variable holding the log density.
597596 * @param size Number of cells in zero sum vector to generate.
598597 * @return The next zero sum of the specified size.
599- * @throws std::invalid_argument if number of dimensions (`k`) is zero
598+ * @throws std::invalid_argument if `size` is zero
600599 */
601600 template <typename Ret, bool Jacobian, typename LP,
602601 require_not_std_vector_t <Ret>* = nullptr >
@@ -606,10 +605,37 @@ class deserializer {
606605 this ->read <Ret>(size - 1 ), lp);
607606 }
608607
608+ /* *
609+ * Return the next zero sum matrix of the specified dimensions (requires
610+ * (N - 1) * (M - 1) unconstrained scalars).
611+ * This particular transformation is linear, not requiring a Jacobian
612+ * adjustment.
613+ *
614+ * <p>See <code>stan::math::sum_to_zero_constrain(Eigen::Matrix, T&)</code>.
615+ *
616+ * @tparam Ret The type to return.
617+ * @tparam Jacobian Whether to increment the log of the absolute Jacobian
618+ * determinant of the transform.
619+ * @tparam LP Type of log probability.
620+ * @param lp (Unused) The reference to the variable holding the log density.
621+ * @param N Number of rows in zero sum matrix to generate.
622+ * @param M Number of columns in zero sum matrix to generate.
623+ * @return The next zero sum of the specified size.
624+ * @throws std::invalid_argument either `N` or `M` is zero
625+ */
626+ template <typename Ret, bool Jacobian, typename LP,
627+ require_matrix_t <Ret>* = nullptr >
628+ inline auto read_constrain_sum_to_zero (LP& lp, size_t N, size_t M) {
629+ stan::math::check_positive (" read_sum_to_zero" , " N" , N);
630+ stan::math::check_positive (" read_sum_to_zero" , " M" , M);
631+ return stan::math::sum_to_zero_constrain<Jacobian>(
632+ this ->read <conditional_var_val_t <Ret, matrix_t >>(N - 1 , M - 1 ), lp);
633+ }
634+
609635 /* *
610636 * Return the next zero sum vector of the specified size (using one fewer
611- * unconstrained scalars), incrementing the specified reference with the
612- * log absolute Jacobian determinant (no adjustment, in this case) .
637+ * unconstrained scalars). This particular transformation is linear, not
638+ * requiring a Jacobian adjustment.
613639 *
614640 * <p>See <code>stan::math::sum_to_zero_constrain(Eigen::Matrix,T&)</code>.
615641 *
@@ -1219,18 +1245,32 @@ class deserializer {
12191245 }
12201246
12211247 /* *
1222- * Read a serialized sum_to_zero vector and unconstrain it
1248+ * Read a serialized sum_to_zero vector and unconstrain it.
12231249 *
12241250 * @tparam Ret Type of output
1225- * @return Unconstrained vector
1251+ * @param size Vector size
1252+ * @return Unconstrained vector of length (size - 1)
12261253 */
12271254 template <typename Ret, require_not_std_vector_t <Ret>* = nullptr >
12281255 inline auto read_free_sum_to_zero (size_t size) {
12291256 return stan::math::sum_to_zero_free (this ->read <Ret>(size));
12301257 }
12311258
12321259 /* *
1233- * Read serialized zero-sum vectors and unconstrain them
1260+ * Read a serialized sum_to_zero matrix and unconstrain it.
1261+ *
1262+ * @tparam Ret Type of output
1263+ * @param N Rows of matrix
1264+ * @param M Cols of matrix
1265+ * @return Unconstrained matrix of size (N-1) x (M-1)
1266+ */
1267+ template <typename Ret, require_matrix_t <Ret>* = nullptr >
1268+ inline auto read_free_sum_to_zero (size_t N, size_t M) {
1269+ return stan::math::sum_to_zero_free (this ->read <Ret>(N, M));
1270+ }
1271+
1272+ /* *
1273+ * Read serialized zero-sum vectors and unconstrain them.
12341274 *
12351275 * @tparam Ret Type of output
12361276 * @tparam Sizes Types of dimensions of output
0 commit comments