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 
7 #include <stdexcept>
8 
9 namespace stan {
10 namespace math {
11 
12 /**
13  * Recover only the memory used for the top nested call. If there
14  * is nothing on the nested stack, then a
15  * <code>std::logic_error</code> exception is thrown.
16  *
17  * @throw std::logic_error if <code>empty_nested()</code> returns
18  * <code>true</code>
19  */
20 static inline void recover_memory_nested() {
21  if (empty_nested())
22  throw std::logic_error(
23  "empty_nested() must be false"
24  " before calling recover_memory_nested()");
25 
27  ChainableStack::instance().nested_var_stack_sizes_.back());
29 
31  ChainableStack::instance().nested_var_nochain_stack_sizes_.back());
33 
34  for (size_t i
35  = ChainableStack::instance().nested_var_alloc_stack_starts_.back();
38  }
40  ChainableStack::instance().nested_var_alloc_stack_starts_.back());
42 
44 }
45 
46 } // namespace math
47 } // namespace stan
48 #endif
static bool empty_nested()
static AutodiffStackStorage & instance()
static void recover_memory_nested()