F <- MakeTape(prod, numeric(3))
show(F)
F$print()
H <- F$jacfun()$jacfun() ## Hessian tape
show(H)
#### Handy way to plot the graph of F
if (requireNamespace("igraph")) {
G <- igraph::graph_from_adjacency_matrix(F$graph())
plot(G, vertex.size=17, layout=igraph::layout_as_tree)
}
## Taped access of an element of 'rivers' dataset
F <- MakeTape(function(i) DataEval( function(i) rivers[i] , i), 1 )
F(1)
F(2)
## DATA_UPDATE example
## - Pay attention to lazy evaluation!
## - Use 'force.update()'
mydat <- 1:4
fetch <- function() { print("Getting 'mydat'"); .GlobalEnv$mydat }
F <- MakeTape( function(x) x * sum(DataEval(fetch)), 1 )
F$reorder() ## Re-order tape for faster execution
F(1) ## No data update
F(2) ## No data update
mydat <- 5:8
F(1) ## Still no data update !
F$force.update() ## Signal that data has changed
F(1) ## data update
F(2) ## No data update
Run the code above in your browser using DataLab