Automatic Differentiation
 
Loading...
Searching...
No Matches
partials_propagator.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_META_PARTIALS_PROPOGATOR_HPP
2#define STAN_MATH_REV_META_PARTIALS_PROPOGATOR_HPP
3
10#include <vector>
11#include <tuple>
12
13namespace stan {
14namespace math {
15
16namespace internal {
17
49template <typename ReturnType, typename... Ops>
50class partials_propagator<ReturnType, require_var_t<ReturnType>, Ops...> {
51 public:
52 std::tuple<
55
56 template <typename... Types>
57 explicit partials_propagator(Types&&... ops)
58 : edges_(
59 internal::ops_partials_edge<double, plain_type_t<std::decay_t<Ops>>>(
60 std::forward<Types>(ops))...) {}
61
75 inline var build(double value) {
76 var ret(value);
78 [ret](auto&& edge) mutable {
80 [operand = edge.operand(), partial = edge.partial(),
81 ret]() mutable { update_adjoints(operand, partial, ret); });
82 },
83 edges_);
84 return ret;
85 }
86};
87} // namespace internal
88} // namespace math
89} // namespace stan
90#endif
An edge holds both the operands and its associated partial derivatives.
std::tuple< internal::ops_partials_edge< double, plain_type_t< std::decay_t< Ops > > >... > edges_
var build(double value)
Build the node to be stored on the autodiff graph.
require_t< is_var< std::decay_t< T > > > require_var_t
Require type satisfies is_var.
Definition is_var.hpp:24
constexpr auto for_each(F &&f, T &&t)
Apply a function to each element of a tuple.
Definition for_each.hpp:66
constexpr auto & edge(internal::partials_propagator< Types... > &x) noexcept
Access the edge of an partials_propagator
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
STL namespace.