| 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_nested.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_CORE_RECOVER_MEMORY_NESTED_HPP
2 #define STAN_MATH_REV_CORE_RECOVER_MEMORY_NESTED_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
21 static inline void recover_memory_nested() {
22 if (empty_nested())
23 throw std::logic_error("empty_nested() must be false"
24 " before calling recover_memory_nested()");
25
26 ChainableStack::var_stack_
27 .resize(ChainableStack::nested_var_stack_sizes_.back());
28 ChainableStack::nested_var_stack_sizes_.pop_back();
29
30 ChainableStack::var_nochain_stack_
31 .resize(ChainableStack::nested_var_nochain_stack_sizes_.back());
32 ChainableStack::nested_var_nochain_stack_sizes_.pop_back();
33
34 for (size_t i = ChainableStack::nested_var_alloc_stack_starts_.back();
35 i < ChainableStack::var_alloc_stack_.size();
36 ++i) {
37 delete ChainableStack::var_alloc_stack_[i];
38 }
39 ChainableStack::var_alloc_stack_.resize
40 (ChainableStack::nested_var_alloc_stack_starts_.back());
41 ChainableStack::nested_var_alloc_stack_starts_.pop_back();
42
43 ChainableStack::memalloc_.recover_nested();
44 }
45
46 }
47 }
48 #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
stan::math::stack_alloc::recover_nested
void recover_nested()
recover memory back to the last start_nested call.
Definition: stack_alloc.hpp:220
empty_nested.hpp
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::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
stan::math::recover_memory_nested
static void recover_memory_nested()
Recover only the memory used for the top nested call.
Definition: recover_memory_nested.hpp:21
chainablestack.hpp
stan::math::AutodiffStackStorage::var_stack_
static std::vector< ChainableT * > var_stack_
Definition: autodiffstackstorage.hpp:13
stan::math::AutodiffStackStorage::nested_var_alloc_stack_starts_
static std::vector< size_t > nested_var_alloc_stack_starts_
Definition: autodiffstackstorage.hpp:21

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