From e0119a3dcbaf86e0cbf0fc7462213e5bc975ba68 Mon Sep 17 00:00:00 2001 From: stevo15025 Date: Sun, 1 Sep 2019 23:00:49 +0300 Subject: [PATCH 01/21] This refactors all of the meta functions to either use standard library methods or coalesce them to be more consistent --- stan/math/fwd/core/fvar.hpp | 5 +- stan/math/fwd/meta.hpp | 1 - stan/math/fwd/scal/meta/ad_promotable.hpp | 30 ---- stan/math/fwd/scal/meta/is_fvar.hpp | 21 ++- stan/math/fwd/scal/meta/partials_type.hpp | 6 +- stan/math/mix/meta.hpp | 2 - .../prim/arr/meta/contains_std_vector.hpp | 20 --- stan/math/prim/arr/meta/index_type.hpp | 9 +- stan/math/prim/arr/meta/is_constant.hpp | 10 +- stan/math/prim/arr/meta/is_vector.hpp | 30 ++-- stan/math/prim/arr/meta/scalar_type.hpp | 23 +-- stan/math/prim/arr/meta/value_type.hpp | 9 +- stan/math/prim/mat/meta/index_type.hpp | 10 +- stan/math/prim/mat/meta/is_constant.hpp | 19 +-- stan/math/prim/mat/meta/is_eigen.hpp | 29 ++++ stan/math/prim/mat/meta/is_vector.hpp | 28 ---- stan/math/prim/mat/meta/is_vector_like.hpp | 43 ------ .../prim/mat/meta/operands_and_partials.hpp | 3 +- stan/math/prim/mat/meta/scalar_type.hpp | 57 +------ stan/math/prim/mat/meta/value_type.hpp | 10 +- .../prim/mat/prob/bernoulli_logit_glm_rng.hpp | 16 +- stan/math/prim/meta.hpp | 7 +- stan/math/prim/scal/meta/VectorBuilder.hpp | 7 +- stan/math/prim/scal/meta/ad_promotable.hpp | 143 +----------------- stan/math/prim/scal/meta/bool_constant.hpp | 15 ++ stan/math/prim/scal/meta/child_type.hpp | 11 +- stan/math/prim/scal/meta/contains_fvar.hpp | 3 +- .../prim/scal/meta/contains_std_vector.hpp | 10 +- stan/math/prim/scal/meta/contains_vector.hpp | 2 +- stan/math/prim/scal/meta/include_summand.hpp | 27 ++-- stan/math/prim/scal/meta/index_type.hpp | 16 +- stan/math/prim/scal/meta/is_constant.hpp | 11 +- stan/math/prim/scal/meta/is_eigen.hpp | 15 ++ stan/math/prim/scal/meta/is_fvar.hpp | 10 +- stan/math/prim/scal/meta/is_var.hpp | 10 +- .../prim/scal/meta/is_var_or_arithmetic.hpp | 11 +- stan/math/prim/scal/meta/is_vector.hpp | 73 ++++++++- stan/math/prim/scal/meta/is_vector_like.hpp | 38 +---- .../prim/scal/meta/partials_return_type.hpp | 12 +- stan/math/prim/scal/meta/partials_type.hpp | 14 +- stan/math/prim/scal/meta/promote_args.hpp | 15 ++ stan/math/prim/scal/meta/return_type.hpp | 8 +- stan/math/prim/scal/meta/scalar_seq_view.hpp | 25 +-- stan/math/prim/scal/meta/scalar_type.hpp | 33 +++- stan/math/prim/scal/meta/scalar_type_pre.hpp | 3 +- stan/math/prim/scal/meta/value_type.hpp | 27 ++-- stan/math/prim/scal/prob/inv_gamma_lpdf.hpp | 6 +- stan/math/rev/core/var.hpp | 18 +++ stan/math/rev/meta.hpp | 1 - stan/math/rev/scal/meta/ad_promotable.hpp | 33 ---- stan/math/rev/scal/meta/is_var.hpp | 10 +- stan/math/rev/scal/meta/partials_type.hpp | 11 +- .../math/fwd/scal/meta/ad_promotable_test.cpp | 3 +- .../arr/meta/contains_std_vector_test.cpp | 4 +- .../prim/arr/meta/contains_vector_test.cpp | 4 +- .../math/prim/arr/meta/is_vector_test.cpp | 9 +- .../math/prim/arr/meta/scalar_type_test.cpp | 12 +- .../mat/meta/contains_std_vector_test.cpp | 4 +- .../math/prim/mat/meta/is_vector_test.cpp | 6 + .../mat/prob/bernoulli_logit_glm_rng_test.cpp | 14 +- .../prim/scal/meta/ad_promotable_test.cpp | 26 ++-- .../scal/meta/is_var_or_arihtmetic_test.cpp | 4 +- .../math/prim/scal/meta/is_vector_test.cpp | 1 + .../math/rev/scal/meta/ad_promotable_test.cpp | 2 +- .../scal/meta/is_var_or_arithmetic_test.cpp | 6 +- 65 files changed, 467 insertions(+), 634 deletions(-) delete mode 100644 stan/math/fwd/scal/meta/ad_promotable.hpp delete mode 100644 stan/math/prim/arr/meta/contains_std_vector.hpp create mode 100644 stan/math/prim/mat/meta/is_eigen.hpp delete mode 100644 stan/math/prim/mat/meta/is_vector.hpp delete mode 100644 stan/math/prim/mat/meta/is_vector_like.hpp create mode 100644 stan/math/prim/scal/meta/bool_constant.hpp create mode 100644 stan/math/prim/scal/meta/is_eigen.hpp create mode 100644 stan/math/prim/scal/meta/promote_args.hpp delete mode 100644 stan/math/rev/scal/meta/ad_promotable.hpp diff --git a/stan/math/fwd/core/fvar.hpp b/stan/math/fwd/core/fvar.hpp index 78ea4607d4e..4679e702c48 100644 --- a/stan/math/fwd/core/fvar.hpp +++ b/stan/math/fwd/core/fvar.hpp @@ -3,7 +3,6 @@ #include #include -#include #include namespace stan { @@ -49,6 +48,10 @@ struct fvar { */ T d_; + /** + * The Type inside of the fvar. + */ + using Scalar = T; /** * Return the value of this variable. * diff --git a/stan/math/fwd/meta.hpp b/stan/math/fwd/meta.hpp index 7483cb6cd33..fbcff8ca4db 100644 --- a/stan/math/fwd/meta.hpp +++ b/stan/math/fwd/meta.hpp @@ -1,7 +1,6 @@ #ifndef STAN_MATH_FWD_META_HPP #define STAN_MATH_FWD_META_HPP -#include #include #include #include diff --git a/stan/math/fwd/scal/meta/ad_promotable.hpp b/stan/math/fwd/scal/meta/ad_promotable.hpp deleted file mode 100644 index 266602b2a3b..00000000000 --- a/stan/math/fwd/scal/meta/ad_promotable.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef STAN_MATH_FWD_SCAL_META_AD_PROMOTABLE_HPP -#define STAN_MATH_FWD_SCAL_META_AD_PROMOTABLE_HPP - -#include - -namespace stan { -namespace math { - -template -struct fvar; -/** - * Template traits metaprogram to determine if a variable - * of one template type is promotable to the base type of - * a second fvar template type. - * - *

It will declare an enum value equal to - * true if the variable type is promotable to - * the base type of the fvar template type, - * false otherwise. - * - * @tparam T promoted type - */ -template -struct ad_promotable > { - enum { value = ad_promotable::value }; -}; - -} // namespace math -} // namespace stan -#endif diff --git a/stan/math/fwd/scal/meta/is_fvar.hpp b/stan/math/fwd/scal/meta/is_fvar.hpp index b54bbdc918e..5c204a79d15 100644 --- a/stan/math/fwd/scal/meta/is_fvar.hpp +++ b/stan/math/fwd/scal/meta/is_fvar.hpp @@ -3,16 +3,21 @@ #include #include +#include namespace stan { -/** - * Defines a public enum named value and sets it to true(1) - * when instantiated with the stan::math::fvar type. - */ -template -struct is_fvar > { - enum { value = true }; -}; + + namespace internal { + template + struct is_fvar_impl : std::false_type {}; + + template + struct is_fvar_impl> : std::true_type {}; + + } + + template + struct is_fvar>::value>> : std::true_type {}; } // namespace stan #endif diff --git a/stan/math/fwd/scal/meta/partials_type.hpp b/stan/math/fwd/scal/meta/partials_type.hpp index fa92c4d4e07..c45ae150493 100644 --- a/stan/math/fwd/scal/meta/partials_type.hpp +++ b/stan/math/fwd/scal/meta/partials_type.hpp @@ -2,13 +2,15 @@ #define STAN_MATH_FWD_SCAL_META_PARTIALS_TYPE_HPP #include +#include #include +#include namespace stan { template -struct partials_type > { - typedef T type; +struct partials_type>::value>> { + using type = typename std::decay_t::Scalar; }; } // namespace stan diff --git a/stan/math/mix/meta.hpp b/stan/math/mix/meta.hpp index 80f08268664..ccb8239b4df 100644 --- a/stan/math/mix/meta.hpp +++ b/stan/math/mix/meta.hpp @@ -2,8 +2,6 @@ #define STAN_MATH_MIX_META_HPP #include -#include -#include #include #include diff --git a/stan/math/prim/arr/meta/contains_std_vector.hpp b/stan/math/prim/arr/meta/contains_std_vector.hpp deleted file mode 100644 index 75b78bdf9c8..00000000000 --- a/stan/math/prim/arr/meta/contains_std_vector.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef STAN_MATH_PRIM_ARR_META_CONTAINS_STD_VECTOR_HPP -#define STAN_MATH_PRIM_ARR_META_CONTAINS_STD_VECTOR_HPP - -#include -#include -#include - -namespace stan { -/** - * Extends std::true_type when instantiated with at least 1 template - * parameter of type std::vector. - */ -template -struct contains_std_vector, Ts...> : std::true_type {}; - -template -struct contains_std_vector : contains_std_vector {}; - -} // namespace stan -#endif diff --git a/stan/math/prim/arr/meta/index_type.hpp b/stan/math/prim/arr/meta/index_type.hpp index 0dc9cd4bac1..3803c3ae5f2 100644 --- a/stan/math/prim/arr/meta/index_type.hpp +++ b/stan/math/prim/arr/meta/index_type.hpp @@ -1,7 +1,9 @@ #ifndef STAN_MATH_PRIM_ARR_META_INDEX_TYPE_HPP #define STAN_MATH_PRIM_ARR_META_INDEX_TYPE_HPP +#include #include +#include #include namespace stan { @@ -14,11 +16,8 @@ namespace math { * @tparam T type of elements in standard vector. */ template -struct index_type > { - /** - * Typedef for index of standard vectors. - */ - typedef typename std::vector::size_type type; +struct index_type::value>> { + using type = typename std::decay_t::size_type; }; } // namespace math diff --git a/stan/math/prim/arr/meta/is_constant.hpp b/stan/math/prim/arr/meta/is_constant.hpp index 90922408c9d..58b7e5d9e3e 100644 --- a/stan/math/prim/arr/meta/is_constant.hpp +++ b/stan/math/prim/arr/meta/is_constant.hpp @@ -1,21 +1,23 @@ #ifndef STAN_MATH_PRIM_ARR_META_IS_CONSTANT_HPP #define STAN_MATH_PRIM_ARR_META_IS_CONSTANT_HPP + +#include +#include #include +#include #include namespace stan { /** - * Defines a public enum named value and sets it to true + * Defines a static member named value and sets it to true * if the type of the elements in the provided std::vector * is constant, false otherwise. This is used in * the is_constant_all metaprogram. * @tparam type of the elements in the std::vector */ template -struct is_constant > { - enum { value = is_constant::value }; -}; +struct is_constant::value>> : bool_constant::value_type>::value> {}; } // namespace stan #endif diff --git a/stan/math/prim/arr/meta/is_vector.hpp b/stan/math/prim/arr/meta/is_vector.hpp index 599eec52a88..44f7e0f3690 100644 --- a/stan/math/prim/arr/meta/is_vector.hpp +++ b/stan/math/prim/arr/meta/is_vector.hpp @@ -2,22 +2,32 @@ #define STAN_MATH_PRIM_ARR_META_IS_VECTOR_HPP #include +#include #include namespace stan { -// FIXME: use boost::type_traits::remove_all_extents to -// extend to array/ptr types +namespace internal { +/** + * This underlying implimentation is used when none of the type is not an std vectors. + */ template -struct is_vector { - enum { value = is_vector::value }; - typedef T type; -}; +struct is_std_vector_impl : std::false_type {}; + +/** + * This specialization implimentation has a static member named value when the template type is an std vector. + */ +template +struct is_std_vector_impl> : std::true_type {}; + +} + +/** + * Checks if the decayed type of T is a standard vector. + */ template -struct is_vector > { - enum { value = 1 }; - typedef T type; -}; +struct is_std_vector>::value>> : std::true_type {}; + } // namespace stan #endif diff --git a/stan/math/prim/arr/meta/scalar_type.hpp b/stan/math/prim/arr/meta/scalar_type.hpp index 19457d85e1d..b3554192de2 100644 --- a/stan/math/prim/arr/meta/scalar_type.hpp +++ b/stan/math/prim/arr/meta/scalar_type.hpp @@ -1,28 +1,19 @@ #ifndef STAN_MATH_PRIM_ARR_META_SCALAR_TYPE_HPP #define STAN_MATH_PRIM_ARR_META_SCALAR_TYPE_HPP +#include #include +#include #include namespace stan { +/** + * Specialization of scalar_type for vector to recursivly return the inner scalar type. + */ template -struct scalar_type > { - typedef typename scalar_type::type type; +struct scalar_type::value>> { + using type = scalar_type_t::value_type>; }; -template -struct scalar_type > { - typedef typename scalar_type::type type; -}; - -template -struct scalar_type&> { - typedef typename scalar_type::type type; -}; - -template -struct scalar_type&> { - typedef typename scalar_type::type type; -}; } // namespace stan #endif diff --git a/stan/math/prim/arr/meta/value_type.hpp b/stan/math/prim/arr/meta/value_type.hpp index 118047f8877..54e9f89ecb8 100644 --- a/stan/math/prim/arr/meta/value_type.hpp +++ b/stan/math/prim/arr/meta/value_type.hpp @@ -1,6 +1,7 @@ #ifndef STAN_MATH_PRIM_ARR_META_VALUE_TYPE_HPP #define STAN_MATH_PRIM_ARR_META_VALUE_TYPE_HPP +#include #include #include @@ -14,12 +15,8 @@ namespace math { * @tparam T type of elements in standard vector. */ template -struct value_type > { - /** - * Type of value stored in a standard vector with type - * T entries. - */ - typedef T type; +struct value_type::value>> { + using type = typename std::decay_t::value_type; }; } // namespace math diff --git a/stan/math/prim/mat/meta/index_type.hpp b/stan/math/prim/mat/meta/index_type.hpp index 4472485b0a3..583dec0cd10 100644 --- a/stan/math/prim/mat/meta/index_type.hpp +++ b/stan/math/prim/mat/meta/index_type.hpp @@ -1,8 +1,10 @@ #ifndef STAN_MATH_PRIM_MAT_META_INDEX_TYPE_HPP #define STAN_MATH_PRIM_MAT_META_INDEX_TYPE_HPP +#include +#include #include -#include +#include namespace stan { namespace math { @@ -15,9 +17,9 @@ namespace math { * @tparam R number of rows for matrix. * @tparam C number of columns for matrix. */ -template -struct index_type > { - typedef typename Eigen::Matrix::Index type; +template +struct index_type::value>> { + using type = typename std::decay_t::Index; }; } // namespace math diff --git a/stan/math/prim/mat/meta/is_constant.hpp b/stan/math/prim/mat/meta/is_constant.hpp index 8ab00d61f26..52127a3da87 100644 --- a/stan/math/prim/mat/meta/is_constant.hpp +++ b/stan/math/prim/mat/meta/is_constant.hpp @@ -2,7 +2,10 @@ #define STAN_MATH_PRIM_MAT_META_IS_CONSTANT_HPP #include +#include +#include #include +#include namespace stan { /** @@ -15,22 +18,8 @@ namespace stan { * @tparam R number of rows in the Eigen Matrix * @tparam C number of cols in the eigen Matrix */ -template -struct is_constant > { - enum { value = is_constant::value }; -}; - -/** - * Defines a public enum named value and sets it to true - * if the type of the elements in the provided Eigen Block - * is constant, false otherwise. This is used in - * the is_constant_all metaprogram. - * @tparam type of the elements in the Eigen Block - */ template -struct is_constant > { - enum { value = is_constant::value }; -}; +struct is_constant::value>> : bool_constant::Scalar>::value>{}; } // namespace stan #endif diff --git a/stan/math/prim/mat/meta/is_eigen.hpp b/stan/math/prim/mat/meta/is_eigen.hpp new file mode 100644 index 00000000000..6e3405690bd --- /dev/null +++ b/stan/math/prim/mat/meta/is_eigen.hpp @@ -0,0 +1,29 @@ +#ifndef STAN_MATH_PRIM_MAT_META_IS_EIGEN_HPP +#define STAN_MATH_PRIM_MAT_META_IS_EIGEN_HPP + +#include +#include +#include + +namespace stan { + +namespace internal { +/* + * Underlying implimenation to check if a type is derived from EigenBase + */ +template +struct is_eigen_base + : std::integral_constant>, + std::decay_t>::value> {}; +} // namespace internal + +/* + * Checks whether type T is derived from EigenBase. If true this will have a static member function named value with a type of true, else value is false. + */ +template +struct is_eigen::value>> + : std::true_type {}; + +} // namespace stan +#endif diff --git a/stan/math/prim/mat/meta/is_vector.hpp b/stan/math/prim/mat/meta/is_vector.hpp deleted file mode 100644 index cd848789547..00000000000 --- a/stan/math/prim/mat/meta/is_vector.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef STAN_MATH_PRIM_MAT_META_IS_VECTOR_HPP -#define STAN_MATH_PRIM_MAT_META_IS_VECTOR_HPP - -#include -#include - -namespace stan { - -// FIXME: use boost::type_traits::remove_all_extents to -// extend to array/ptr types - -template -struct is_vector > { - enum { value = 1 }; - typedef T type; -}; -template -struct is_vector > { - enum { value = 1 }; - typedef T type; -}; -template -struct is_vector > { - enum { value = 1 }; - typedef T type; -}; -} // namespace stan -#endif diff --git a/stan/math/prim/mat/meta/is_vector_like.hpp b/stan/math/prim/mat/meta/is_vector_like.hpp deleted file mode 100644 index 2ec77491741..00000000000 --- a/stan/math/prim/mat/meta/is_vector_like.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef STAN_MATH_PRIM_MAT_META_IS_VECTOR_LIKE_HPP -#define STAN_MATH_PRIM_MAT_META_IS_VECTOR_LIKE_HPP - -#include -#include - -namespace stan { - -/** - * Template metaprogram indicates whether a type is vector_like. - * - * A type is vector_like if an instance can be accessed like a - * vector, i.e. square brackets. - * - * Access is_vector_like::value for the result. - * - * This metaprogram removes the const qualifier. - * - * @tparam T Type to test - */ -template -struct is_vector_like > { - enum { value = true }; -}; - -/** - * Template metaprogram indicates whether a type is vector_like. - * - * A type is vector_like if an instance can be accessed like a - * vector, i.e. square brackets. - * - * Access is_vector_like::value for the result. - * - * This metaprogram removes the const qualifier. - * - * @tparam T Type to test - */ -template -struct is_vector_like > { - enum { value = true }; -}; -} // namespace stan -#endif diff --git a/stan/math/prim/mat/meta/operands_and_partials.hpp b/stan/math/prim/mat/meta/operands_and_partials.hpp index 6aaca072513..88c7cd0d3e3 100644 --- a/stan/math/prim/mat/meta/operands_and_partials.hpp +++ b/stan/math/prim/mat/meta/operands_and_partials.hpp @@ -1,11 +1,10 @@ #ifndef STAN_MATH_PRIM_MAT_META_OPERANDS_AND_PARTIALS_HPP #define STAN_MATH_PRIM_MAT_META_OPERANDS_AND_PARTIALS_HPP +#include #include #include #include - -#include #include namespace stan { diff --git a/stan/math/prim/mat/meta/scalar_type.hpp b/stan/math/prim/mat/meta/scalar_type.hpp index 3af731a7344..307d6e8fbaf 100644 --- a/stan/math/prim/mat/meta/scalar_type.hpp +++ b/stan/math/prim/mat/meta/scalar_type.hpp @@ -2,8 +2,9 @@ #define STAN_MATH_PRIM_MAT_META_SCALAR_TYPE_HPP #include +#include #include - +#include namespace stan { /** * Template metaprogram defining the base scalar type of @@ -13,59 +14,9 @@ namespace stan { * @tparam R number of rows for matrix. * @tparam C number of columns for matrix. */ -template -struct scalar_type > { - typedef typename scalar_type::type type; -}; - -/** - * Template metaprogram defining the base scalar type of - * values stored in a const Eigen matrix. - * - * @tparam T type of matrix. - * @tparam R number of rows for matrix. - * @tparam C number of columns for matrix. - */ -template -struct scalar_type > { - typedef typename scalar_type::type type; -}; - -/** - * Template metaprogram defining the base scalar type of - * values stored in a referenced Eigen matrix. - * - * @tparam T type of matrix. - * @tparam R number of rows for matrix. - * @tparam C number of columns for matrix. - */ -template -struct scalar_type&> { - typedef typename scalar_type::type type; -}; - -/** - * Template metaprogram defining the base scalar type of - * values stored in a referenced const Eigen matrix. - * - * @tparam T type of matrix. - * @tparam R number of rows for matrix. - * @tparam C number of columns for matrix. - */ -template -struct scalar_type&> { - typedef typename scalar_type::type type; -}; - -/** - * Template metaprogram defining the base scalar type of - * values stored in an Eigen Block. - * - * @tparam T type of block. - */ template -struct scalar_type > { - typedef typename scalar_type::type type; +struct scalar_type::value>> { + using type = scalar_type_t::Scalar>; }; } // namespace stan #endif diff --git a/stan/math/prim/mat/meta/value_type.hpp b/stan/math/prim/mat/meta/value_type.hpp index 076f89e421e..1476b62d5ac 100644 --- a/stan/math/prim/mat/meta/value_type.hpp +++ b/stan/math/prim/mat/meta/value_type.hpp @@ -1,8 +1,10 @@ #ifndef STAN_MATH_PRIM_MAT_META_VALUE_TYPE_HPP #define STAN_MATH_PRIM_MAT_META_VALUE_TYPE_HPP +#include +#include #include -#include +#include namespace stan { namespace math { @@ -15,9 +17,9 @@ namespace math { * @tparam R number of rows for matrix. * @tparam C number of columns for matrix. */ -template -struct value_type > { - typedef T type; +template +struct value_type::value>> { + using type = typename std::decay_t::Scalar; }; } // namespace math diff --git a/stan/math/prim/mat/prob/bernoulli_logit_glm_rng.hpp b/stan/math/prim/mat/prob/bernoulli_logit_glm_rng.hpp index ce981ea9a44..1800d8d96e8 100644 --- a/stan/math/prim/mat/prob/bernoulli_logit_glm_rng.hpp +++ b/stan/math/prim/mat/prob/bernoulli_logit_glm_rng.hpp @@ -46,27 +46,27 @@ inline typename VectorBuilder::type bernoulli_logit_glm_rng( static const char *function = "bernoulli_logit_glm_rng"; - const size_t N = x.col(0).size(); - const size_t M = x.row(0).size(); + const size_t N = x.row(0).size(); + const size_t M = x.col(0).size(); check_finite(function, "Matrix of independent variables", x); check_finite(function, "Weight vector", beta); check_finite(function, "Intercept", alpha); - check_consistent_size(function, "Weight vector", beta, M); - check_consistent_size(function, "Vector of intercepts", alpha, N); + check_consistent_size(function, "Weight vector", beta, N); + check_consistent_size(function, "Vector of intercepts", alpha, M); scalar_seq_view beta_vec(beta); - Eigen::VectorXd beta_vector(M); - for (int i = 0; i < M; ++i) + Eigen::VectorXd beta_vector(N); + for (int i = 0; i < N; ++i) beta_vector[i] = beta_vec[i]; Eigen::VectorXd x_beta = x * beta_vector; scalar_seq_view alpha_vec(alpha); - VectorBuilder output(N); + VectorBuilder output(M); - for (size_t n = 0; n < N; ++n) { + for (size_t n = 0; n < M; ++n) { double theta_n = alpha_vec[n] + x_beta(n); variate_generator> bernoulli_rng( rng, bernoulli_distribution<>(inv_logit(theta_n))); diff --git a/stan/math/prim/meta.hpp b/stan/math/prim/meta.hpp index f962eaca700..7680fe98f71 100644 --- a/stan/math/prim/meta.hpp +++ b/stan/math/prim/meta.hpp @@ -13,9 +13,8 @@ #include #include #include +#include #include -#include -#include #include #include #include @@ -25,7 +24,6 @@ #include #include -#include #include #include #include @@ -35,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include diff --git a/stan/math/prim/scal/meta/VectorBuilder.hpp b/stan/math/prim/scal/meta/VectorBuilder.hpp index 8dde92059cd..5f502a04a17 100644 --- a/stan/math/prim/scal/meta/VectorBuilder.hpp +++ b/stan/math/prim/scal/meta/VectorBuilder.hpp @@ -22,13 +22,10 @@ namespace stan { * * These values are mutable. */ -template +template class VectorBuilder { private: - typedef VectorBuilderHelper::value> + typedef VectorBuilderHelper::value> helper; public: diff --git a/stan/math/prim/scal/meta/ad_promotable.hpp b/stan/math/prim/scal/meta/ad_promotable.hpp index 03240f83d1b..872a93fed38 100644 --- a/stan/math/prim/scal/meta/ad_promotable.hpp +++ b/stan/math/prim/scal/meta/ad_promotable.hpp @@ -1,150 +1,23 @@ #ifndef STAN_MATH_PRIM_SCAL_META_AD_PROMOTABLE_HPP #define STAN_MATH_PRIM_SCAL_META_AD_PROMOTABLE_HPP +#include #include namespace stan { namespace math { /** - * Template traits metaprogram to determine if a variable of one - * template type can be promoted to a second target template - * type. All variables are promotable to themselves, and all - * primitive arithmetic types are promotable to double. + * If the type From can be converted to To using implicit conversions, or + * both From and To are possibly cv-qualified void), + * provides the member constant value equal to true. * - *

It will declare an enum value equal to - * false. - * - * @tparam V promoted type - * @tparam T target type - */ -template -struct ad_promotable { - enum { value = false }; -}; - -/** - * Any type may be promoted to itself. - * - * @tparam T promoted and target type - */ -template -struct ad_promotable< - typename std::enable_if::value, T>::type, T> { - enum { value = true }; -}; - -/** - * A bool may be promoted to a double. - */ -template <> -struct ad_promotable { - enum { value = true }; -}; - -/** - * A char may be promoted to a double. - */ -template <> -struct ad_promotable { - enum { value = true }; -}; - -/** - * An unsigned char may be promoted to a double. - */ -template <> -struct ad_promotable { - enum { value = true }; -}; - -/** - * A short may be promoted to a double. - */ -template <> -struct ad_promotable { // NOLINT(runtime/int) - enum { value = true }; -}; - -/** - * An unsigned short may be promoted to a double. - */ -template <> -struct ad_promotable { // NOLINT(runtime/int) - enum { value = true }; -}; - -/** - * An int may be promoted to a double. + * @tparam From promoted type + * @tparam To target type */ -template <> -struct ad_promotable { - enum { value = true }; -}; +template +struct ad_promotable : bool_constant, std::decay_t>::value> {}; -/** - * An unsigned int may be promoted to a double. - */ -template <> -struct ad_promotable { - enum { value = true }; -}; - -/** - * A long may be promoted to a double. - */ -template <> -struct ad_promotable { // NOLINT(runtime/int) - enum { value = true }; -}; - -/** - * An unsigned long may be promoted to a double. - */ -template <> -struct ad_promotable { // NOLINT(runtime/int) - enum { value = true }; -}; - -/** - * A long long may be promoted to a double. - */ -template <> -struct ad_promotable { // NOLINT(runtime/int) - enum { value = true }; -}; - -/** - * An unsigned long long may be promoted to a double. - */ -template <> -struct ad_promotable { // NOLINT(runtime/int) - enum { value = true }; -}; - -/** - * A float may be promoted to a double. - */ -template <> -struct ad_promotable { - enum { value = true }; -}; - -/** - * A double may be promoted to a double. - */ -template <> -struct ad_promotable { - enum { value = true }; -}; - -/** - * A long double may be promoted to a double. - */ -template <> -struct ad_promotable { - enum { value = true }; -}; } // namespace math } // namespace stan diff --git a/stan/math/prim/scal/meta/bool_constant.hpp b/stan/math/prim/scal/meta/bool_constant.hpp new file mode 100644 index 00000000000..cd74b28a6ee --- /dev/null +++ b/stan/math/prim/scal/meta/bool_constant.hpp @@ -0,0 +1,15 @@ +#ifndef STAN_MATH_PRIM_SCAL_META_BOOL_CONSTANT_HPP +#define STAN_MATH_PRIM_SCAL_META_BOOL_CONSTANT_HPP + +#include + +namespace stan { +/** + * Alias for structs used for wraps a static constant of bool. + * @tparam B On true, inherits std::true_type, false is std::false_type + */ +template +using bool_constant = std::integral_constant; +} + +#endif diff --git a/stan/math/prim/scal/meta/child_type.hpp b/stan/math/prim/scal/meta/child_type.hpp index 9788cfb1cad..a0631048172 100644 --- a/stan/math/prim/scal/meta/child_type.hpp +++ b/stan/math/prim/scal/meta/child_type.hpp @@ -1,6 +1,9 @@ #ifndef STAN_MATH_PRIM_SCAL_META_CHILD_TYPE_HPP #define STAN_MATH_PRIM_SCAL_META_CHILD_TYPE_HPP +#include + + namespace stan { namespace math { @@ -13,10 +16,9 @@ namespace math { * * @tparam T type of container. */ - template struct child_type { - typedef double type; + using type = double; }; /** @@ -28,10 +30,9 @@ struct child_type { * @tparam T_struct type of parent. * @tparam T_child type of child type. */ - template