stan-dev/stan — pull request #1033 by bob-carpenter (2014-09-16 05:57:56+00:00)
Title: Feature/issue 1031 nested reverse mode autodiff

#### Summary:

Adds the ability to do nested reverse-mode autodiff, which is necessary for the ODE integrator.

#### Intended Effect:

Allow nested reverse-mode. In the middle of a reverse mode, mark the position, do another reverse mode, then pop back to where you were.

#### How to Verify:

New unit tests for nested behavior.

#### Side Effects:

Yes. It removes the `recover_memory()` call from `grad()`, which moves responsibility for recovering memory back to the calling function.

It also makes the recovery of memory more robust in `agrad/autodiff.hpp` with proper try/catch behavior.

#### Documentation:

Not user facing.

#### Reviewer Suggestions:

Anyone familiar with the guts of reverse-mode autodiff.