| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
promote_scalar.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_PROMOTE_SCALAR_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_PROMOTE_SCALAR_HPP
3
4 #include <stan/math/prim/scal/fun/promote_scalar_type.hpp>
5 #include <stan/math/prim/scal/meta/index_type.hpp>
6 #include <stan/math/prim/arr/meta/index_type.hpp>
7 #include <vector>
8
9 namespace stan {
10
11 namespace math {
12
21 template <typename T, typename S>
22 struct promote_scalar_struct {
34 static T apply(S x) {
35 return T(x);
36 }
37 };
38
46 template <typename T>
47 struct promote_scalar_struct<T, T> {
54 static T apply(const T& x) {
55 return x;
56 }
57 };
58
68 template <typename T, typename S>
69 struct promote_scalar_struct<T, std::vector<S> > {
78 static std::vector<typename promote_scalar_type<T, S>::type>
79 apply(const std::vector<S>& x) {
80 typedef std::vector<typename promote_scalar_type<T, S>::type> return_t;
81 typedef typename index_type<return_t>::type idx_t;
82 return_t y(x.size());
83 for (idx_t i = 0; i < x.size(); ++i)
84 y[i] = promote_scalar_struct<T, S>::apply(x[i]);
85 return y;
86 }
87 };
88
98 template <typename T, typename S>
99 typename promote_scalar_type<T, S>::type
100 promote_scalar(const S& x) {
101 return promote_scalar_struct<T, S>::apply(x);
102 }
103
104
105 }
106 }
107
108 #endif
index_type.hpp
stan::math::promote_scalar_struct< T, T >::apply
static T apply(const T &x)
Return the unmodified input.
Definition: promote_scalar.hpp:54
index_type.hpp
stan::math::promote_scalar
promote_scalar_type< T, S >::type promote_scalar(const S &x)
This is the top-level function to call to promote the scalar types of an input of type S to type T...
Definition: promote_scalar.hpp:100
stan::math::promote_scalar_struct< T, std::vector< S > >::apply
static std::vector< typename promote_scalar_type< T, S >::type > apply(const std::vector< S > &x)
Return the standard vector consisting of the recursive promotion of the elements of the input standar...
Definition: promote_scalar.hpp:79
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
stan::math::promote_scalar_struct
General struct to hold static function for promoting underlying scalar types.
Definition: promote_scalar.hpp:22
promote_scalar_type.hpp
stan::math::promote_scalar_struct::apply
static T apply(S x)
Return the value of the input argument promoted to the type specified by the template parameter...
Definition: promote_scalar.hpp:34

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