-
Notifications
You must be signed in to change notification settings - Fork 28
Description
A few comments for consideration in the matrix autodiff design document.
-
As much as the matrix of vars enables better performance it also greatly facilities the implementation matrix-valued reverse mode updates, as demonstrated in the matrix product example. The resulting code is not only easier to develop but also easier to read -- all in addition to likely being much faster. Perhaps worthy of mentioning in the summary.
-
Given the amount of compiler logic proposed it would be great to have a compiler option that returns an annotated Stan program indicating with variables were assigned
matrix<var>and which were assignedvar<matrix>. This would help users track down undesired casts down tomatrix<var>and optimize their code without having to guess at the underlying compiler logic. -
It would also be great to have some way to force a conversion from a
matrix<var>to avar<matrix>, even if only with a function meant for advanced users. I'm thinking in particular of Gaussian process applications where custom Gram matrices are built element by element in a user-defined function, but afterwards are used used as only monolithic matrices. My understanding of the proposed logic is that this would propagate amatrix<var>throughout the Stan program and miss out on potential performance unless there is some way to force a user-defined function to return avar<matrix>to cast the return, for example
functions {
matrix custom_covar(...);
}
...
model {
matrix[N, N] custom_gram = to_varmat(custom_covar(...));
}