Stan Math Library  2.10.0
reverse mode automatic differentiation
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  // vector to_vector(matrix)
12  // vector to_vector(row_vector)
13  // vector to_vector(vector)
14  template <typename T, int R, int C>
15  inline Eigen::Matrix<T, Eigen::Dynamic, 1>
16  to_vector(const Eigen::Matrix<T, R, C>& matrix) {
17  return Eigen::Matrix<T, Eigen::Dynamic, 1>::Map(matrix.data(),
18  matrix.rows()*matrix.cols());
19  }
20 
21  // vector to_vector(real[])
22  template <typename T>
23  inline Eigen::Matrix<T, Eigen::Dynamic, 1>
24  to_vector(const std::vector<T> & vec) {
25  return Eigen::Matrix<T, Eigen::Dynamic, 1>::Map(vec.data(), vec.size());
26  }
27 
28  // vector to_vector(int[])
29  inline Eigen::Matrix<double, Eigen::Dynamic, 1>
30  to_vector(const std::vector<int> & vec) {
31  int R = vec.size();
32  Eigen::Matrix<double, Eigen::Dynamic, 1> result(R);
33  double* datap = result.data();
34  for (int i=0; i < R; i++)
35  datap[i] = vec[i];
36  return result;
37  }
38 
39 
40  }
41 }
42 #endif
Eigen::Matrix< T, Eigen::Dynamic, 1 > to_vector(const Eigen::Matrix< T, R, C > &matrix)
Definition: to_vector.hpp:16

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