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

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