Automatic Differentiation
 
Loading...
Searching...
No Matches
promote_scalar_type.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_META_PROMOTE_SCALAR_TYPE_HPP
2#define STAN_MATH_PRIM_META_PROMOTE_SCALAR_TYPE_HPP
3
9#include <vector>
10
11namespace stan {
12namespace math {
13
21template <typename T, typename S, typename Enable = void>
26 using type = T;
27};
28
37template <typename T, typename S>
38struct promote_scalar_type<T, std::vector<S>> {
42 using type = std::vector<typename promote_scalar_type<T, S>::type>;
43};
44
51template <typename T, typename S>
53 T, S, require_all_t<is_var<T>, is_var<S>, is_eigen<value_type_t<S>>>> {
57 using type = std::decay_t<S>;
58};
59
66template <typename T, typename S>
68 require_all_t<std::is_arithmetic<T>, is_var<S>,
69 is_eigen<value_type_t<S>>>> {
74};
75
84template <typename T, typename S>
89 using type = typename std::conditional<
90 std::is_same<typename Eigen::internal::traits<std::decay_t<S>>::XprKind,
91 Eigen::MatrixXpr>::value,
92 Eigen::Matrix<typename promote_scalar_type<T, typename S::Scalar>::type,
93 S::RowsAtCompileTime, S::ColsAtCompileTime>,
94 Eigen::Array<typename promote_scalar_type<T, typename S::Scalar>::type,
95 S::RowsAtCompileTime, S::ColsAtCompileTime>>::type;
96};
97
98template <typename T, typename S>
103 using type = Eigen::SparseMatrix<
105 typename S::StorageIndex>;
106};
107
108template <typename... PromotionScalars, typename... UnPromotedTypes>
109struct promote_scalar_type<std::tuple<PromotionScalars...>,
110 std::tuple<UnPromotedTypes...>> {
111 using type = std::tuple<typename promote_scalar_type<
112 std::decay_t<PromotionScalars>, std::decay_t<UnPromotedTypes>>::type...>;
113};
114
115template <typename T, typename S>
117 typename promote_scalar_type<std::decay_t<T>, std::decay_t<S>>::type;
118
119} // namespace math
120} // namespace stan
121#endif
require_t< is_eigen_dense_base< std::decay_t< T > > > require_eigen_dense_base_t
Require type satisfies is_eigen_dense_base.
require_t< is_eigen_sparse_base< std::decay_t< T > > > require_eigen_sparse_base_t
Require type satisfies is_eigen_sparse_base.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
typename promote_scalar_type< std::decay_t< T >, std::decay_t< S > >::type promote_scalar_t
std::enable_if_t< math::conjunction< Checks... >::value > require_all_t
If all conditions are true, template is enabled Returns a type void if all conditions are true and ot...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
STL namespace.
Check if type derives from EigenBase
Definition is_eigen.hpp:21
Defines a static member named value which is defined to be false as the primitive scalar types cannot...
Definition is_var.hpp:14
typename std::conditional< std::is_same< typename Eigen::internal::traits< std::decay_t< S > >::XprKind, Eigen::MatrixXpr >::value, Eigen::Matrix< typename promote_scalar_type< T, typename S::Scalar >::type, S::RowsAtCompileTime, S::ColsAtCompileTime >, Eigen::Array< typename promote_scalar_type< T, typename S::Scalar >::type, S::RowsAtCompileTime, S::ColsAtCompileTime > >::type type
The promoted type.
Eigen::SparseMatrix< typename promote_scalar_type< T, typename S::Scalar >::type, S::Options, typename S::StorageIndex > type
The promoted type.
std::vector< typename promote_scalar_type< T, S >::type > type
The promoted type.
std::tuple< typename promote_scalar_type< std::decay_t< PromotionScalars >, std::decay_t< UnPromotedTypes > >::type... > type
Template metaprogram to calculate a type for converting a convertible type.