Automatic Differentiation
 
Loading...
Searching...
No Matches
callback_vari.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_CALLBACK_VARI_HPP
2#define STAN_MATH_REV_CORE_CALLBACK_VARI_HPP
3
5#include <utility>
6
7namespace stan {
8namespace math {
9namespace internal {
10
11template <typename T, typename F>
12struct callback_vari : public vari_value<T> {
14
15 template <typename S,
17 explicit callback_vari(S&& value, F&& rev_functor)
18 : vari_value<T>(std::move(value)),
19 rev_functor_(std::forward<F>(rev_functor)) {}
20
21 inline void chain() final { rev_functor_(*this); }
22};
23
24} // namespace internal
25
40template <typename T, typename F>
42 F&& functor) {
44 std::move(value), std::forward<F>(functor));
45}
46
60template <typename T, typename F>
63 make_callback_vari(std::move(value), std::forward<F>(functor)));
64}
65
66} // namespace math
67} // namespace stan
68
69#endif
require_t< std::is_same< std::decay_t< T >, std::decay_t< S > > > require_same_t
Require types T and S satisfies std::is_same.
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
internal::callback_vari< plain_type_t< T >, F > * make_callback_vari(T &&value, F &&functor)
Creates a new vari with given value and a callback that implements the reverse pass (chain).
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.
callback_vari(S &&value, F &&rev_functor)