Stan Math Library  2.20.0
reverse mode automatic differentiation
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 
8 #include <stdexcept>
9 
10 namespace stan {
11 namespace math {
12 
18  if (empty_nested())
19  throw std::logic_error(
20  "empty_nested() must be false before calling"
21  " set_zero_all_adjoints_nested()");
22  size_t start1 = ChainableStack::instance_->nested_var_stack_sizes_.back();
23  // avoid wrap with unsigned when start1 == 0
24  for (size_t i = (start1 == 0U) ? 0U : (start1 - 1);
25  i < ChainableStack::instance_->var_stack_.size(); ++i)
26  ChainableStack::instance_->var_stack_[i]->set_zero_adjoint();
27 
28  size_t start2
30  for (size_t i = (start2 == 0U) ? 0U : (start2 - 1);
32  ChainableStack::instance_->var_nochain_stack_[i]->set_zero_adjoint();
33  }
34 }
35 
36 } // namespace math
37 } // namespace stan
38 #endif
static bool empty_nested()
Return true if there is no nested autodiff being executed.
static void set_zero_all_adjoints_nested()
Reset all adjoint values in the top nested portion of the stack to zero.
static STAN_THREADS_DEF AutodiffStackStorage * instance_

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