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

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