Skip to content

Commit

Permalink
Merge pull request #3304 from stan-dev/feature/serializer-stoch-matrices
Browse files Browse the repository at this point in the history
adds row and column stochastic free functions to serializer
  • Loading branch information
SteveBronder authored Jul 29, 2024
2 parents b0192b9 + 5dea791 commit 01f5923
Show file tree
Hide file tree
Showing 2 changed files with 351 additions and 335 deletions.
48 changes: 48 additions & 0 deletions src/stan/io/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,54 @@ class serializer {
this->write_free_corr_matrix(ret_i);
}
}

/**
* Read a serialized column simplex matrix and unconstrain it
*
* @tparam Mat An Eigen matrix
* @param x A column stochastic eigen matrix
*/
template <typename Mat, require_not_std_vector_t<Mat>* = nullptr>
inline void write_free_stochastic_column(Mat&& x) {
this->write(stan::math::stochastic_column_free(x));
}

/**
* Read serialized column simplex matrices and unconstrain them
*
* @tparam StdVec A standard vector of Eigen matrices
* @param x A vector of column stochastic Eigen matrices
*/
template <typename StdVec, require_std_vector_t<StdVec>* = nullptr>
inline void write_free_stochastic_column(StdVec&& x) {
for (auto&& x_i : x) {
this->write_free_stochastic_column(x_i);
}
}

/**
* Read a serialized row simplex matrix and unconstrain it
*
* @tparam Mat An Eigen matrix
* @param x A row stochastic eigen matrix
*/
template <typename Mat, require_not_std_vector_t<Mat>* = nullptr>
inline void write_free_stochastic_row(Mat&& x) {
this->write(stan::math::stochastic_row_free(x));
}

/**
* Read serialized row simplex matrices and unconstrain them
*
* @tparam StdVec A standard vector of Eigen matrices
* @param x A vector of row stochastic Eigen matrices
*/
template <typename StdVec, require_std_vector_t<StdVec>* = nullptr>
inline void write_free_stochastic_row(StdVec&& x) {
for (auto&& x_i : x) {
this->write_free_stochastic_row(x_i);
}
}
};

} // namespace io
Expand Down
Loading

0 comments on commit 01f5923

Please sign in to comment.