## numeric object to AD
AD(numeric(4), force=TRUE)
## complex object to AD
AD(complex(4), force=TRUE)
## Convert sparse matrices (Matrix package) to AD representation
F <- MakeTape(function(x) {
M <- AD(Matrix::Matrix(0,4,4))
M[1,] <- x
D <- AD(Matrix::Diagonal(4))
D@x[] <- x
M + D
}, 0)
F(2)
Run the code above in your browser using DataLab