Stan Math Library  2.20.0
reverse mode automatic differentiation
to_array_2d.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_TO_ARRAY_2D_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_TO_ARRAY_2D_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8 namespace math {
9 
10 // real[, ] to_array_2d(matrix)
11 template <typename T>
12 inline std::vector<std::vector<T> > to_array_2d(
13  const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& matrix) {
14  using std::vector;
15  const T* datap = matrix.data();
16  int C = matrix.cols();
17  int R = matrix.rows();
18  vector<vector<T> > result(R, vector<T>(C));
19  for (int i = 0, ij = 0; i < C; i++)
20  for (int j = 0; j < R; j++, ij++)
21  result[j][i] = datap[ij];
22  return result;
23 }
24 
25 } // namespace math
26 } // namespace stan
27 #endif
std::vector< std::vector< T > > to_array_2d(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &matrix)
Definition: to_array_2d.hpp:12

     [ Stan Home Page ] © 2011–2018, Stan Development Team.