stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
744 stars 187 forks source link

quad_form_diag derivatives #2565

Open spinkney opened 3 years ago

spinkney commented 3 years ago

Provide a reverse-mode specialization for quad_form_diag.

bob-carpenter commented 3 years ago

I rewrote the issue as an issue and tagged it as a feature and good first issue, but it's still missing all the boilerplate.

Is it faster or negligibile to just autodiff through the diag version?

A reverse specialization would be faster and more memory efficient. It probably hasn't been optimized because it's mainly used for rescaling a covariance matrix, which we'd rather do in the Cholesky space for efficiency.