| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

promoter.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_PROMOTER_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_PROMOTER_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <vector>
6
7 namespace stan {
8
9 namespace math {
10 // from input type F to output type T
11
12 // scalar, F != T (base template)
13 template <typename F, typename T>
14 struct promoter {
15 inline static void promote(const F& u, T& t) {
16 t = u;
17 }
18 inline static T promote_to(const F& u) {
19 return u;
20 }
21 };
22 // scalar, F == T
23 template <typename T>
24 struct promoter<T, T> {
25 inline static void promote(const T& u, T& t) {
26 t = u;
27 }
28 inline static T promote_to(const T& u) {
29 return u;
30 }
31 };
32
33 // std::vector, F != T
34 template <typename F, typename T>
35 struct promoter<std::vector<F>, std::vector<T> > {
36 inline static void promote(const std::vector<F>& u,
37 std::vector<T>& t) {
38 t.resize(u.size());
39 for (size_t i = 0; i < u.size(); ++i)
40 promoter<F, T>::promote(u[i], t[i]);
41 }
42 inline static std::vector<T>
43 promote_to(const std::vector<F>& u) {
44 std::vector<T> t;
45 promoter<std::vector<F>, std::vector<T> >::promote(u, t);
46 return t;
47 }
48 };
49 // std::vector, F == T
50 template <typename T>
51 struct promoter<std::vector<T>, std::vector<T> > {
52 inline static void promote(const std::vector<T>& u,
53 std::vector<T>& t) {
54 t = u;
55 }
56 inline static std::vector<T> promote_to(const std::vector<T>& u) {
57 return u;
58 }
59 };
60
61 // Eigen::Matrix, F != T
62 template <typename F, typename T, int R, int C>
63 struct promoter<Eigen::Matrix<F, R, C>, Eigen::Matrix<T, R, C> > {
64 inline static void promote(const Eigen::Matrix<F, R, C>& u,
65 Eigen::Matrix<T, R, C>& t) {
66 t.resize(u.rows(), u.cols());
67 for (int i = 0; i < u.size(); ++i)
68 promoter<F, T>::promote(u(i), t(i));
69 }
70 inline static Eigen::Matrix<T, R, C>
71 promote_to(const Eigen::Matrix<F, R, C>& u) {
72 Eigen::Matrix<T, R, C> t;
73 promoter<Eigen::Matrix<F, R, C>,
74 Eigen::Matrix<T, R, C> >::promote(u, t);
75 return t;
76 }
77 };
78 // Eigen::Matrix, F == T
79 template <typename T, int R, int C>
80 struct promoter<Eigen::Matrix<T, R, C>, Eigen::Matrix<T, R, C> > {
81 inline static void promote(const Eigen::Matrix<T, R, C>& u,
82 Eigen::Matrix<T, R, C>& t) {
83 t = u;
84 }
85 inline static Eigen::Matrix<T, R, C>
86 promote_to(const Eigen::Matrix<T, R, C>& u) {
87 return u;
88 }
89 };
90
91 }
92 }
93
94
95 #endif
stan::math::promoter< T, T >::promote
static void promote(const T &u, T &t)
Definition: promoter.hpp:25
stan::math::promoter< std::vector< T >, std::vector< T > >::promote
static void promote(const std::vector< T > &u, std::vector< T > &t)
Definition: promoter.hpp:52
stan
Definition: log_sum_exp.hpp:8
stan::math::promoter< Eigen::Matrix< F, R, C >, Eigen::Matrix< T, R, C > >::promote
static void promote(const Eigen::Matrix< F, R, C > &u, Eigen::Matrix< T, R, C > &t)
Definition: promoter.hpp:64
std
Definition: std_numeric_limits.hpp:7
Eigen
(Expert) Numerical traits for algorithmic differentiation variables.
Definition: Eigen_NumTraits.hpp:8
stan::math::promoter< std::vector< F >, std::vector< T > >::promote
static void promote(const std::vector< F > &u, std::vector< T > &t)
Definition: promoter.hpp:36
stan::math::promoter< T, T >::promote_to
static T promote_to(const T &u)
Definition: promoter.hpp:28
stan::math::promoter< Eigen::Matrix< T, R, C >, Eigen::Matrix< T, R, C > >::promote
static void promote(const Eigen::Matrix< T, R, C > &u, Eigen::Matrix< T, R, C > &t)
Definition: promoter.hpp:81
stan::math::promoter< Eigen::Matrix< T, R, C >, Eigen::Matrix< T, R, C > >::promote_to
static Eigen::Matrix< T, R, C > promote_to(const Eigen::Matrix< T, R, C > &u)
Definition: promoter.hpp:86
Eigen.hpp
stan::math::promoter::promote
static void promote(const F &u, T &t)
Definition: promoter.hpp:15
stan::math::promoter::promote_to
static T promote_to(const F &u)
Definition: promoter.hpp:18
stan::math::promoter< std::vector< F >, std::vector< T > >::promote_to
static std::vector< T > promote_to(const std::vector< F > &u)
Definition: promoter.hpp:43
stan::math::promoter
Definition: promoter.hpp:14
stan::math::promoter< std::vector< T >, std::vector< T > >::promote_to
static std::vector< T > promote_to(const std::vector< T > &u)
Definition: promoter.hpp:56
stan::math::promoter< Eigen::Matrix< F, R, C >, Eigen::Matrix< T, R, C > >::promote_to
static Eigen::Matrix< T, R, C > promote_to(const Eigen::Matrix< F, R, C > &u)
Definition: promoter.hpp:71

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