Learn R Programming

RTMB (version 1.6)

ADoverload: Enable extra RTMB convenience methods

Description

Enable extra RTMB convenience methods

Usage

ADoverload(x = c("[<-", "c", "diag<-"))

Value

Function representing the overload.

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] <- 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.

Examples

Run this code
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)

Run the code above in your browser using DataLab