I am looking to move from using ForwardDiff to ReverseDiff due to the speedup provided by compiled tapes. I would like to differentiate a function where one of the arguments is an index of the output, and then compile this jacobian calculation to be reused for the rest of the indexes, however this throws an error.
How would one differentiate the following function using ReverseDiff?
f(x::Vector, theta::Vector, i) = (x.*theta)[i]
Currently I have
using ReverseDiff: jacobian
jacobian(f, ([1.0 2.0], [3.0 4.0], [2.0]))
# Indexing with an integer gives the same error
which gives the error:
ArgumentError: invalid index: TrackedReal<59S>(2.0, 0.0, 2eM, 1, HO3) of type ReverseDiff.TrackedReal{Float64,Float64,ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}}}