kaskr/RTMB

Nested tape evaluation surprise

kaskr opened this issue · 0 comments

Currently, tape evaluation method is dispatched based on class of input. This can cause surprises:

F <- MakeTape(function(x) {
    G <- MakeTape(function(y) y*x, numeric(5))
    G(1:5) ## User expects (1:5)*x here [but that would require G(advector(1:5))]
}, numeric(5))
F(1:5) ## Expecting (1:5)^2

Result

F(1:5)
[1] 0 0 0 0 0

A safer approach would be to always choose AD evaluation whenever there's an active AD context.