Automatic Differentiation
 
Loading...
Searching...
No Matches
promote_elements.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_PROMOTE_ELEMENTS_HPP
2#define STAN_MATH_PRIM_FUN_PROMOTE_ELEMENTS_HPP
3
6#include <cstddef>
7#include <vector>
8
9namespace stan {
10namespace math {
11
20template <typename T, typename S>
28 inline static T promote(const S& u) { return u; }
29};
30
38template <typename T>
39struct promote_elements<T, T> {
46 inline static const T& promote(const T& u) { return u; }
47};
48
58template <typename T, typename S>
59struct promote_elements<std::vector<T>, std::vector<S> > {
66 inline static std::vector<T> promote(const std::vector<S>& u) {
67 std::vector<T> t;
68 t.reserve(u.size());
69 for (size_t i = 0; i < u.size(); ++i) {
70 t.push_back(promote_elements<T, S>::promote(u[i]));
71 }
72 return t;
73 }
74};
75
83template <typename T>
84struct promote_elements<std::vector<T>, std::vector<T> > {
91 inline static const std::vector<T>& promote(const std::vector<T>& u) {
92 return u;
93 }
94};
95
107template <typename T, typename S, int R, int C>
108struct promote_elements<Eigen::Matrix<T, R, C>, Eigen::Matrix<S, R, C> > {
115 inline static Eigen::Matrix<T, R, C> promote(
116 const Eigen::Matrix<S, R, C>& u) {
117 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> t(u.rows(), u.cols());
118 for (int i = 0; i < u.size(); ++i) {
120 }
121 return t;
122 }
123};
124
134template <typename T, int R, int C>
135struct promote_elements<Eigen::Matrix<T, R, C>, Eigen::Matrix<T, R, C> > {
142 inline static const Eigen::Matrix<T, R, C>& promote(
143 const Eigen::Matrix<T, R, C>& u) {
144 return u;
145 }
146};
147
148} // namespace math
149} // namespace stan
150
151#endif
(Expert) Numerical traits for algorithmic differentiation variables.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
STL namespace.
static const Eigen::Matrix< T, R, C > & promote(const Eigen::Matrix< T, R, C > &u)
Return input matrix.
static Eigen::Matrix< T, R, C > promote(const Eigen::Matrix< S, R, C > &u)
Return input matrix of type S as matrix of type T.
static const T & promote(const T &u)
Return input element.
static std::vector< T > promote(const std::vector< S > &u)
Return input vector of type S as vector of type T.
static const std::vector< T > & promote(const std::vector< T > &u)
Return input vector.
static T promote(const S &u)
Return input element.
Struct with static function for elementwise type promotion.