| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

set_zero_all_adjoints_nested.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_CORE_SET_ZERO_ALL_ADJOINTS_NESTED_HPP
2 #define STAN_MATH_REV_CORE_SET_ZERO_ALL_ADJOINTS_NESTED_HPP
3
4 #include <stan/math/rev/core/vari.hpp>
5 #include <stan/math/rev/core/chainable_alloc.hpp>
6 #include <stan/math/rev/core/chainablestack.hpp>
7 #include <stan/math/rev/core/empty_nested.hpp>
8 #include <stdexcept>
9
10 namespace stan {
11 namespace math {
12
17 static void set_zero_all_adjoints_nested() {
18 if (empty_nested())
19 throw std::logic_error("empty_nested() must be false before calling"
20 " set_zero_all_adjoints_nested()");
21 size_t start1 = ChainableStack::nested_var_stack_sizes_.back();
22 // avoid wrap with unsigned when start1 == 0
23 for (size_t i = (start1 == 0U) ? 0U : (start1 - 1);
24 i < ChainableStack::var_stack_.size(); ++i)
25 ChainableStack::var_stack_[i]->set_zero_adjoint();
26
27 size_t start2 = ChainableStack::nested_var_nochain_stack_sizes_.back();
28 for (size_t i = (start2 == 0U) ? 0U : (start2 - 1);
29 i < ChainableStack::var_nochain_stack_.size(); ++i) {
30 ChainableStack::var_nochain_stack_[i]->set_zero_adjoint();
31 }
32 }
33
34 }
35 }
36 #endif
stan::math::empty_nested
static bool empty_nested()
Return true if there is no nested autodiff being executed.
Definition: empty_nested.hpp:12
vari.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::set_zero_all_adjoints_nested
static void set_zero_all_adjoints_nested()
Reset all adjoint values in the top nested portion of the stack to zero.
Definition: set_zero_all_adjoints_nested.hpp:17
empty_nested.hpp
stan::math::AutodiffStackStorage::var_nochain_stack_
static std::vector< ChainableT * > var_nochain_stack_
Definition: autodiffstackstorage.hpp:14
stan::math::AutodiffStackStorage::nested_var_nochain_stack_sizes_
static std::vector< size_t > nested_var_nochain_stack_sizes_
Definition: autodiffstackstorage.hpp:20
chainable_alloc.hpp
stan::math::AutodiffStackStorage::nested_var_stack_sizes_
static std::vector< size_t > nested_var_stack_sizes_
Definition: autodiffstackstorage.hpp:19
chainablestack.hpp
stan::math::AutodiffStackStorage::var_stack_
static std::vector< ChainableT * > var_stack_
Definition: autodiffstackstorage.hpp:13

[ Stan Home Page ] © 2011–2016, Stan Development Team.