Stan Math Library  2.6.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
to_fvar.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_TO_FVAR_HPP
2 #define STAN_MATH_FWD_MAT_FUN_TO_FVAR_HPP
3 
5 #include <stan/math/fwd/core.hpp>
8 #include <boost/utility/enable_if.hpp>
9 
10 namespace stan {
11  namespace math {
12 
13  template<typename T>
14  inline
15  fvar<T>
16  to_fvar(const T& x) {
17  return fvar<T>(x);
18  }
19 
20  template<typename T>
21  inline
22  fvar<T>
23  to_fvar(const fvar<T>& x) {
24  return x;
25  }
26 
27 
28  template<int R, int C, typename T>
29  inline
30  Eigen::Matrix<T, R, C>
31  to_fvar(const Eigen::Matrix<T, R, C>& m) {
32  return m;
33  }
34 
35  template<int R, int C>
36  inline
37  Eigen::Matrix<fvar<double>, R, C>
38  to_fvar(const Eigen::Matrix<double, R, C>& m) {
39  Eigen::Matrix<fvar<double>, R, C> m_fd(m.rows(), m.cols());
40  for (int i = 0; i < m.size(); ++i)
41  m_fd(i) = m(i);
42  return m_fd;
43  }
44 
45  template<typename T, int R, int C>
46  inline
47  Eigen::Matrix<fvar<T>, R, C>
48  to_fvar(const Eigen::Matrix<T, R, C>& val,
49  const Eigen::Matrix<T, R, C>& deriv) {
51  "value", val,
52  "deriv", deriv);
53  Eigen::Matrix<fvar<T>, R, C> ret(val.rows(), val.cols());
54  for (int i = 0; i < val.rows(); i++) {
55  for (int j = 0; j < val.cols(); j++) {
56  ret(i, j).val_ = val(i, j);
57  ret(i, j).d_ = deriv(i, j);
58  }
59  }
60  return ret;
61  }
62  }
63 }
64 #endif
fvar< T > to_fvar(const T &x)
Definition: to_fvar.hpp:16
bool check_matching_dims(const char *function, const char *name1, const Eigen::Matrix< T1, R1, C1 > &y1, const char *name2, const Eigen::Matrix< T2, R2, C2 > &y2)
Return true if the two matrices are of the same size.

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