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

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