Stan Math Library  2.20.0
reverse mode automatic differentiation
to_var.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_TO_VAR_HPP
2 #define STAN_MATH_REV_MAT_FUN_TO_VAR_HPP
3 
4 #include <stan/math/rev/meta.hpp>
7 #include <stan/math/rev/core.hpp>
10 
11 namespace stan {
12 namespace math {
13 
22 inline matrix_v to_var(const matrix_d& m) {
23  matrix_v m_v(m.rows(), m.cols());
24  for (int j = 0; j < m.cols(); ++j)
25  for (int i = 0; i < m.rows(); ++i)
26  m_v(i, j) = m(i, j);
27  return m_v;
28 }
37 inline matrix_v to_var(const matrix_v& m) { return m; }
47 inline vector_v to_var(const vector_d& v) {
48  vector_v v_v(v.size());
49  for (int i = 0; i < v.size(); ++i)
50  v_v[i] = v[i];
51  return v_v;
52 }
62 inline vector_v to_var(const vector_v& v) { return v; }
72 inline row_vector_v to_var(const row_vector_d& rv) {
73  row_vector_v rv_v(rv.size());
74  for (int i = 0; i < rv.size(); ++i)
75  rv_v[i] = rv[i];
76  return rv_v;
77 }
87 inline row_vector_v to_var(const row_vector_v& rv) { return rv; }
88 
89 } // namespace math
90 } // namespace stan
91 #endif
Eigen::Matrix< var, Eigen::Dynamic, 1 > vector_v
The type of a (column) vector holding var values.
Definition: typedefs.hpp:23
Eigen::Matrix< double, Eigen::Dynamic, 1 > vector_d
Type for (column) vector of double values.
Definition: typedefs.hpp:24
Eigen::Matrix< double, 1, Eigen::Dynamic > row_vector_d
Type for (row) vector of double values.
Definition: typedefs.hpp:29
Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > matrix_v
The type of a matrix holding var values.
Definition: typedefs.hpp:17
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > matrix_d
Type for matrix of double values.
Definition: typedefs.hpp:19
Eigen::Matrix< var, 1, Eigen::Dynamic > row_vector_v
The type of a row vector holding var values.
Definition: typedefs.hpp:29
std::vector< var > to_var(const std::vector< double > &v)
Converts argument to an automatic differentiation variable.
Definition: to_var.hpp:19

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