All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
promote_scalar.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_SCAL_FUN_PROMOTE_SCALAR_HPP
#define STAN_MATH_PRIM_SCAL_FUN_PROMOTE_SCALAR_HPP
#include <stan/math/prim/scal/fun/promote_scalar_type.hpp>
#include <stan/math/prim/scal/meta/index_type.hpp>
#include <stan/math/prim/arr/meta/index_type.hpp>
#include <vector>
namespace stan {
namespace math {
template <typename T, typename S>
struct promote_scalar_struct {
static T apply(S x) {
return T(x);
}
};
template <typename T>
struct promote_scalar_struct<T, T> {
static T apply(const T& x) {
return x;
}
};
template <typename T, typename S>
struct promote_scalar_struct<T, std::vector<S> > {
static std::vector<typename promote_scalar_type<T, S>::type>
apply(const std::vector<S>& x) {
typedef std::vector<typename promote_scalar_type<T, S>::type> return_t;
typedef typename index_type<return_t>::type idx_t;
return_t y(x.size());
for (idx_t i = 0; i < x.size(); ++i)
y[i] = promote_scalar_struct<T, S>::apply(x[i]);
return y;
}
};
template <typename T, typename S>
typename promote_scalar_type<T, S>::type
promote_scalar(const S& x) {
return promote_scalar_struct<T, S>::apply(x);
}
}
}
#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.