All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
grad.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_CORE_GRAD_HPP
#define STAN_MATH_REV_CORE_GRAD_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 <stan/math/rev/core/nested_size.hpp>
#include <vector>
namespace stan {
namespace math {
static void grad(chainable* vi) {
// simple reference implementation (intended as doc):
// vi->init_dependent();
// size_t end = var_stack_.size();
// size_t begin = empty_nested() ? 0 : end - nested_size();
// for (size_t i = end; --i > begin; )
// var_stack_[i]->chain();
typedef std::vector<chainable*>::reverse_iterator it_t;
vi->init_dependent();
it_t begin = ChainableStack::var_stack_.rbegin();
it_t end = empty_nested()
? ChainableStack::var_stack_.rend() : begin + nested_size();
for (it_t it = begin; it < end; ++it) {
(*it)->chain();
}
}
}
}
#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::chainable
Abstract base class for variable implementations that handles memory management and applying the chai...
Definition: chainable.hpp:14
chainable.hpp
stan::math::grad
static void grad(chainable *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
Definition: grad.hpp:30
nested_size.hpp
empty_nested.hpp
stan::math::chainable::init_dependent
virtual void init_dependent()
Initialize this chainable's adjoint value to make it the dependent variable in a gradient calculation...
Definition: chainable.hpp:42
chainable_alloc.hpp
stan::math::nested_size
static size_t nested_size()
Definition: nested_size.hpp:12
chainablestack.hpp
stan::math::AutodiffStackStorage::var_stack_
static std::vector< ChainableT * > var_stack_
Definition: autodiffstackstorage.hpp:13

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