library(RTMB)
library(Matrix)
I <- .symDiagonal(2)
parameters <- list(u=matrix(0,2,2), delta=.123)
func <- function(parms) {
getAll(parms)
f <- function(x)dgmrf(x,Q=I*delta,log=TRUE)
-dseparable(f,f)(u)
}
obj <- MakeADFun(func, parameters, random="u")
obj$fn() ## Should be zero
obj$gr() ## Should be zero
Example:
Gives
Reason:
dgmrf
throws away 'advector' class attribute when called with numeric x and AD precision: https://github.com/kaskr/RTMB/blob/cd8bcb91a7ed0668ce7e24c2faf84f7163c3b610/RTMB/R/mvgauss.R#L177 https://github.com/kaskr/RTMB/blob/cd8bcb91a7ed0668ce7e24c2faf84f7163c3b610/RTMB/R/mvgauss.R#L61