stan-dev/stan — pull request #411 by bob-carpenter (2013-11-23 08:40:30+00:00)
Title: Bugfix/issue 379 sd grad at 0

Fixes issue #379, which was caused by auto-diff blindly applying the chain rule in the case where sd(x) = 0, leading to a sqrt(0) in the denominator.

Worked out and implemented for reverse-mode the analytic gradients for sd() and variance(), including limits as sd(x) approaches 0.

Everything tested vs. autodiff or finite diffs.