All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
to_fvar.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_FWD_MAT_FUN_TO_FVAR_HPP
#define STAN_MATH_FWD_MAT_FUN_TO_FVAR_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/mat/err/check_matching_dims.hpp>
#include <stan/math/prim/scal/meta/is_constant.hpp>
#include <boost/utility/enable_if.hpp>
namespace stan {
namespace math {
template<typename T>
inline
fvar<T>
to_fvar(const T& x) {
return fvar<T>(x);
}
template<typename T>
inline
fvar<T>
to_fvar(const fvar<T>& x) {
return x;
}
template<int R, int C, typename T>
inline
Eigen::Matrix<T, R, C>
to_fvar(const Eigen::Matrix<T, R, C>& m) {
return m;
}
template<int R, int C>
inline
Eigen::Matrix<fvar<double>, R, C>
to_fvar(const Eigen::Matrix<double, R, C>& m) {
Eigen::Matrix<fvar<double>, R, C> m_fd(m.rows(), m.cols());
for (int i = 0; i < m.size(); ++i)
m_fd(i) = m(i);
return m_fd;
}
template<typename T, int R, int C>
inline
Eigen::Matrix<fvar<T>, R, C>
to_fvar(const Eigen::Matrix<T, R, C>& val,
const Eigen::Matrix<T, R, C>& deriv) {
stan::math::check_matching_dims("to_fvar",
"value", val,
"deriv", deriv);
Eigen::Matrix<fvar<T>, R, C> ret(val.rows(), val.cols());
for (int i = 0; i < val.rows(); i++) {
for (int j = 0; j < val.cols(); j++) {
ret(i, j).val_ = val(i, j);
ret(i, j).d_ = deriv(i, j);
}
}
return ret;
}
}
}
#endif
check_matching_dims.hpp
core.hpp
stan::math::to_fvar
fvar< T > to_fvar(const T &x)
Definition: to_fvar.hpp:16
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
stan::math::fvar
Definition: fvar.hpp:13
is_constant.hpp

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