From b5b929824b2bc922ecc828357969ffffbe0284fa Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Thu, 5 Oct 2023 21:22:01 -0400 Subject: [PATCH] upstream fix to SparseDiffTools.jl --- src/jacobian.jl | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/jacobian.jl b/src/jacobian.jl index d9327e701..82f2ef2bb 100644 --- a/src/jacobian.jl +++ b/src/jacobian.jl @@ -80,11 +80,7 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p, ::Val{ii if has_analytic_jac f.jac_prototype === nothing ? undefmatrix(u) : f.jac_prototype else - if f.jac_prototype === nothing - __safe_init_jacobian(jac_cache) - else - f.jac_prototype - end + f.jac_prototype === nothing ? init_jacobian(jac_cache) : f.jac_prototype end end @@ -102,26 +98,6 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f, u, p, ::Val{ii return uf, linsolve, J, fu, jac_cache, du end -@generated function __getfield(c::T, ::Val{S}) where {T, S} - hasfield(T, S) && return :(c.$(S)) - return :(nothing) -end - -function __safe_init_jacobian(c::SparseDiffTools.AbstractMaybeSparseJacobianCache) - T = promote_type(eltype(c.fx), eltype(c.x)) - return __safe_init_jacobian(__getfield(c, Val(:jac_prototype)), T, c.fx, c.x) -end -function __safe_init_jacobian(::Nothing, ::Type{T}, fx, x) where {T} - return similar(fx, T, length(fx), length(x)) -end -function __safe_init_jacobian(J::SparseMatrixCSC, ::Type{T}, fx, x) where {T} - @assert size(J, 1) == length(fx) && size(J, 2) == length(x) - return T.(J) -end -function __safe_init_jacobian(J, ::Type{T}, fx, x) where {T} - return similar(fx, T, length(fx), length(x)) # This is not safe for sparse jacobians -end - __get_nonsparse_ad(::AutoSparseForwardDiff) = AutoForwardDiff() __get_nonsparse_ad(::AutoSparseFiniteDiff) = AutoFiniteDiff() __get_nonsparse_ad(::AutoSparseZygote) = AutoZygote()