Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 7a8170f

Browse files
committed
Add direct SArray dispatch
1 parent 55513d4 commit 7a8170f

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/highlevel/common.jl

-11
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,3 @@ init_jacobian(J::SparseMatrixCSC, ::Type{T}, fx, x; kwargs...) where {T} = T.(J)
332332

333333
__maybe_copy_x(_, x) = x
334334
__maybe_copy_x(_, ::Nothing) = nothing
335-
336-
# Create a mutable version of the input array
337-
function __make_mutable(x)
338-
if ArrayInterface.can_setindex(x)
339-
return x
340-
else
341-
y = similar(x)
342-
copyto!(y, x)
343-
return y
344-
end
345-
end

src/highlevel/finite_diff.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ __getfield(c::FiniteDiffJacobianCache, ::Val{:jac_prototype}) = c.jac_prototype
1010

1111
function sparse_jacobian_cache(fd::Union{AutoSparseFiniteDiff, AutoFiniteDiff},
1212
sd::AbstractMaybeSparsityDetection, f::F, x; fx = nothing) where {F}
13-
x = __make_mutable(x) # FiniteDiff is bad at handling immutables
1413
coloring_result = sd(fd, f, x)
1514
fx = fx === nothing ? similar(f(x)) : fx
1615
if coloring_result isa NoMatrixColoring
@@ -26,7 +25,6 @@ end
2625

2726
function sparse_jacobian_cache(fd::Union{AutoSparseFiniteDiff, AutoFiniteDiff},
2827
sd::AbstractMaybeSparsityDetection, f!::F, fx, x) where {F}
29-
x = __make_mutable(x) # FiniteDiff is bad at handling immutables
3028
coloring_result = sd(fd, f!, fx, x)
3129
if coloring_result isa NoMatrixColoring
3230
cache = FiniteDiff.JacobianCache(x, fx)
@@ -50,3 +48,7 @@ function sparse_jacobian!(J::AbstractMatrix, _, cache::FiniteDiffJacobianCache,
5048
FiniteDiff.finite_difference_jacobian!(J, f!, x, cache.cache)
5149
return J
5250
end
51+
52+
function sparse_jacobian_static_array(_, cache::FiniteDiffJacobianCache, f, x::SArray)
53+
return FiniteDiff.finite_difference_jacobian(f, x, cache.cache)
54+
end

0 commit comments

Comments
 (0)