| ADoverload {RTMB} | R Documentation |
Enable extra RTMB convenience methods
Description
Enable extra RTMB convenience methods
Usage
ADoverload(x = c("[<-", "c", "diag<-"))
Arguments
x |
Name of primitive to overload |
Details
Work around limitations in R's method dispatch system by overloading some selected primitives, currently:
Inplace replacement, so you can do
x[i] <- ywhenxis numeric andyis AD.Mixed combine, so you can do e.g.
c(x, y)whenxnumeric andyis AD.Diagonal assignment, so you can do
diag(x) <- ywhenxis a numeric matrix andyis 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.
Value
Function representing the overload.
Examples
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)