1 #ifndef STAN_MATH_PRIM_MAT_FUN_TO_MATRIX_HPP 2 #define STAN_MATH_PRIM_MAT_FUN_TO_MATRIX_HPP 4 #include <boost/math/tools/promotion.hpp> 24 template <
typename T,
int R,
int C>
25 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
39 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
41 std::vector<Eigen::Matrix<T, 1, Eigen::Dynamic> >& x) {
44 return Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> (0, 0);
45 int cols = x[0].size();
46 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
48 for (
int i = 0, ij = 0; i <
cols; i++)
49 for (
int j = 0; j <
rows; j++, ij++)
63 inline Eigen::Matrix<
typename 64 boost::math::tools::promote_args<T, double>::type,
65 Eigen::Dynamic, Eigen::Dynamic>
67 using boost::math::tools::promote_args;
68 size_t rows = x.size();
70 return Eigen::Matrix<typename promote_args<T, double>::type,
71 Eigen::Dynamic, Eigen::Dynamic> (0, 0);
72 size_t cols = x[0].size();
73 Eigen::Matrix<typename promote_args<T, double>::type,
74 Eigen::Dynamic, Eigen::Dynamic> result(rows, cols);
75 for (
size_t i = 0, ij = 0; i <
cols; i++)
76 for (
size_t j = 0; j <
rows; j++, ij++)
93 template <
typename T,
int R,
int C>
94 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
95 to_matrix(
const Eigen::Matrix<T, R, C>& x,
int m,
int n) {
96 static const char* fun =
"to_matrix(matrix)";
99 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> y = x;
116 template <
typename T>
117 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
119 static const char* fun =
"to_matrix(array)";
122 return Eigen::Map<
const 123 Eigen::Matrix<T, Eigen::Dynamic,
124 Eigen::Dynamic> >(&x[0], m, n);
138 inline Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
140 static const char* fun =
"to_matrix(array)";
143 "vector size", size);
144 Eigen::Matrix<double,
145 Eigen::Dynamic, Eigen::Dynamic> result(m, n);
146 for (
int i = 0; i <
size; i++)
167 template <
typename T,
int R,
int C>
168 inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
169 to_matrix(
const Eigen::Matrix<T, R, C>& x,
int m,
int n,
174 "matrix size", x.size());
175 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
177 for (
int i = 0, ij = 0; i < m; i++)
178 for (
int j = 0; j < n; j++, ij++)
179 result(i, j) = x(ij);
199 template <
typename T>
201 Eigen::Matrix<
typename 202 boost::math::tools::promote_args<T, double>::type,
203 Eigen::Dynamic, Eigen::Dynamic>
204 to_matrix(
const std::vector<T>& x,
int m,
int n,
bool col_major) {
208 "matrix size", x.size());
209 Eigen::Matrix<
typename 210 boost::math::tools::promote_args<T, double>::type,
211 Eigen::Dynamic, Eigen::Dynamic>
213 for (
int i = 0, ij = 0; i < m; i++)
214 for (
int j = 0; j < n; j++, ij++)
215 result(i, j) = x[ij];
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > to_matrix(const Eigen::Matrix< T, R, C > &x)
Returns a matrix with dynamic dimensions constructed from an Eigen matrix which is either a row vecto...
int size(const std::vector< T > &x)
Return the size of the specified standard vector.