Stan Math Library  2.20.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> to_vector(
16  const Eigen::Matrix<T, R, C>& matrix) {
17  return Eigen::Matrix<T, Eigen::Dynamic, 1>::Map(
18  matrix.data(), matrix.rows() * matrix.cols());
19 }
20 
21 // vector to_vector(real[])
22 template <typename T>
23 inline Eigen::Matrix<T, Eigen::Dynamic, 1> to_vector(
24  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> to_vector(
30  const std::vector<int>& vec) {
31  int R = vec.size();
32  Eigen::Matrix<double, Eigen::Dynamic, 1> result(R);
33  for (int i = 0; i < R; i++)
34  result(i) = vec[i];
35  return result;
36 }
37 
38 } // namespace math
39 } // namespace stan
40 #endif
Eigen::Matrix< T, Eigen::Dynamic, 1 > to_vector(const Eigen::Matrix< T, R, C > &matrix)
Definition: to_vector.hpp:15

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