autoppl  v0.8
A C++ template library for probabilistic programming
traits.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <fastad_bits/util/type_traits.hpp>
11 
12 namespace ppl {
13 
14 // forward declarations
15 template <class ValueType
16  , class ShapeType
17  , class ConstraintType>
18 struct ParamView;
19 
20 template <class ValueType
21  , class ShapeType>
22 struct TParamView;
23 
24 template <class ValueType
25  , class ShapeType>
26 struct DataView;
27 
28 namespace expr {
29 namespace var {
30 
31 template <class ValueType
32  , class ShapeType>
33 struct Constant;
34 
35 } // namespace var
36 
37 namespace prog {
38 
39 template <class TupExprType, class>
40 struct ProgramNode;
41 
42 } // namespace prog
43 } // namespace expr
44 
45 namespace util {
46 namespace details {
47 
51 template <class T, class = void>
53 {};
54 
55 // Convert from param to param viewer
56 template <class T>
58  std::enable_if_t<
59  util::is_param_v<std::decay_t<T>>
60  > >
61 {
62 private:
63  using raw_t = std::decay_t<T>;
64  using value_t = typename
66  using shape_t = typename
68  using constraint_t = typename
70 public:
72 };
73 
74 // Convert from tparam to tparam viewer
75 template <class T>
77  std::enable_if_t<
78  util::is_tparam_v<std::decay_t<T>>
79  > >
80 {
81 private:
82  using raw_t = std::decay_t<T>;
83  using value_t = typename
85  using shape_t = typename
87 public:
89 };
90 
91 // Convert from data to data viewer
92 template <class T>
94  std::enable_if_t<
95  util::is_data_v<std::decay_t<T>>
96  > >
97 {
98 private:
99  using raw_t = std::decay_t<T>;
100  using value_t = typename
102  using shape_t = typename
104 public:
106 };
107 
108 // Convert arithmetic types to Constants
109 template <class T>
111  std::enable_if_t<std::is_arithmetic_v<std::decay_t<T>>
112  > >
113 {
115 };
116 
117 // Convert Eigen types to Constants
118 template <class T>
120  std::enable_if_t<ad::util::is_eigen_v<std::decay_t<T>>
121  > >
122 {
123 private:
124  using raw_t = std::decay_t<T>;
125  using value_t = typename T::Scalar;
126  using shape_t = std::conditional_t<
127  T::ColsAtCompileTime == 1,
128  ppl::vec, ppl::mat>;
129 public:
131 };
132 
133 // Convert variable expressions (not variables) into itself (no change)
134 template <class T>
136  std::enable_if_t<
137  util::is_var_expr_v<std::decay_t<T>> &&
138  !util::is_var_v<std::decay_t<T>>
139  > >
140 {
141  using type = T;
142 };
143 
144 } // namespace details
145 
146 template <class T>
149 
153 namespace details {
154 
155 template <class T, class = void>
157 
158 // Convert T to ProgramNode if T is model expression
159 template <class T>
161  std::enable_if_t<
162  util::is_model_expr_v<std::decay_t<T>>
163  > >
164 {
166 };
167 
168 // Convert T to itself if it already is a program expression
169 template <class T>
171  std::enable_if_t<
172  util::is_program_expr_v<std::decay_t<T>>
173  > >
174 {
175  using type = T;
176 };
177 
178 } // namespace details
179 
180 template <class T>
183 
189 template <class T>
190 inline constexpr bool is_valid_dist_param_v =
191  std::is_arithmetic_v<std::decay_t<T>> ||
192  ad::util::is_eigen_v<std::decay_t<T>> ||
193  util::is_var_v<std::decay_t<T>> ||
194  util::is_var_expr_v<std::decay_t<T>>
195  ;
196 
201 template <class T1, class T2>
202 inline constexpr bool is_not_both_arithmetic_v =
203  !(std::is_arithmetic_v<std::decay_t<T1>> &&
204  std::is_arithmetic_v<std::decay_t<T2>>)
205  ;
206 
207 template <class T>
208 inline constexpr bool is_valid_op_param_v =
209  std::is_arithmetic_v<std::decay_t<T>> ||
210  util::is_var_v<std::decay_t<T>> ||
211  util::is_var_expr_v<std::decay_t<T>>
212  ;
213 
214 } // namespace util
215 } // namespace ppl
var_traits.hpp
ppl::util::param_traits::constraint_t
typename VarType::constraint_t constraint_t
Definition: var_traits.hpp:55
type_traits.hpp
var_expr_traits.hpp
shape_traits.hpp
ppl::expr::prog::ProgramNode
Definition: program.hpp:39
model_expr_traits.hpp
ppl::vec
ad::vec vec
Definition: shape_traits.hpp:17
dist_expr_traits.hpp
ppl::util::is_valid_dist_param_v
constexpr bool is_valid_dist_param_v
Definition: traits.hpp:190
ppl::util::is_not_both_arithmetic_v
constexpr bool is_not_both_arithmetic_v
Definition: traits.hpp:202
ppl::util::details::convert_to_program
Definition: traits.hpp:156
ppl::expr::var::Constant
Definition: constant.hpp:15
ppl::scl
ad::scl scl
Definition: shape_traits.hpp:16
ppl::TParamView
Definition: tparam.hpp:122
ppl::util::details::convert_to_param
Definition: traits.hpp:53
ppl::util::var_expr_traits< VarType >::value_t
typename VarExprType::value_t value_t
Definition: var_expr_traits.hpp:29
ppl::util::details::convert_to_program< T, std::enable_if_t< util::is_program_expr_v< std::decay_t< T > > > >::type
T type
Definition: traits.hpp:175
ppl::util::shape_traits
ad::util::shape_traits< T > shape_traits
Definition: shape_traits.hpp:23
ppl::DataView
Definition: data.hpp:29
ppl
Definition: bounded.hpp:11
ppl::mat
ad::mat mat
Definition: shape_traits.hpp:18
ppl::util::is_valid_op_param_v
constexpr bool is_valid_op_param_v
Definition: traits.hpp:208
ppl::ParamView
Definition: param.hpp:47
ppl::util::convert_to_param_t
typename details::convert_to_param< T >::type convert_to_param_t
Definition: traits.hpp:148
ppl::util::details::convert_to_param< T, std::enable_if_t< util::is_var_expr_v< std::decay_t< T > > &&!util::is_var_v< std::decay_t< T > > > >::type
T type
Definition: traits.hpp:141
concept.hpp
program_expr_traits.hpp
ppl::util::convert_to_program_t
typename details::convert_to_program< T >::type convert_to_program_t
Definition: traits.hpp:182