Skip to content

Commit 01f5923

Browse files
authored
Merge pull request #3304 from stan-dev/feature/serializer-stoch-matrices
adds row and column stochastic free functions to serializer
2 parents b0192b9 + 5dea791 commit 01f5923

File tree

2 files changed

+351
-335
lines changed

2 files changed

+351
-335
lines changed

src/stan/io/serializer.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,54 @@ class serializer {
492492
this->write_free_corr_matrix(ret_i);
493493
}
494494
}
495+
496+
/**
497+
* Read a serialized column simplex matrix and unconstrain it
498+
*
499+
* @tparam Mat An Eigen matrix
500+
* @param x A column stochastic eigen matrix
501+
*/
502+
template <typename Mat, require_not_std_vector_t<Mat>* = nullptr>
503+
inline void write_free_stochastic_column(Mat&& x) {
504+
this->write(stan::math::stochastic_column_free(x));
505+
}
506+
507+
/**
508+
* Read serialized column simplex matrices and unconstrain them
509+
*
510+
* @tparam StdVec A standard vector of Eigen matrices
511+
* @param x A vector of column stochastic Eigen matrices
512+
*/
513+
template <typename StdVec, require_std_vector_t<StdVec>* = nullptr>
514+
inline void write_free_stochastic_column(StdVec&& x) {
515+
for (auto&& x_i : x) {
516+
this->write_free_stochastic_column(x_i);
517+
}
518+
}
519+
520+
/**
521+
* Read a serialized row simplex matrix and unconstrain it
522+
*
523+
* @tparam Mat An Eigen matrix
524+
* @param x A row stochastic eigen matrix
525+
*/
526+
template <typename Mat, require_not_std_vector_t<Mat>* = nullptr>
527+
inline void write_free_stochastic_row(Mat&& x) {
528+
this->write(stan::math::stochastic_row_free(x));
529+
}
530+
531+
/**
532+
* Read serialized row simplex matrices and unconstrain them
533+
*
534+
* @tparam StdVec A standard vector of Eigen matrices
535+
* @param x A vector of row stochastic Eigen matrices
536+
*/
537+
template <typename StdVec, require_std_vector_t<StdVec>* = nullptr>
538+
inline void write_free_stochastic_row(StdVec&& x) {
539+
for (auto&& x_i : x) {
540+
this->write_free_stochastic_row(x_i);
541+
}
542+
}
495543
};
496544

497545
} // namespace io

0 commit comments

Comments
 (0)