ADapply: AD apply functions

ADapplyR Documentation

AD apply functions

Description

These base apply methods have been modified to keep the AD class attribute (which would otherwise be lost).

Usage

## S4 method for signature 'advector'
apply(X, MARGIN, FUN, ..., simplify = TRUE)

## S4 method for signature 'ANY'
sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)

## S4 method for signature 'ANY'
Vectorize(FUN, vectorize.args = arg.names, SIMPLIFY = TRUE, USE.NAMES = TRUE)

Arguments

X, MARGIN, FUN, ...

See apply

simplify, USE.NAMES

See sapply

vectorize.args, SIMPLIFY

See Vectorize. USE.NAMES is currently ignored by AD version.

Details

The Vectorize function is especially fast in RTMB, and recommended to be used to speed up long computations where tape construction is a bottleneck.

Value

Object of class "advector" with a dimension attribute.

Functions

  • apply(advector): As apply

  • sapply(ANY): As sapply

  • Vectorize(ANY): As Vectorize

Examples

F <- MakeTape(function(x) apply(matrix(x,2,2), 2, sum), numeric(4))
F$jacobian(1:4)
f <- Vectorize(function(x) integrate(dnorm, -Inf, x)$value)
F <- MakeTape(f, numeric(1e3))

RTMB documentation built on March 20, 2026, 5:08 p.m.