1#ifndef STAN_MATH_PRIM_FUN_SERIALIZER_HPP
2#define STAN_MATH_PRIM_FUN_SERIALIZER_HPP
64 template <
typename U, require_stan_scalar_t<U>* =
nullptr,
65 require_not_complex_t<U>* =
nullptr>
81 std::complex<T>
read(
const std::complex<U>& x) {
82 T re =
read(x.real());
83 T im =
read(x.imag());
97 template <
typename U, require_std_vector_t<U>* =
nullptr,
98 require_not_st_complex<U>* =
nullptr>
102 for (
size_t i = 0; i < x.size(); ++i)
103 y.push_back(
read(x[i]));
117 template <
typename U, require_std_vector_st<is_complex, U>* =
nullptr>
121 for (
size_t i = 0; i < x.size(); ++i)
122 y.push_back(
read(x[i]));
138 template <
typename U,
int R,
int C>
139 Eigen::Matrix<T, R, C>
read(
const Eigen::Matrix<U, R, C>& x) {
140 Eigen::Matrix<T, R, C> y(x.rows(), x.cols());
141 for (
int j = 0; j < x.cols(); ++j) {
142 for (
int i = 0; i < x.rows(); ++i) {
143 y(i + j * x.rows()) =
read(x(i, j));
161 template <
typename U,
int R,
int C>
162 Eigen::Matrix<std::complex<T>, R, C>
read(
163 const Eigen::Matrix<std::complex<U>, R, C>& x) {
164 Eigen::Matrix<std::complex<T>, R, C> y(x.rows(), x.cols());
165 for (
int j = 0; j < x.cols(); ++j) {
166 for (
int i = 0; i < x.rows(); ++i) {
167 y(i + j * x.rows()) =
read(x(i, j));
203 template <
typename U, require_stan_scalar_t<U>* =
nullptr>
214 template <
typename U>
215 void write(
const std::complex<U>& x) {
226 template <
typename U>
227 void write(
const std::vector<U>& x) {
228 for (
size_t i = 0; i < x.size(); ++i)
240 template <
typename U, require_eigen_t<U>* =
nullptr>
242 for (
int j = 0; j < x.cols(); ++j) {
243 for (
int i = 0; i < x.rows(); ++i) {
244 write(x.coeff(i, j));
283template <
typename T, require_eigen_vector_t<T>* =
nullptr>
296template <
typename U,
typename T,
typename... Ts>
311template <
typename U,
typename... Ts>
327 return serialize<real_return_t<T>>(x);
338template <
typename... Ts>
340 return to_vector(serialize<double>(xs...));
auto to_vector(T_x &&x)
Returns input matrix reshaped into a vector.
auto to_array_1d(T_x &&x)
Returns input matrix reshaped into a vector.
typename promote_scalar_type< std::decay_t< T >, std::decay_t< S > >::type promote_scalar_t
deserializer< T > to_deserializer(const std::vector< T > &vals)
Return a deserializer based on the specified values.
Eigen::VectorXd serialize_args(const Ts... xs)
Serialize the specified sequence of structured objects with double-based scalars into an Eigen vector...
std::vector< U > serialize(const Ts... xs)
Serialize the specified sequence of objects, which all must have scalar types assignable to the resul...
std::vector< real_return_t< T > > serialize_return(const T &x)
Serialized the specified single argument.
void serialize_helper(serializer< U > &s)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
deserializer(const std::vector< T > &vals)
Construct a deserializer from the specified sequence of values.
std::complex< T > read(const std::complex< U > &x)
Read a complex number conforming to the shape of the specified argument.
T scalar_t
Type of scalars in all objects.
Eigen::Matrix< std::complex< T >, R, C > read(const Eigen::Matrix< std::complex< U >, R, C > &x)
Read a standard vector of std::complex variables conforming to the shape of the specified argument,...
Eigen::Matrix< T, R, C > read(const Eigen::Matrix< U, R, C > &x)
Read a standard vector conforming to the shape of the specified argument, here an Eigen matrix,...
T read(const U &x)
Read a scalar conforming to the shape of the specified argument, here a scalar.
size_t position_
Current read position.
promote_scalar_t< std::complex< T >, U > read(const U &x)
Read a standard vector of std::complex variables conforming to the shape of the specified argument,...
deserializer(const Eigen::Matrix< T, -1, 1 > &v_vals)
Construct a deserializer from the specified sequence of values.
const std::vector< T > vals_
The sequence of values to deserialize.
promote_scalar_t< T, U > read(const U &x)
Read a standard vector conforming to the shape of the specified argument, here a standard vector.
A class to store a sequence of values which can be deserialized back into structured objects such as ...
const Eigen::Matrix< T, -1, 1 > & vector_vals()
Return the serialized values as an Eigen vector.
void write(const U &x)
Serialize the specified scalar.
void write(const std::vector< U > &x)
Serialize the specified standard vector.
std::vector< T > vals_
Container for serialized values.
void write(const std::complex< U > &x)
Serialize the specified complex number.
serializer()
Construct a serializer.
const std::vector< T > & array_vals()
Return the serialized values as a standard vector.
T scalar_t
Scalar type of serializer.
A structure to serialize structures to an internal stored sequence of scalars.