Zygote.gradient(): Mutating arrays is not supported

When I do a gradient calculation with Zygote, it throw an error: Mutating arrays is not supported. I don’t know why it went wrong, how should I correct it, or how should I debug it so that I would know where it went wrong.

Mutating arrays is not supported

Stacktrace:
[1] error(::String) at .\error.jl:33
[2] (::Zygote.var"#451#452")(::Nothing) at C:\Users\38606.julia\packages\Zygote\seGHk\src\lib\array.jl:65
[3] (::Zygote.var"#2373#back#453"{Zygote.var"#451#452"})(::Nothing) at C:\Users\38606.julia\packages\ZygoteRules\6nssF\src\adjoint.jl:49
[4] Square_T0 at .\In[2]:13 [inlined]
[5] (::typeof(∂(Square_T0)))(::Nothing) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
[6] hotrg at .\In[13]:5 [inlined]
[7] (::typeof(∂(hotrg)))(::Float64) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
[8] #70 at .\In[19]:1 [inlined]
[9] (::Zygote.var"#41#42"{typeof(∂(#70))})(::Float64) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface.jl:45
[10] gradient(::Function, ::Array{Complex{Float64},2}, ::Vararg{Array{Complex{Float64},2},N} where N) at C:\Users\38606.julia\packages\Zygote\seGHk\src\compiler\interface.jl:54
[11] top-level scope at In[19]:1

Probably, you try to differentiate through some code that contains something like x[i] = y.
This is not supported by Zygote. I used this work-around at some point.

To get more help, please follow the recommendations in Please read: make it easier to help you.

1 Like