Xped
Loading...
Searching...
No Matches
reverse_pass_callback_alloc.hpp
Go to the documentation of this file.
1#ifndef XPED_REVERSE_PASS_CALLBACK_ALLOC_HPP_
2#define XPED_REVERSE_PASS_CALLBACK_ALLOC_HPP_
3
4#include <stan/math/rev/core/chainable_alloc.hpp>
5#include <stan/math/rev/core/vari.hpp>
6
7namespace Xped {
8namespace internal {
9
10template <typename F>
11struct reverse_pass_callback_alloc_vari : public stan::math::vari_base, public stan::math::chainable_alloc
12{
14
15 explicit reverse_pass_callback_alloc_vari(F&& rev_functor)
16 : rev_functor_(std::forward<F>(rev_functor))
17 {
18 stan::math::ChainableStack::instance_->var_stack_.push_back(this);
19 }
20
21 inline void chain() final { rev_functor_(); }
22 inline void set_zero_adjoint() final {}
23 inline void init_dependent() {}
24};
25
26} // namespace internal
27
39template <typename F>
40inline void reverse_pass_callback_alloc(F&& functor)
41{
42 new internal::reverse_pass_callback_alloc_vari<F>(std::forward<F>(functor));
43}
44
45} // namespace Xped
46
47#endif
Definition: bench.cpp:62
void reverse_pass_callback_alloc(F &&functor)
Definition: reverse_pass_callback_alloc.hpp:40
Definition: MatrixMultiplication.hpp:4
Definition: reverse_pass_callback_alloc.hpp:12
void chain() final
Definition: reverse_pass_callback_alloc.hpp:21
void init_dependent()
Definition: reverse_pass_callback_alloc.hpp:23
void set_zero_adjoint() final
Definition: reverse_pass_callback_alloc.hpp:22
F rev_functor_
Definition: reverse_pass_callback_alloc.hpp:13
reverse_pass_callback_alloc_vari(F &&rev_functor)
Definition: reverse_pass_callback_alloc.hpp:15