Zygote gradient: problem with indexing constant arrays

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?

I got that error yesterday in a different context.

add Zygote#master
add IRTools#master

allowed me to continue

1 Like