| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <vector>
6
7 namespace stan {
8 namespace math {
9
10 using Eigen::Dynamic;
11 using Eigen::Matrix;
12 using std::vector;
13
14 // real[, ] to_array_2d(matrix)
15 template <typename T>
16 inline vector< vector<T> >
17 to_array_2d(const Matrix<T, Dynamic, Dynamic> & matrix) {
18 const T* datap = matrix.data();
19 int C = matrix.cols();
20 int R = matrix.rows();
21 vector< vector<T> > result(R, vector<T>(C));
22 for (int i=0, ij=0; i < C; i++)
23 for (int j=0; j < R; j++, ij++)
24 result[j][i] = datap[ij];
25 return result;
26 }
27
28 }
29 }
30 #endif
stan::math::to_array_2d
vector< vector< T > > to_array_2d(const Matrix< T, Dynamic, Dynamic > &matrix)
Definition: to_array_2d.hpp:17
Eigen.hpp

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