JuliaDiff / SparseDiffTools.jl

Fast jacobian computation through sparsity exploitation and matrix coloring
MIT License
242 stars 42 forks source link

oop jacobian can't preserve array-like objects #71

Open huanglangwen opened 5 years ago

huanglangwen commented 5 years ago

forwarddiff_color_jacobian automatically converts array-like input object into array. When f depend on specific property of the input object, the jacobian will fail. MWE:

using OrdinaryDiffEq, SparseDiffTools
mutable struct SimTypeg{T,T2} <: DEDataMatrix{T}
  x::Array{T,2} # two dimensional
  f1::T2
end
function f(u)
  u.f1*u[1]
end
u0 = SimTypeg(fill(0.00001,2,2),0.0)
forwarddiff_color_jacobian(f,u0)
ChrisRackauckas commented 5 years ago

Does it also convert SArrays?

huanglangwen commented 5 years ago

No, because vec(x) keeps SArray. https://github.com/JuliaDiffEq/SparseDiffTools.jl/blob/aaaa9048de136cf222967d3f4c5d13315cbf9208/src/differentiation/compute_jacobian_ad.jl#L102

ChrisRackauckas commented 5 years ago

Does this at least not break anything that currently exists?

huanglangwen commented 5 years ago

Does this at least not break anything that currently exists?

It break at least one test in OrdinaryDiffEq.jl: https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/master/test/interface/data_array_test.jl

ChrisRackauckas commented 5 years ago

Looks like there's a few other things to work out with resizing.