Stan Math Library: stan/math/rev/core/recover_memory_nested.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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_alloc.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
20 static inline void recover_memory_nested() {
21 if (empty_nested())
22 throw std::logic_error("empty_nested() must be false"
23 " before calling recover_memory_nested()");
24
25 ChainableStack::var_stack_
26 .resize(ChainableStack::nested_var_stack_sizes_.back());
27 ChainableStack::nested_var_stack_sizes_.pop_back();
28
29 ChainableStack::var_nochain_stack_
30 .resize(ChainableStack::nested_var_nochain_stack_sizes_.back());
31 ChainableStack::nested_var_nochain_stack_sizes_.pop_back();
32
33 for (size_t i = ChainableStack::nested_var_alloc_stack_starts_.back();
34 i < ChainableStack::var_alloc_stack_.size();
35 ++i) {
36 delete ChainableStack::var_alloc_stack_[i];
37 }
38 ChainableStack::var_alloc_stack_.resize
39 (ChainableStack::nested_var_alloc_stack_starts_.back());
40 ChainableStack::nested_var_alloc_stack_starts_.pop_back();
41
42 ChainableStack::memalloc_.recover_nested();
43 }
44
45 }
46 }
47 #endif
stan::math::empty_nested
static bool empty_nested()
Return true if there is no nested autodiff being executed.
Definition: empty_nested.hpp:12
stan
Definition: log_sum_exp.hpp:8
stan::math::AutodiffStackStorage::memalloc_
static stack_alloc memalloc_
Definition: autodiffstackstorage.hpp:16
stan::math::stack_alloc::recover_nested
void recover_nested()
recover memory back to the last start_nested call.
Definition: stack_alloc.hpp:216
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:20
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–2016, Stan Development Team.