Stan Math Library  2.9.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> >
14  const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> & matrix
15  ) {
16  using std::vector;
17  const T* datap = matrix.data();
18  int C = matrix.cols();
19  int R = matrix.rows();
20  vector< vector<T> > result(R, vector<T>(C));
21  for (int i=0, ij=0; i < C; i++)
22  for (int j=0; j < R; j++, ij++)
23  result[j][i] = datap[ij];
24  return result;
25  }
26 
27  }
28 }
29 #endif
std::vector< std::vector< T > > to_array_2d(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &matrix)
Definition: to_array_2d.hpp:13

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