1 #ifndef STAN__META__TRAITS_HPP
2 #define STAN__META__TRAITS_HPP
6 #include <boost/type_traits.hpp>
7 #include <boost/type_traits/is_arithmetic.hpp>
8 #include <boost/math/tools/promotion.hpp>
48 enum {
value = boost::is_convertible<T,double>::value };
67 template <
typename T,
int R,
int C>
99 struct is_vector<Eigen::Matrix<T,Eigen::Dynamic,1> > {
103 template <
typename T>
108 template <
typename T>
116 template <
bool is_vec,
typename T>
117 struct scalar_type_helper {
121 template <
typename T>
122 struct scalar_type_helper<true, T> {
124 scalar_type_helper<is_vector<typename stan::math::value_type<T>::type>::value,
137 template <
typename T>
139 typedef typename scalar_type_helper<is_vector<T>::value, T>
::type type;
142 template <
typename T>
143 inline T
get(
const T& x,
size_t n) {
146 template <
typename T>
147 inline T
get(
const std::vector<T>& x,
size_t n) {
150 template <
typename T,
int R,
int C>
151 inline T
get(
const Eigen::Matrix<T,R,C>& m,
size_t n) {
152 return m(static_cast<int>(n));
158 template <
typename T>
162 template <
typename T>
166 template <
typename T,
int R,
int C>
167 size_t length(
const Eigen::Matrix<T,R,C>& m) {
171 template<
typename T,
bool is_vec>
185 template <
typename T>
190 template <
typename T1,
typename T2>
192 size_t result =
length(x1);
197 template <
typename T1,
typename T2,
typename T3>
198 size_t max_size(
const T1& x1,
const T2& x2,
const T3& x3) {
199 size_t result =
length(x1);
205 template <
typename T1,
typename T2,
typename T3,
typename T4>
206 size_t max_size(
const T1& x1,
const T2& x2,
const T3& x3,
const T4& x4) {
207 size_t result =
length(x1);
215 template <
typename T>
216 struct scalar_type<Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> > {
220 template <
typename T>
227 template <
typename T>
231 template <
typename T>
233 enum { value =
true };
236 template <
typename T>
241 template <
typename T>
272 template <
typename T,
274 bool throw_if_accessed =
false>
283 template <
int R,
int C>
289 if (throw_if_accessed)
290 throw std::out_of_range(
"VectorView: this cannot be accessed");
304 template <
typename T,
bool is_array,
bool throw_if_accessed>
315 template <
int R,
int C>
316 VectorView(
const Eigen::Matrix<scalar_t,R,C>& m) : x_(&m(0)) { }
319 if (throw_if_accessed)
320 throw std::out_of_range(
"VectorView: this cannot be accessed");
357 template<
bool used,
bool is_vec>
362 throw std::runtime_error(
"used is false. this should never be called");
380 std::vector<double> x_;
392 template <
typename T1,
393 typename T2 = double,
394 typename T3 = double,
395 typename T4 = double,
396 typename T5 = double,
397 typename T6 =
double>
400 boost::math::tools::promote_args<typename scalar_type<T1>::type,
410 template <
typename T>
414 template <
typename T>
420 template <
typename T>
437 template <
typename T1,
438 typename T2 = double,
439 typename T3 = double,
440 typename T4 = double,
441 typename T5 = double,
442 typename T6 =
double>
455 template <
typename T1,
456 typename T2 = double,
457 typename T3 = double,
458 typename T4 = double,
459 typename T5 = double,
460 typename T6 =
double>
465 || boost::is_arithmetic<typename scalar_type<T1>::type>
::value)
469 || boost::is_arithmetic<typename scalar_type<T3>::type>
::value)
473 || boost::is_arithmetic<typename scalar_type<T5>::type>
::value)
480 template <
bool is_vec,
typename T,
typename T_container>
481 struct scalar_type_helper_pre {
482 typedef T_container type;
485 template <
typename T,
typename T_container>
486 struct scalar_type_helper_pre<true, T, T_container> {
488 scalar_type_helper_pre<is_vector<typename stan::math::value_type<T>::type>::value,
501 template <
typename T>
504 scalar_type_helper_pre<is_vector<typename stan::math::value_type<T>::type>::value,
510 template <
typename T,
513 bool throw_if_accessed =
false>
523 if (throw_if_accessed)
524 throw std::out_of_range(
"VectorViewMvt: this cannot be accessed");
538 template <
typename T,
bool is_array,
bool throw_if_accessed>
548 if (throw_if_accessed)
549 throw std::out_of_range(
"VectorViewMvt: this cannot be accessed");
560 template <
typename T>
562 throw std::out_of_range(
"length_mvt passed to an unrecognized type.");
565 template <
typename T,
int R,
int C>
569 template <
typename T,
int R,
int C>
570 size_t length_mvt(
const std::vector<Eigen::Matrix<T,R,C> >& x) {
574 template <
typename T1,
typename T2>
581 template <
typename T1,
typename T2,
typename T3>
589 template <
typename T1,
typename T2,
typename T3,
typename T4>
590 size_t max_size_mvt(
const T1& x1,
const T2& x2,
const T3& x3,
const T4& x4) {
scalar_type< T >::type type
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
double & operator[](size_t i)
Metaprogram structure to determine the base scalar type of a template argument.
scalar_t & operator[](int i)
size_t max_size_mvt(const T1 &x1, const T2 &x2)
scalar_type< T >::type scalar_t
double & operator[](size_t)
static size_t size_of(const T &)
scalar_type_helper_pre< is_vector< typename stan::math::value_type< T >::type >::value, typename stan::math::value_type< T >::type, T >::type type
static size_t size_of(const T &x)
DoubleVectorView(size_t n)
double & operator[](size_t)
VectorViewMvt(std::vector< matrix_t > &vm)
Metaprogram to calculate the base scalar return type resulting from promoting all the scalar types of...
DoubleVectorView allocates double values to be used as intermediate values.
scalar_type_helper< is_vector< T >::value, T >::type type
VectorViewMvt(const std::vector< matrix_t > &vm)
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type
matrix_t & operator[](int i)
VectorView(std::vector< scalar_t > &v)
Metaprogram to determine if a type has a base scalar type that can be assigned to type double...
VectorView(const scalar_t *x)
scalar_type< T >::type scalar_t
size_t size_of(const T &x)
VectorView(const std::vector< scalar_t > &v)
size_t length_mvt(const T &)
scalar_type< T >::type type
size_t max_size(const T1 &x1, const T2 &x2)
VectorView(Eigen::Matrix< scalar_t, R, C > &m)
const scalar_t & operator[](int i) const
double operator[](int) const
Independent (input) and dependent (output) variables for gradients.
const matrix_t & operator[](int i) const
VectorViewMvt(matrix_t &m)
VectorView(const scalar_t &c)
scalar_type_pre< T >::type matrix_t
VectorViewMvt(const matrix_t &m)
Metaprogram structure to determine the type of first container of the base scalar type of a template ...
Metaprogram to calculate the base scalar return type resulting from promoting all the scalar types of...
VectorView is a template metaprogram that takes its argument and allows it to be used like a vector...
VectorView(const Eigen::Matrix< scalar_t, R, C > &m)
scalar_type_pre< T >::type matrix_t
Primary template class for metaprogram to compute the type of values stored in a container.