Skip to content

Commit b5b9298

Browse files
committed
upstream fix to SparseDiffTools.jl
1 parent cb105fc commit b5b9298

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

src/jacobian.jl

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p, ::Val{ii
8080
if has_analytic_jac
8181
f.jac_prototype === nothing ? undefmatrix(u) : f.jac_prototype
8282
else
83-
if f.jac_prototype === nothing
84-
__safe_init_jacobian(jac_cache)
85-
else
86-
f.jac_prototype
87-
end
83+
f.jac_prototype === nothing ? init_jacobian(jac_cache) : f.jac_prototype
8884
end
8985
end
9086

@@ -102,26 +98,6 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p, ::Val{ii
10298
return uf, linsolve, J, fu, jac_cache, du
10399
end
104100

105-
@generated function __getfield(c::T, ::Val{S}) where {T, S}
106-
hasfield(T, S) && return :(c.$(S))
107-
return :(nothing)
108-
end
109-
110-
function __safe_init_jacobian(c::SparseDiffTools.AbstractMaybeSparseJacobianCache)
111-
T = promote_type(eltype(c.fx), eltype(c.x))
112-
return __safe_init_jacobian(__getfield(c, Val(:jac_prototype)), T, c.fx, c.x)
113-
end
114-
function __safe_init_jacobian(::Nothing, ::Type{T}, fx, x) where {T}
115-
return similar(fx, T, length(fx), length(x))
116-
end
117-
function __safe_init_jacobian(J::SparseMatrixCSC, ::Type{T}, fx, x) where {T}
118-
@assert size(J, 1) == length(fx) && size(J, 2) == length(x)
119-
return T.(J)
120-
end
121-
function __safe_init_jacobian(J, ::Type{T}, fx, x) where {T}
122-
return similar(fx, T, length(fx), length(x)) # This is not safe for sparse jacobians
123-
end
124-
125101
__get_nonsparse_ad(::AutoSparseForwardDiff) = AutoForwardDiff()
126102
__get_nonsparse_ad(::AutoSparseFiniteDiff) = AutoFiniteDiff()
127103
__get_nonsparse_ad(::AutoSparseZygote) = AutoZygote()

0 commit comments

Comments
 (0)