| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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/chainable.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
19 static inline void recover_memory() {
20 if (!empty_nested())
21 throw std::logic_error("empty_nested() must be true"
22 " before calling recover_memory()");
23 ChainableStack::var_stack_.clear();
24 ChainableStack::var_nochain_stack_.clear();
25 for (size_t i = 0; i < ChainableStack::var_alloc_stack_.size(); ++i) {
26 delete ChainableStack::var_alloc_stack_[i];
27 }
28 ChainableStack::var_alloc_stack_.clear();
29 ChainableStack::memalloc_.recover_all();
30 }
31
32 }
33 }
34 #endif
stan::math::empty_nested
static bool empty_nested()
Return true if there is no nested autodiff being executed.
Definition: empty_nested.hpp:14
stan::math::AutodiffStackStorage::memalloc_
static stack_alloc memalloc_
Definition: autodiffstackstorage.hpp:16
chainable.hpp
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:201
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
chainable_alloc.hpp
stan::math::recover_memory
static void recover_memory()
Recover memory used for all variables for reuse.
Definition: recover_memory.hpp:19
chainablestack.hpp
stan::math::AutodiffStackStorage::var_stack_
static std::vector< ChainableT * > var_stack_
Definition: autodiffstackstorage.hpp:13

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