Closed sethaxen closed 2 years ago
Seems the jacobian
case can be fixed by changing https://github.com/JuliaDiff/FiniteDifferences.jl/blob/178cfb59ca77aa0cf8aa760bb053274c67de8399/src/grad.jl#L24 to (reduce(hcat, ys),)
which might also be more performant since it takes the fast path in base and avoids splatting. I can prepare a PR.
Similarly, it looks like the j′vp
issue can be replaced by changing https://github.com/JuliaDiff/FiniteDifferences.jl/blob/56e1d6338bbe10bc3de6e4daa17c7d93d6a10e15/src/grad.jl#L73 to
return (vec_to_x(_j′vp(fdm, x -> first(to_vec(f(vec_to_x(x)))), ȳ_vec, x_vec)), )
It seems broadcasting CompositeFunction
s (at least in this case), is not type-stable on SVector
inputs once they get larger than 2 functions:
julia> @inferred FiniteDifferences._eval_function(fdm.bound_estimator, identity, 1.0, 1.0);
julia> @inferred FiniteDifferences._eval_function(fdm.bound_estimator, identity ∘ identity, 1.0, 1.0);
julia> @inferred FiniteDifferences._eval_function(fdm.bound_estimator, identity ∘ identity ∘ identity, 1.0, 1.0);
ERROR: return type StaticArrays.SVector{7, Float64} does not match inferred return type StaticArrays.SVector{7}
While
jvp
is. Example: