Stan Math Library  2.20.0
reverse mode automatic differentiation
promote_elements.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_ARR_FUN_PROMOTE_ELEMENTS_HPP
2 #define STAN_MATH_PRIM_ARR_FUN_PROMOTE_ELEMENTS_HPP
3 
6 #include <vector>
7 #include <cstddef>
8 
9 namespace stan {
10 namespace math {
11 
21 template <typename T, typename S>
22 struct promote_elements<std::vector<T>, std::vector<S> > {
29  inline static std::vector<T> promote(const std::vector<S>& u) {
30  std::vector<T> t;
31  t.reserve(u.size());
32  for (size_t i = 0; i < u.size(); ++i)
33  t.push_back(promote_elements<T, S>::promote(u[i]));
34  return t;
35  }
36 };
37 
45 template <typename T>
46 struct promote_elements<std::vector<T>, std::vector<T> > {
53  inline static const std::vector<T>& promote(const std::vector<T>& u) {
54  return u;
55  }
56 };
57 
58 } // namespace math
59 } // namespace stan
60 
61 #endif
static const std::vector< T > & promote(const std::vector< T > &u)
Return input vector.
Struct with static function for elementwise type promotion.
static std::vector< T > promote(const std::vector< S > &u)
Return input vector of type S as vector of type T.

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