@@ -99,10 +99,15 @@ function JacobianCache(prob, alg, f::F, fu_, u, p; stats, autodiff = nothing,
99
99
# While this is technically wasteful, it gives out the type of the Jacobian
100
100
# which is needed to create the linear solver cache
101
101
stats. njacs += 1
102
- if iip
103
- DI. jacobian (f, fu, di_extras, autodiff, u, Constant (p))
102
+ if has_analytic_jac
103
+ __similar (
104
+ fu, promote_type (eltype (fu), eltype (u)), length (fu), length (u))
104
105
else
105
- DI. jacobian (f, autodiff, u, Constant (p))
106
+ if iip
107
+ DI. jacobian (f, fu, di_extras, autodiff, u, Constant (p))
108
+ else
109
+ DI. jacobian (f, autodiff, u, Constant (p))
110
+ end
106
111
end
107
112
else
108
113
zero (init_jacobian (sdifft_extras; preserve_immutable = Val (true )))
@@ -120,9 +125,10 @@ function JacobianCache(prob, alg, f::F, ::Number, u::Number, p; stats,
120
125
autodiff = nothing , kwargs... ) where {F}
121
126
fu = f (u, p)
122
127
if SciMLBase. has_jac (f) || SciMLBase. has_vjp (f) || SciMLBase. has_jvp (f)
123
- return JacobianCache {false} (u, f, fu, u, p, stats, autodiff, nothing )
128
+ return JacobianCache {false} (u, f, fu, u, p, stats, autodiff, nothing , nothing )
124
129
end
125
- autodiff = get_concrete_forward_ad (autodiff, prob; check_forward_mode = false )
130
+ autodiff = get_dense_ad (get_concrete_forward_ad (
131
+ autodiff, prob; check_forward_mode = false ))
126
132
di_extras = DI. prepare_derivative (f, get_dense_ad (autodiff), u, Constant (prob. p))
127
133
return JacobianCache {false} (u, f, fu, u, p, stats, autodiff, di_extras, nothing )
128
134
end
0 commit comments