Stan Math Library: stan/math/fwd/mat/fun/to_fvar.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/fwd/core.hpp>
6 #include <stan/math/fwd/scal/fun/to_fvar.hpp>
7 #include <stan/math/prim/mat/err/check_matching_dims.hpp>
8
9
10 namespace stan {
11 namespace math {
12
13 template<int R, int C, typename T>
14 inline
15 Eigen::Matrix<T, R, C>
16 to_fvar(const Eigen::Matrix<T, R, C>& m) {
17 return m;
18 }
19
20 template<int R, int C>
21 inline
22 Eigen::Matrix<fvar<double>, R, C>
23 to_fvar(const Eigen::Matrix<double, R, C>& m) {
24 Eigen::Matrix<fvar<double>, R, C> m_fd(m.rows(), m.cols());
25 for (int i = 0; i < m.size(); ++i)
26 m_fd(i) = m(i);
27 return m_fd;
28 }
29
30 template<typename T, int R, int C>
31 inline
32 Eigen::Matrix<fvar<T>, R, C>
33 to_fvar(const Eigen::Matrix<T, R, C>& val,
34 const Eigen::Matrix<T, R, C>& deriv) {
35 stan::math::check_matching_dims("to_fvar",
36 "value", val,
37 "deriv", deriv);
38 Eigen::Matrix<fvar<T>, R, C> ret(val.rows(), val.cols());
39 for (int i = 0; i < val.rows(); i++) {
40 for (int j = 0; j < val.cols(); j++) {
41 ret(i, j).val_ = val(i, j);
42 ret(i, j).d_ = deriv(i, j);
43 }
44 }
45 return ret;
46 }
47 }
48 }
49 #endif
check_matching_dims.hpp
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::to_fvar
std::vector< fvar< T > > to_fvar(const std::vector< T > &v)
Definition: to_fvar.hpp:14
stan::math::check_matching_dims
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.
Definition: check_matching_dims.hpp:37
Eigen.hpp
to_fvar.hpp

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