autoppl
v0.8
A C++ template library for probabilistic programming
|
Go to the documentation of this file.
2 #include <fastad_bits/reverse/core/unary.hpp>
19 template <
class UnaryOp
25 using expr_t = VarExprType;
27 static_assert(util::is_var_expr_v<expr_t>);
32 static constexpr
bool has_param = expr_t::has_param;
42 return eval_helper(expr_.get());
46 return eval_helper(expr_.eval());
49 constexpr
size_t size()
const {
return expr_.size(); }
50 constexpr
size_t rows()
const {
return expr_.rows(); }
51 constexpr
size_t cols()
const {
return expr_.cols(); }
53 template <
class PtrPackType>
54 auto ad(
const PtrPackType& pack)
const
56 return UnaryOp::fmap(expr_.ad(pack));
59 template <
class PtrPackType>
60 void bind(
const PtrPackType& pack)
62 if constexpr (expr_t::has_param) {
68 expr_.activate_refcnt();
74 auto eval_helper(
const T& x)
const {
75 if constexpr (util::is_scl_v<expr_t>) {
76 return UnaryOp::fmap(x);
78 return UnaryOp::fmap(x.array()).matrix();
88 #define PPL_UNARY_FUNC(name, strct) \
89 template <class ExprType \
90 , class = std::enable_if_t< \
91 util::is_valid_op_param_v<ExprType> && \
92 !std::is_arithmetic_v<ExprType> \
94 constexpr inline auto name(const ExprType& expr) \
96 using expr_t = util::convert_to_param_t<ExprType>; \
97 expr_t wrap_expr = expr; \
98 using unary_t = expr::var::UnaryNode<ad::core::strct, expr_t>; \
99 return unary_t(wrap_expr); \
UnaryNode(const expr_t &expr)
Definition: unary.hpp:34
#define PPL_UNARY_FUNC(name, strct)
Definition: unary.hpp:88
void bind(const PtrPackType &pack)
Definition: unary.hpp:60
auto ad(const PtrPackType &pack) const
Definition: unary.hpp:54
typename VarExprType::value_t value_t
Definition: var_expr_traits.hpp:29
typename util::shape_traits< expr_t >::shape_t shape_t
Definition: unary.hpp:31
ad::util::shape_traits< T > shape_traits
Definition: shape_traits.hpp:23
typename util::var_expr_traits< expr_t >::value_t value_t
Definition: unary.hpp:30
constexpr size_t cols() const
Definition: unary.hpp:51
static constexpr bool has_param
Definition: unary.hpp:32
void traverse(Func &&) const
Definition: unary.hpp:39
Definition: bounded.hpp:11
Definition: var_expr_traits.hpp:20
auto get() const
Definition: unary.hpp:41
auto eval()
Definition: unary.hpp:45
constexpr size_t rows() const
Definition: unary.hpp:50
constexpr size_t size() const
Definition: unary.hpp:49
void activate_refcnt() const
Definition: unary.hpp:67