Skip to content

Commit a85a673

Browse files
Merge pull request #264 from avik-pal/ap/init_jacobian_v2
Special Dispatch for Static Array
2 parents 659b523 + cf98e97 commit a85a673

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/SparseDiffTools.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ForwardDiff: Dual, jacobian, partials, DEFAULT_CHUNK_THRESHOLD
1616
using ArrayInterface, SparseArrays
1717
import ArrayInterface: matrix_colors
1818
import StaticArrays
19+
import StaticArrays: StaticArray
1920
# Others
2021
using SciMLOperators, LinearAlgebra, Random
2122
import DataStructures: DisjointSets, find_root!, union!

src/highlevel/common.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ function init_jacobian(c::AbstractMaybeSparseJacobianCache)
259259
return init_jacobian(__getfield(c, Val(:jac_prototype)), T, c.fx, c.x)
260260
end
261261
init_jacobian(::Nothing, ::Type{T}, fx, x) where {T} = similar(fx, T, length(fx), length(x))
262+
function init_jacobian(::Nothing, ::Type{T}, fx::StaticArray, x::StaticArray) where {T}
263+
# We want to construct a MArray to preserve types
264+
J = StaticArrays.MArray{Tuple{length(fx), length(x)}, T}(undef)
265+
return J
266+
end
262267
init_jacobian(J, ::Type{T}, _, _) where {T} = similar(J, T, size(J, 1), size(J, 2))
263268
init_jacobian(J::SparseMatrixCSC, ::Type{T}, _, _) where {T} = T.(J)
264269

0 commit comments

Comments
 (0)