All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
recover_memory_nested.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_CORE_RECOVER_MEMORY_NESTED_HPP
#define STAN_MATH_REV_CORE_RECOVER_MEMORY_NESTED_HPP
#include <stan/math/rev/core/chainable.hpp>
#include <stan/math/rev/core/chainable_alloc.hpp>
#include <stan/math/rev/core/chainablestack.hpp>
#include <stan/math/rev/core/empty_nested.hpp>
#include <stdexcept>
namespace stan {
namespace math {
static inline void recover_memory_nested() {
if (empty_nested())
throw std::logic_error("empty_nested() must be false"
" before calling recover_memory_nested()");
ChainableStack::var_stack_
.resize(ChainableStack::nested_var_stack_sizes_.back());
ChainableStack::nested_var_stack_sizes_.pop_back();
ChainableStack::var_nochain_stack_
.resize(ChainableStack::nested_var_nochain_stack_sizes_.back());
ChainableStack::nested_var_nochain_stack_sizes_.pop_back();
for (size_t i = ChainableStack::nested_var_alloc_stack_starts_.back();
i < ChainableStack::var_alloc_stack_.size();
++i) {
delete ChainableStack::var_alloc_stack_[i];
}
ChainableStack::var_alloc_stack_.resize
(ChainableStack::nested_var_alloc_stack_starts_.back());
ChainableStack::nested_var_alloc_stack_starts_.pop_back();
ChainableStack::memalloc_.recover_nested();
}
}
}
#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.