SparseDiffTools.jl icon indicating copy to clipboard operation
SparseDiffTools.jl copied to clipboard

oop jacobian can't preserve array-like objects

Open huanglangwen opened this issue 6 years ago • 5 comments

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)

huanglangwen avatar Oct 27 '19 17:10 huanglangwen

Does it also convert SArrays?

ChrisRackauckas avatar Oct 29 '19 10:10 ChrisRackauckas

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

huanglangwen avatar Oct 29 '19 11:10 huanglangwen

Does this at least not break anything that currently exists?

ChrisRackauckas avatar Oct 31 '19 20:10 ChrisRackauckas

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

huanglangwen avatar Nov 01 '19 14:11 huanglangwen

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

ChrisRackauckas avatar Nov 02 '19 14:11 ChrisRackauckas