All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
stan::math::chainable Class Reference

Abstract base class for variable implementations that handles memory management and applying the chain rule. More...

`#include <chainable.hpp>`

Inheritance diagram for stan::math::chainable:

## Public Member Functions

| chainable ()
| Construct a chainable object. More...
virtual | ~chainable ()
| Chainables are not destructible and should go on the function call stack or be allocated with operator new. More...
virtual void | chain ()
| Apply the chain rule to this variable based on the variables on which it depends. More...
virtual void | init_dependent ()
| Initialize this chainable's adjoint value to make it the dependent variable in a gradient calculation. More...
virtual void | set_zero_adjoint ()
| Set the value of the adjoint for this chainable to its initial value. More...

## Static Public Member Functions

static void * | operator new (size_t nbytes)
| Allocate memory from the underlying memory pool. More...
static void | operator delete (void *)
| Delete a pointer from the underlying memory pool. More...

## Detailed Description

Abstract base class for variable implementations that handles memory management and applying the chain rule.

Definition at line 14 of file chainable.hpp.

## Constructor & Destructor Documentation

stan::math::chainable::chainable | ( |  | ) |

inline

Construct a chainable object.

The implementation in this abstract base class is a no-op.

Definition at line 20 of file chainable.hpp.

virtual stan::math::chainable::~chainable | ( |  | ) |

inlinevirtual

Chainables are not destructible and should go on the function call stack or be allocated with operator new.

Definition at line 26 of file chainable.hpp.

## Member Function Documentation

virtual void stan::math::chainable::chain | ( |  | ) |

inlinevirtual

Apply the chain rule to this variable based on the variables on which it depends.

The base implementation in this class is a no-op.

Reimplemented in stan::math::precomputed_gradients_vari, stan::math::cholesky_decompose_v_vari, stan::math::stored_gradient_vari, stan::math::gevv_vvv_vari, stan::math::partials_vari, stan::math::sum_v_vari, stan::math::precomp_vvv_vari, stan::math::precomp_vv_vari, and stan::math::precomp_v_vari.

Definition at line 35 of file chainable.hpp.

virtual void stan::math::chainable::init_dependent | ( |  | ) |

inlinevirtual

Initialize this chainable's adjoint value to make it the dependent variable in a gradient calculation.

Reimplemented in stan::math::vari.

Definition at line 42 of file chainable.hpp.

static void stan::math::chainable::operator delete | ( | void * |  | ) |

inlinestatic

Delete a pointer from the underlying memory pool.

This no-op implementation enables a subclass to throw exceptions in its constructor. An exception thrown in the constructor of a subclass will result in an error being raised, which is in turn caught and calls delete().

See the discussion of "plugging the memory leak" in: http://www.parashift.com/c++-faq/memory-pools.html

Definition at line 75 of file chainable.hpp.

static void* stan::math::chainable::operator new | ( | size_t | nbytes | ) |

inlinestatic

Allocate memory from the underlying memory pool.

This memory is is managed by the gradient program and will be recovered as a whole. Classes should not be allocated with this operator if they have non-trivial destructors.

Parameters

  nbytes | Number of bytes to allocate.

Returns
  Pointer to allocated bytes.

Definition at line 61 of file chainable.hpp.

virtual void stan::math::chainable::set_zero_adjoint | ( |  | ) |

inlinevirtual

Set the value of the adjoint for this chainable to its initial value.

Reimplemented in stan::math::vari.

Definition at line 49 of file chainable.hpp.

The documentation for this class was generated from the following file:

- stan/math/rev/core/chainable.hpp

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