| ADoverload | R Documentation |
Enable extra RTMB convenience methods
ADoverload(x = c("[<-", "c", "diag<-"))
x |
Name of primitive to overload |
Work around limitations in R's method dispatch system by overloading some selected primitives, currently:
Inplace replacement, so you can do x[i] <- y when x is numeric and y is AD.
Mixed combine, so you can do e.g. c(x, y) when x numeric and y is AD.
Diagonal assignment, so you can do diag(x) <- y when x is a numeric matrix and y is AD.
In all cases, the result should be AD.
The methods are automatically temporarily attached to the search path (search()) when entering MakeTape or MakeADFun.
Alternatively, methods can be overloaded locally inside functions using e.g. "[<-" <- ADoverload("[<-"). This is only needed when using RTMB from a package.
Function representing the overload.
MakeTape(function(x) {print(search()); x}, numeric(0))
MakeTape(function(x) c(1,x), 1:3)
MakeTape(function(x) {y <- 1:3; y[2] <- x; y}, 1)
MakeTape(function(x) {y <- matrix(0,3,3); diag(y) <- x; y}, 1:3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.