It looks super simple,
function h(pars)
my_array = [1.0, 2.0, 3.0]
indices = [2,3,1]
#
v = 0.0
for (c,i) in zip(pars,indices)
v += c * my_array[i]
end
return v
end
h([1.0,2.0,3.0]) # 11, fine
g(x) = gradient(pars->h(pars), x)
g([1.0,2.0,3.0]) # MethodError: no method matching getindex(::Nothing, ::Int64)
I wondering what happens, any ideas? Does my_array
get lost at differentiation?