Stan Math Library
5.0.0
Automatic Differentiation
|
The AD tape of reverse mode AD is by default stored globally within the process (or thread).
With the ScopedChainableStack class one may execute a nullary functor with reference to an AD tape which is stored with the instance of ScopedChainableStack. Example:
ScopedChainableStack scoped_stack;
double cgrad_a = scoped_stack.execute([] { var a = 2.0; var b = 4.0; var c = a*a + b; c.grad(); return a.adj(); });
Doing so will not interfere with the process (or thread) AD tape.
Definition at line 31 of file scoped_chainablestack.hpp.
#include <scoped_chainablestack.hpp>
Classes | |
struct | activate_scope |
Public Member Functions | |
ScopedChainableStack ()=default | |
template<typename F , typename... Args> | |
decltype(auto) | execute (F &&f, Args &&... args) |
Execute in the current thread a function and write the AD tape to local_stack_ of this instance. | |
ScopedChainableStack (const ScopedChainableStack &)=delete | |
ScopedChainableStack & | operator= (const ScopedChainableStack &)=delete |
Private Attributes | |
ChainableStack::AutodiffStackStorage | local_stack_ |
std::mutex | local_stack_mutex_ |