Automatic Differentiation
 
Loading...
Searching...
No Matches
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
10namespace stan {
11namespace math {
12
20static inline void set_zero_all_adjoints_nested() {
21 if (empty_nested()) {
22 throw std::logic_error(
23 "empty_nested() must be false before calling"
24 " set_zero_all_adjoints_nested()");
25 }
26 const size_t start1
28 // avoid wrap with unsigned when start1 == 0
29 for (size_t i = start1; i < ChainableStack::instance_->var_stack_.size();
30 ++i) {
31 ChainableStack::instance_->var_stack_[i]->set_zero_adjoint();
32 }
33
34 const size_t start2
36 for (size_t i = start2;
38 ChainableStack::instance_->var_nochain_stack_[i]->set_zero_adjoint();
39 }
40}
41
42} // namespace math
43} // namespace stan
44#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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
static thread_local AutodiffStackStorage * instance_