autoppl
v0.8
A C++ template library for probabilistic programming
|
Go to the documentation of this file.
2 #include <fastad_bits/reverse/core/for_each.hpp>
16 template <
class VecExprType>
21 using vec_expr_t = VecExprType;
22 using elt_t = std::decay_t<typename VecExprType::value_type>;
24 static_assert(util::is_var_expr_v<elt_t>);
39 for (
auto& expr: vec_expr_) expr.traverse(f);
45 for (
const auto& expr: vec_expr_) expr.traverse(f);
49 assert(!vec_expr_.empty());
50 return vec_expr_.back().get();
54 for (
auto& expr : vec_expr_) expr.eval();
58 constexpr
size_t size()
const {
return vec_expr_.empty() ? 0 : vec_expr_[0].size(); }
59 constexpr
size_t rows()
const {
return vec_expr_.empty() ? 0 : vec_expr_[0].rows(); }
60 constexpr
size_t cols()
const {
return vec_expr_.empty() ? 0 : vec_expr_[0].cols(); }
62 template <
class PtrPackType>
63 auto ad(
const PtrPackType& pack)
const
67 [&](
const auto& expr) {
72 template <
class PtrPackType>
73 void bind(
const PtrPackType& pack)
75 if constexpr (elt_t::has_param) {
76 for (
auto& expr : vec_expr_) expr.bind(pack);
81 for (
const auto& expr : vec_expr_) expr.activate_refcnt();
97 using iter_elt_t = std::decay_t<typename std::iterator_traits<Iter>::value_type>;
98 using ret_t = std::invoke_result_t<F, iter_elt_t>;
100 std::vector<expr_t> exprs;
101 exprs.reserve(std::distance(begin, end));
103 std::for_each(begin, end, [&](
auto&& x) { exprs.emplace_back(f(x)); });
static constexpr bool has_param
Definition: for_each.hpp:29
Definition: var_expr_traits.hpp:28
ForEachNode(const vec_expr_t &vec_expr)
Definition: for_each.hpp:32
constexpr auto for_each(Iter begin, Iter end, F f)
Definition: for_each.hpp:93
Definition: for_each.hpp:19
auto ad(const PtrPackType &pack) const
Definition: for_each.hpp:63
void traverse(Func &&f) const
Definition: for_each.hpp:43
auto eval()
Definition: for_each.hpp:53
auto get() const
Definition: for_each.hpp:48
typename VarExprType::value_t value_t
Definition: var_expr_traits.hpp:29
constexpr size_t rows() const
Definition: for_each.hpp:59
typename util::var_expr_traits< elt_t >::value_t value_t
Definition: for_each.hpp:27
void activate_refcnt() const
Definition: for_each.hpp:80
ad::util::shape_traits< T > shape_traits
Definition: shape_traits.hpp:23
Definition: bounded.hpp:11
Definition: var_expr_traits.hpp:20
typename util::shape_traits< elt_t >::shape_t shape_t
Definition: for_each.hpp:28
typename details::convert_to_param< T >::type convert_to_param_t
Definition: traits.hpp:148
constexpr size_t size() const
Definition: for_each.hpp:58
constexpr size_t cols() const
Definition: for_each.hpp:60
void bind(const PtrPackType &pack)
Definition: for_each.hpp:73
void traverse(Func &&f)
Definition: for_each.hpp:37