Skip to content

Commit

Permalink
Special Dispatch for Static Array
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 8, 2023
1 parent 659b523 commit cf98e97
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}

Check warning on line 262 in src/highlevel/common.jl

View check run for this annotation

Codecov / codecov/patch

src/highlevel/common.jl#L262

Added line #L262 was not covered by tests
# We want to construct a MArray to preserve types
J = StaticArrays.MArray{Tuple{length(fx), length(x)}, T}(undef)
return J

Check warning on line 265 in src/highlevel/common.jl

View check run for this annotation

Codecov / codecov/patch

src/highlevel/common.jl#L264-L265

Added lines #L264 - L265 were not covered by tests
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 cf98e97

Please sign in to comment.