1 #ifndef __STAN__IO__READER_HPP__
2 #define __STAN__IO__READER_HPP__
4 #include <boost/throw_exception.hpp>
38 std::vector<T>& data_r_;
39 std::vector<int>& data_i_;
43 inline T& scalar_ptr() {
44 return data_r_.at(pos_);
47 inline T& scalar_ptr_increment(
size_t m) {
49 return data_r_.at(pos_ - m);
52 inline int& int_ptr() {
53 return data_i_.at(int_pos_);
56 inline int& int_ptr_increment(
size_t m) {
58 return data_i_.at(int_pos_ - m);
63 typedef Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>
matrix_t;
64 typedef Eigen::Matrix<T,Eigen::Dynamic,1>
vector_t;
84 std::vector<int>& data_i)
102 return data_r_.size() - pos_;
111 return data_i_.size() - int_pos_;
120 if (int_pos_ >= data_i_.size())
121 BOOST_THROW_EXCEPTION(
122 std::runtime_error(
"no more integers to read."));
123 return data_i_[int_pos_++];
156 if (pos_ >= data_r_.size())
157 BOOST_THROW_EXCEPTION(std::runtime_error(
"no more scalars to read"));
158 return data_r_[pos_++];
196 T& start = scalar_ptr_increment(m);
197 vec.insert(vec.begin(), &start, &scalar_ptr());
334 BOOST_THROW_EXCEPTION(
335 std::runtime_error(
"required value greater than or equal to lb"));
377 BOOST_THROW_EXCEPTION(
378 std::runtime_error(
"required value less than or equal to ub"));
423 BOOST_THROW_EXCEPTION(
424 std::runtime_error(
"lower bound must be less than or equal to ub"));
426 BOOST_THROW_EXCEPTION(
427 std::runtime_error(
"required value greater than or equal to lb"));
429 BOOST_THROW_EXCEPTION(
430 std::runtime_error(
"required value less than or equal to ub"));
475 "Constrained scalar");
516 template <
typename TL>
520 x, lb,
"Constrained scalar");
535 template <
typename TL>
551 template <
typename TL>
570 template <
typename TU>
588 template <
typename TU>
604 template <
typename TU>
623 template <
typename TL,
typename TU>
643 template <
typename TL,
typename TU>
661 template <
typename TL,
typename TU>
979 template <
typename TL>
982 for (
size_t i = 0; i < m; ++i)
986 template <
typename TL>
989 for (
size_t i = 0; i < m; ++i)
993 template <
typename TL>
996 for (
size_t i = 0; i < m; ++i)
1001 template <
typename TL>
1004 for (
size_t i = 0; i < m; ++i)
1008 template <
typename TL>
1011 for (
size_t i = 0; i < m; ++i)
1015 template <
typename TL>
1018 for (
size_t i = 0; i < m; ++i)
1023 template <
typename TL>
1026 for (
size_t i = 0; i < m; ++i)
1027 for (
size_t j = 0; j < n; ++j)
1031 template <
typename TL>
1034 for (
size_t i = 0; i < m; ++i)
1035 for (
size_t j = 0; j < n; ++j)
1039 template <
typename TL>
1042 for (
size_t i = 0; i < m; ++i)
1043 for (
size_t j = 0; j < n; ++j)
1050 template <
typename TU>
1053 for (
size_t i = 0; i < m; ++i)
1057 template <
typename TU>
1060 for (
size_t i = 0; i < m; ++i)
1064 template <
typename TU>
1067 for (
size_t i = 0; i < m; ++i)
1072 template <
typename TU>
1075 for (
size_t i = 0; i < m; ++i)
1079 template <
typename TU>
1082 for (
size_t i = 0; i < m; ++i)
1086 template <
typename TU>
1089 for (
size_t i = 0; i < m; ++i)
1094 template <
typename TU>
1097 for (
size_t i = 0; i < m; ++i)
1098 for (
size_t j = 0; j < n; ++j)
1102 template <
typename TU>
1105 for (
size_t i = 0; i < m; ++i)
1106 for (
size_t j = 0; j < n; ++j)
1110 template <
typename TU>
1113 for (
size_t i = 0; i < m; ++i)
1114 for (
size_t j = 0; j < n; ++j)
1120 template <
typename TL,
typename TU>
1123 for (
size_t i = 0; i < m; ++i)
1127 template <
typename TL,
typename TU>
1130 for (
size_t i = 0; i < m; ++i)
1134 template <
typename TL,
typename TU>
1137 for (
size_t i = 0; i < m; ++i)
1142 template <
typename TL,
typename TU>
1145 for (
size_t i = 0; i < m; ++i)
1149 template <
typename TL,
typename TU>
1152 for (
size_t i = 0; i < m; ++i)
1156 template <
typename TL,
typename TU>
1159 for (
size_t i = 0; i < m; ++i)
1164 template <
typename TL,
typename TU>
1167 for (
size_t i = 0; i < m; ++i)
1168 for (
size_t j = 0; j < n; ++j)
1172 template <
typename TL,
typename TU>
1175 for (
size_t i = 0; i < m; ++i)
1176 for (
size_t j = 0; j < n; ++j)
1180 template <
typename TL,
typename TU>
1183 for (
size_t i = 0; i < m; ++i)
1184 for (
size_t j = 0; j < n; ++j)
A stream-based reader for integer, scalar, vector, matrix and array data types, with Jacobian calcula...
row_vector_t row_vector_lb_constrain(const TL lb, size_t m, T &lp)
Eigen::Map< matrix_t > map_matrix_t
T prob_constrain(T &lp)
Return the next scalar transformed to be a probability between 0 and 1, incrementing the specified re...
T scalar_lub_constrain(const TL lb, const TU ub)
Return the next scalar transformed to be between the specified lower and upper bounds.
Eigen::Map< vector_t > map_vector_t
matrix_t matrix_lub(const TL lb, const TU ub, size_t m, size_t n)
T scalar_lub(const TL lb, const TU ub)
Return the next scalar, checking that it is between the specified lower and upper bound.
T scalar_constrain()
Return the next scalar.
int integer_lb(int lb)
Return the next integer, checking that it is greater than or equal to the specified lower bound.
int integer_ub_constrain(int ub, T &lp)
Return the next integer, checking that it is less than or equal to the specified upper bound.
matrix_t cov_matrix_constrain(size_t k, T &lp)
Return the next covariance matrix of the specified dimensionality, incrementing the specified referen...
Eigen::Matrix< T, Eigen::Dynamic, 1 > simplex_constrain(size_t k)
Return the next simplex transformed vector of the specified length.
matrix_t matrix_constrain(size_t m, size_t n, T &lp)
Return a matrix of the specified dimensionality made up of the next scalars arranged in column-major ...
T scalar_ub_constrain(const TU ub)
Return the next scalar transformed to have the specified upper bound.
matrix_t matrix_ub(const TU ub, size_t m, size_t n)
T prob_constrain()
Return the next scalar transformed to be a probability between 0 and 1.
int integer_lub_constrain(int lb, int ub, T &lp)
Return the next integer, checking that it is less than or equal to the specified upper bound.
vector_t vector_ub(const TU ub, size_t m)
vector_t vector_lb_constrain(const TL lb, size_t m, T &lp)
vector_t vector_constrain(size_t m)
Return a column vector of specified dimensionality made up of the next scalars.
T scalar_pos_constrain(T &lp)
Return the next scalar transformed to be positive, incrementing the specified reference with the log ...
T scalar_pos_constrain()
Return the next scalar, transformed to be positive.
T scalar_ub_constrain(const TU ub, T &lp)
Return the next scalar transformed to have the specified upper bound, incrementing the specified refe...
row_vector_t row_vector_lub(const TL lb, const TU ub, size_t m)
vector_t vector_constrain(size_t m, T &lp)
Return a column vector of specified dimensionality made up of the next scalars.
size_t available()
Return the number of scalars remaining to be read.
int integer_ub(int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound.
vector_t vector_ub_constrain(const TU ub, size_t m)
T scalar_lb(const TL lb)
Return the next scalar, checking that it is greater than or equal to the specified lower bound.
row_vector_t row_vector_ub_constrain(const TU ub, size_t m, T &lp)
~reader()
Destroy this variable reader.
int integer_lb_constrain(int lb, T &lp)
Return the next integer, checking that it is greater than or equal to the specified lower bound.
size_t available_i()
Return the number of integers remaining to be read.
matrix_t cov_matrix(size_t k)
Return the next covariance matrix with the specified dimensionality.
vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m, T &lp)
Eigen::Map< row_vector_t > map_row_vector_t
matrix_t matrix_constrain(size_t m, size_t n)
Return a matrix of the specified dimensionality made up of the next scalars arranged in column-major ...
std::vector< T > std_vector(size_t m)
Return a standard library vector of the specified dimensionality made up of the next scalars.
matrix_t corr_matrix_constrain(size_t k)
Return the next correlation matrix of the specified dimensionality.
matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n)
matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n, T &lp)
vector_t vector_ub_constrain(const TU ub, size_t m, T &lp)
row_vector_t row_vector_ub(const TU ub, size_t m)
T scalar()
Return the next scalar in the sequence.
T corr_constrain(T &lp)
Return the next scalar transformed to be a (partial) correlation between -1 and 1,...
row_vector_t row_vector_constrain(size_t m)
Return a row vector of specified dimensionality made up of the next scalars.
row_vector_t row_vector(size_t m)
Return a row vector of specified dimensionality made up of the next scalars.
vector_t ordered_constrain(size_t k, T &lp)
Return the next ordered vector of the specified size, incrementing the specified reference with the l...
vector_t vector_lb_constrain(const TL lb, size_t m)
vector_t simplex_constrain(size_t k, T &lp)
Return the next simplex of the specified size (using one fewer unconstrained scalars),...
T scalar_lb_constrain(const TL lb, T &lp)
Return the next scalar transformed to have the specified lower bound, incrementing the specified refe...
matrix_t matrix_lub_constrain(const TL lb, const TU ub, size_t m, size_t n)
row_vector_t row_vector_lb(const TL lb, size_t m)
Eigen::Matrix< T, 1, Eigen::Dynamic > row_vector_t
int integer_lb_constrain(int lb)
Return the next integer, checking that it is greater than or equal to the specified lower bound.
row_vector_t row_vector_ub_constrain(const TU ub, size_t m)
matrix_t matrix_lb_constrain(const TL lb, size_t m, size_t n, T &lp)
vector_t simplex(size_t k)
Return a simplex of the specified size made up of the next scalars.
vector_t vector_lub_constrain(const TL lb, const TU ub, size_t m)
reader(std::vector< T > &data_r, std::vector< int > &data_i)
Construct a variable reader using the specified vectors as the source of scalar and integer values fo...
matrix_t corr_matrix(size_t k)
Returns the next correlation matrix of the specified dimensionality.
int integer_ub_constrain(int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound.
T scalar_ub(TU ub)
Return the next scalar, checking that it is less than or equal to the specified upper bound.
int integer_lub_constrain(int lb, int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound.
T scalar_lb_constrain(const TL lb)
Return the next scalar transformed to have the specified lower bound.
row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m)
row_vector_t row_vector_lub_constrain(const TL lb, const TU ub, size_t m, T &lp)
matrix_t corr_matrix_constrain(size_t k, T &lp)
Return the next correlation matrix of the specified dimensionality, incrementing the specified refere...
int integer_constrain(T &log_prob)
Return the next integer in the integer sequence.
matrix_t cov_matrix_constrain(size_t k)
Return the next covariance matrix of the specified dimensionality.
row_vector_t row_vector_constrain(size_t m, T &lp)
Return a row vector of specified dimensionality made up of the next scalars.
row_vector_t row_vector_lb_constrain(const TL lb, size_t m)
vector_t positive_ordered(size_t k)
Return the next vector of specified size containing positive values in ascending order.
vector_t vector(size_t m)
Return a column vector of specified dimensionality made up of the next scalars.
Eigen::Matrix< T, Eigen::Dynamic, 1 > vector_t
matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n, T &lp)
T scalar_pos()
Return the next scalar, checking that it is positive.
vector_t vector_lub(const TL lb, const TU ub, size_t m)
vector_t positive_ordered_constrain(size_t k, T &lp)
Return the next positive_ordered vector of the specified size, incrementing the specified reference w...
T prob()
Return the next scalar, checking that it is a valid value for a probability, between 0 (inclusive) an...
T scalar_lub_constrain(TL lb, TU ub, T &lp)
Return the next scalar transformed to be between the the specified lower and upper bounds.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > matrix_t
vector_t ordered_constrain(size_t k)
Return the next ordered vector of the specified length.
vector_t ordered(size_t k)
Return the next vector of specified size containing values in ascending order.
vector_t vector_lb(const TL lb, size_t m)
T corr_constrain()
Return the next scalar transformed to be a correlation between -1 and 1.
T scalar_constrain(T &log_prob)
Return the next scalar in the sequence, incrementing the specified reference with the log absolute Ja...
int integer_constrain()
Return the next integer in the integer sequence.
vector_t positive_ordered_constrain(size_t k)
Return the next positive ordered vector of the specified length.
int integer()
Return the next integer in the integer sequence.
T corr()
Return the next scalar, checking that it is a valid value for a correlation, between -1 (inclusive) a...
matrix_t matrix_ub_constrain(const TU ub, size_t m, size_t n)
int integer_lub(int lb, int ub)
Return the next integer, checking that it is less than or equal to the specified upper bound.
matrix_t matrix_lb(const TL lb, size_t m, size_t n)
matrix_t matrix(size_t m, size_t n)
Return a matrix of the specified dimensionality made up of the next scalars arranged in column-major ...
bool check_corr_matrix(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result, const Policy &)
Return true if the specified matrix is a valid correlation matrix.
bool check_simplex(const char *function, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const char *name, T_result *result, const Policy &)
Return true if the specified vector is simplex.
bool check_ordered(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const char *name, T_result *result, const Policy &)
Return true if the specified vector is sorted into increasing order.
bool check_greater_or_equal(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result, const Policy &)
bool check_positive_ordered(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const char *name, T_result *result, const Policy &)
Return true if the specified vector contains only non-negative values and is sorted into increasing o...
bool check_cov_matrix(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result, const Policy &)
Return true if the specified matrix is a valid covariance matrix.
bool check_less_or_equal(const char *function, const T_y &y, const T_high &high, const char *name, T_result *result, const Policy &)
bool check_bounded(const char *function, const T_y &y, const T_low &low, const T_high &high, const char *name, T_result *result, const Policy &)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
T corr_constrain(const T x)
Return the result of transforming the specified scalar to have a valid correlation value between -1 a...
Eigen::Matrix< T, Eigen::Dynamic, 1 > positive_ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing positive ordered vector derived from the specified free vector.
Eigen::Matrix< T, Eigen::Dynamic, 1 > simplex_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &y)
Return the simplex corresponding to the specified free vector.
boost::math::tools::promote_args< T, TU >::type ub_constrain(const T x, const TU ub)
Return the upper-bounded value for the specified unconstrained scalar and upper bound.
Eigen::Matrix< T, Eigen::Dynamic, 1 > ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing ordered vector derived from the specified free vector.
T prob_constrain(const T x)
Return a probability value constrained to fall between 0 and 1 (inclusive) for the specified free sca...
T lb_constrain(const T x, const TL lb)
Return the lower-bounded value for the specified unconstrained input and specified lower bound.
boost::math::tools::promote_args< T, TL, TU >::type lub_constrain(const T x, TL lb, TU ub)
Return the lower- and upper-bounded scalar derived by transforming the specified free scalar given th...
T positive_constrain(const T x)
Return the positive value for the specified unconstrained input.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > corr_matrix_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, typename Eigen::Matrix< T, Eigen::Dynamic, 1 >::size_type k)
Return the correlation matrix of the specified dimensionality derived from the specified vector of un...
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > cov_matrix_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, typename Eigen::Matrix< T, Eigen::Dynamic, 1 >::size_type K)
Return the symmetric, positive-definite matrix of dimensions K by K resulting from transforming the s...
Probability, optimization and sampling library.