Stan Math Library: stan/math/prim/mat/fun/to_array_2d.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 // real[, ] to_array_2d(matrix)
11 template <typename T>
12 inline std::vector< std::vector<T> >
13 to_array_2d(
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
stan
Definition: log_sum_exp.hpp:8
stan::math::to_array_2d
std::vector< std::vector< T > > to_array_2d(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &matrix)
Definition: to_array_2d.hpp:13
Eigen.hpp

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