| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

recover_memory.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_CORE_RECOVER_MEMORY_HPP
2 #define STAN_MATH_REV_CORE_RECOVER_MEMORY_HPP
3
4 #include <stan/math/rev/core/vari.hpp>
5 #include <stan/math/rev/core/chainablestack.hpp>
6 #include <stan/math/rev/core/empty_nested.hpp>
7 #include <stdexcept>
8
9 namespace stan {
10 namespace math {
11
18 static inline void recover_memory() {
19 if (!empty_nested())
20 throw std::logic_error("empty_nested() must be true"
21 " before calling recover_memory()");
22 ChainableStack::var_stack_.clear();
23 ChainableStack::var_nochain_stack_.clear();
24 for (size_t i = 0; i < ChainableStack::var_alloc_stack_.size(); ++i) {
25 delete ChainableStack::var_alloc_stack_[i];
26 }
27 ChainableStack::var_alloc_stack_.clear();
28 ChainableStack::memalloc_.recover_all();
29 }
30
31 }
32 }
33 #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::AutodiffStackStorage::memalloc_
static stack_alloc memalloc_
Definition: autodiffstackstorage.hpp:16
empty_nested.hpp
stan::math::stack_alloc::recover_all
void recover_all()
Recover all the memory used by the stack allocator.
Definition: stack_alloc.hpp:197
stan::math::AutodiffStackStorage::var_alloc_stack_
static std::vector< ChainableAllocT * > var_alloc_stack_
Definition: autodiffstackstorage.hpp:15
stan::math::AutodiffStackStorage::var_nochain_stack_
static std::vector< ChainableT * > var_nochain_stack_
Definition: autodiffstackstorage.hpp:14
stan::math::recover_memory
static void recover_memory()
Recover memory used for all variables for reuse.
Definition: recover_memory.hpp:18
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.