Hi all,
this is my first post here!
I’m still very new to Julia and I’m enjoying a lot learning about it. I have a simple question for which I couldn’t find an answer, I hope it wasn’t posted already somewhere else.
I’ll make a simple example that shows the problem (the actual code is much more complex, but this is the basic idea): I’m trying to differentiate the following function wrt to x
function my_fun(x,xvals,ids)
out = copy(xvals)
out[ids] = x[ids]
return out
end
Basically, the function returns a vector, some element of that vector are constant (xvals) while others (defined by the mask ids) depend on the input x.
If I have, for example, x = [0 0 0 0], xvals = [1 2 3 4] and ids=[1 2], the function seems to work correctly, but when I try to call ForwarDiff to differentiate it wrt x
zz = ForwardDiff.jacobian(x → my_fun(x,xvals,ids),x)
I get MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{var"#5#6", Int64}, Int64, 4})
I can’t really understand what the problem is, since if I try with another function that only returns the selected components:
function my_fun(x,ids)
out = x[ids]
return out
end
the differentiation works without problems.
Can someone explain me what’s wrong?
Thanks