Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
to_vector.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_TO_VECTOR_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_TO_VECTOR_HPP
3 
5  // stan::scalar_type
6 #include <vector>
7 
8 namespace stan {
9  namespace math {
10 
11  using Eigen::Dynamic;
12  using Eigen::Matrix;
13  using std::vector;
14 
15  // vector to_vector(matrix)
16  // vector to_vector(row_vector)
17  // vector to_vector(vector)
18  template <typename T, int R, int C>
19  inline Matrix<T, Dynamic, 1>
20  to_vector(const Matrix<T, R, C>& matrix) {
21  return Matrix<T, Dynamic, 1>::Map(matrix.data(),
22  matrix.rows()*matrix.cols());
23  }
24 
25  // vector to_vector(real[])
26  template <typename T>
27  inline Matrix<T, Dynamic, 1>
28  to_vector(const vector<T> & vec) {
29  return Matrix<T, Dynamic, 1>::Map(vec.data(), vec.size());
30  }
31 
32  // vector to_vector(int[])
33  inline Matrix<double, Dynamic, 1>
34  to_vector(const vector<int> & vec) {
35  int R = vec.size();
36  Matrix<double, Dynamic, 1> result(R);
37  double* datap = result.data();
38  for (int i=0; i < R; i++)
39  datap[i] = vec[i];
40  return result;
41  }
42 
43 
44  }
45 }
46 #endif
Matrix< T, Dynamic, 1 > to_vector(const Matrix< T, R, C > &matrix)
Definition: to_vector.hpp:20

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