Skip to content

Commit

Permalink
Merge pull request #264 from avik-pal/ap/init_jacobian_v2
Browse files Browse the repository at this point in the history
Special Dispatch for Static Array
  • Loading branch information
ChrisRackauckas authored Oct 9, 2023
2 parents 659b523 + cf98e97 commit a85a673
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SparseDiffTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ForwardDiff: Dual, jacobian, partials, DEFAULT_CHUNK_THRESHOLD
using ArrayInterface, SparseArrays
import ArrayInterface: matrix_colors
import StaticArrays
import StaticArrays: StaticArray
# Others
using SciMLOperators, LinearAlgebra, Random
import DataStructures: DisjointSets, find_root!, union!
Expand Down
5 changes: 5 additions & 0 deletions src/highlevel/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ function init_jacobian(c::AbstractMaybeSparseJacobianCache)
return init_jacobian(__getfield(c, Val(:jac_prototype)), T, c.fx, c.x)
end
init_jacobian(::Nothing, ::Type{T}, fx, x) where {T} = similar(fx, T, length(fx), length(x))
function init_jacobian(::Nothing, ::Type{T}, fx::StaticArray, x::StaticArray) where {T}
# We want to construct a MArray to preserve types
J = StaticArrays.MArray{Tuple{length(fx), length(x)}, T}(undef)
return J
end
init_jacobian(J, ::Type{T}, _, _) where {T} = similar(J, T, size(J, 1), size(J, 2))
init_jacobian(J::SparseMatrixCSC, ::Type{T}, _, _) where {T} = T.(J)

Expand Down

0 comments on commit a85a673

Please sign in to comment.