When I try to do jacobian sparsity detection, I get error that ERROR: MethodError: no method matching zero(::Type{Any})
.
The array returned from PreallocationsTools.jl for array of Symbolics.Num datatype, is of type Vector{Any}
. So when I do some mathematical operations on it, it errors. Here is a MWE
using Symbolics, PreallocationTools, SparseArrays
import LinearAlgebra as LA
function f!(du::AbstractArray{T}, u::AbstractArray{T}, p) where {T}
∇, vbd, intp, Γd, tmp, v = p
v = get_tmp(v, first(u))
tmp = get_tmp(tmp, first(u))
v[Γd] .= vbd
v[intp] .= u
@show typeof(v)
LA.mul!(tmp, ∇, v)
tmp - sin.(v)
du .= tmp[intp]
return
end
function main()
n = 1000
Γd = rand(1:n, 10)
v = rand(n)
vcache = DiffCache(v[:])
tmp = DiffCache(v[:])
vbd = v[Γd]
intp = setdiff(1:n, Γd)
∇ = sprand(n, n, 0.3)
p = (∇, vbd, intp, Γd, tmp, vcache)
u = v[intp]
du = similar(u)
f1!(du, u) = f!(du, u, p)
jac_sp = Symbolics.jacobian_sparsity(f1!, du, u)
jac_sp = Float64.(jac_sp)
return jac_sp
end
jac_sp = main()
It seems I’m missing something and there should be an easy fix for this. Thanks in advance.