StackOverflowError trying to fit a difference equation with Turing

This was answered by @wupeifan on Julia Slack. Replacing the definition of diffsolve by what follows resolves the problem:

function diffsolve(func_, u0, p, n=100)
    u_t = deepcopy(u0)
    T = promote_type(eltype(u0), eltype(p))
    u = Array{Array{T,1},1}() 
    du = Vector{T}(undef, 3) 

    push!(u, u0)
    for t in 1:n
        func_(du, u_t, p, 1)
        u_t = u_t + du
        push!(u, u_t)
    end
    u
end

This solution converts both du and u0 to the same type as p (not only u0 as in a previous answer) and hence, it works.

1 Like