autoppl  v0.8
A C++ template library for probabilistic programming
shape_traits.hpp
Go to the documentation of this file.
1 #pragma once
3 #include <fastad_bits/util/shape_traits.hpp>
4 #if __cplusplus <= 201703L
6 #else
7 #include <concepts>
8 #endif
9 #include <cstddef>
10 
11 namespace ppl {
12 
16 using scl = ad::scl;
17 using vec = ad::vec;
18 using mat = ad::mat;
19 
20 namespace util {
21 
22 template <class T>
23 using shape_traits = ad::util::shape_traits<T>;
24 
25 #if __cplusplus <= 201703L
26 
27 template <class T>
28 inline constexpr bool is_scl_v = ad::util::is_scl_v<T>;
29 
30 template <class T>
31 inline constexpr bool is_vec_v = ad::util::is_vec_v<T>;
32 
33 template <class T>
34 inline constexpr bool is_mat_v = ad::util::is_mat_v<T>;
35 
36 template <class T>
37 inline constexpr bool is_shape_v =
38  is_scl_v<T> ||
39  is_vec_v<T> ||
40  is_mat_v<T>
41  ;
42 
43 #else
44 
45 template <class T>
46 concept scl_c =
47  requires(const T cx) {
48  typename T::shape_t;
49  { cx.size() } -> std::same_as<size_t>;
50  } &&
51  std::same_as<typename T::shape_t, ppl::scl>
52  ;
53 
54 template <class T>
55 concept vec_c =
56  requires(const T cx) {
57  typename T::shape_t;
58  { cx.size() } -> std::same_as<size_t>;
59  } &&
60  std::same_as<typename T::shape_t, ppl::vec>
61  ;
62 
63 template <class T>
64 concept mat_c =
65  requires(const T cx) {
66  typename T::shape_t;
67  { cx.size() } -> std::same_as<size_t>;
68  } &&
69  std::same_as<typename T::shape_t, ppl::mat>
70  ;
71 
72 template <class T>
73 concept shape_c =
74  scl_c<T> ||
75  vec_c<T> ||
76  mat_c<T>
77  ;
78 
79 template <class T>
80 concept is_scl_v = scl_c<T>;
81 
82 template <class T>
83 concept is_vec_v = vec_c<T>;
84 
85 template <class T>
86 concept is_mat_v = mat_c<T>;
87 
88 template <class T>
89 concept is_shape_v = shape_c<T>;
90 
91 #endif
92 
94 // Useful tools to manage shapes
96 
100 template <class T>
101 inline constexpr bool is_shape_tag_v =
102  std::is_same_v<T, ppl::scl> ||
103  std::is_same_v<T, ppl::vec> ||
104  std::is_same_v<T, ppl::mat>
105  ;
106 
110 namespace details {
111 
112 template <class V, class T>
113 struct var;
114 
115 template <class V>
116 struct var<V, scl> { using type = V; };
117 
118 template <class V>
119 struct var<V, vec>
120 {
121  using type = Eigen::Map<Eigen::Matrix<V, Eigen::Dynamic, 1>>;
122 };
123 
124 template <class V>
125 struct var<V, mat>
126 {
127  using type = Eigen::Map<Eigen::Matrix<V, Eigen::Dynamic, Eigen::Dynamic>>;
128 };
129 
130 } // namespace details
131 template <class V, class T>
133 
134 } // namespace util
135 } // namespace ppl
type_traits.hpp
ppl::util::details::var< V, mat >::type
Eigen::Map< Eigen::Matrix< V, Eigen::Dynamic, Eigen::Dynamic > > type
Definition: shape_traits.hpp:127
ppl::vec
ad::vec vec
Definition: shape_traits.hpp:17
ppl::util::is_vec_v
constexpr bool is_vec_v
Definition: shape_traits.hpp:31
ppl::util::details::var< V, scl >::type
V type
Definition: shape_traits.hpp:116
ppl::scl
ad::scl scl
Definition: shape_traits.hpp:16
ppl::util::is_scl_v
constexpr bool is_scl_v
Definition: shape_traits.hpp:28
ppl::util::var_t
typename details::var< V, T >::type var_t
Definition: shape_traits.hpp:132
ppl::util::is_mat_v
constexpr bool is_mat_v
Definition: shape_traits.hpp:34
ppl::util::is_shape_tag_v
constexpr bool is_shape_tag_v
Definition: shape_traits.hpp:101
ppl::util::shape_traits
ad::util::shape_traits< T > shape_traits
Definition: shape_traits.hpp:23
ppl::util::is_shape_v
constexpr bool is_shape_v
Definition: shape_traits.hpp:37
ppl::util::details::var
Definition: shape_traits.hpp:113
ppl
Definition: bounded.hpp:11
ppl::mat
ad::mat mat
Definition: shape_traits.hpp:18
concept.hpp
ppl::util::details::var< V, vec >::type
Eigen::Map< Eigen::Matrix< V, Eigen::Dynamic, 1 > > type
Definition: shape_traits.hpp:121