#2994 added unit test for comparison of autodiff results with numeric differences and fixed a few bugs in AutoDiff code