ADoverload: Enable extra RTMB convenience methods

View source: R/advector.R

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

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)

RTMB documentation built on Sept. 12, 2024, 6:45 a.m.