@@ -142,10 +142,16 @@ end
142
142
# # Numbers
143
143
function (cache:: JacobianCache{<:Number} )(:: Number , u, p = cache. p)
144
144
cache. stats. njacs += 1
145
- SciMLBase. has_jac (cache. f) && return cache. f. jac (u, p)
146
- SciMLBase. has_vjp (cache. f) && return cache. f. vjp (one (u), u, p)
147
- SciMLBase. has_jvp (cache. f) && return cache. f. jvp (one (u), u, p)
148
- return DI. derivative (cache. f, cache. di_extras, cache. autodiff, u, Constant (p))
145
+ cache. J = if SciMLBase. has_jac (cache. f)
146
+ cache. f. jac (u, p)
147
+ elseif SciMLBase. has_vjp (cache. f)
148
+ cache. f. vjp (one (u), u, p)
149
+ elseif SciMLBase. has_jvp (cache. f)
150
+ cache. f. jvp (one (u), u, p)
151
+ else
152
+ DI. derivative (cache. f, cache. di_extras, cache. autodiff, u, Constant (p))
153
+ end
154
+ return cache. J
149
155
end
150
156
151
157
# # Actually Compute the Jacobian
@@ -156,12 +162,17 @@ function (cache::JacobianCache)(J::Union{AbstractMatrix, Nothing}, u, p = cache.
156
162
cache. f. jac (J, u, p)
157
163
else
158
164
DI. jacobian! (
159
- cache. f, cache. fu, J, cache. di_extras, cache. autodiff, u, Constant (p))
165
+ cache. f, cache. fu, J, cache. di_extras, cache. autodiff, u, Constant (p)
166
+ )
160
167
end
161
168
return J
162
169
else
163
- SciMLBase. has_jac (cache. f) && return cache. f. jac (u, p)
164
- return DI. jacobian (cache. f, cache. di_extras, cache. autodiff, u, Constant (p))
170
+ if SciMLBase. has_jac (cache. f)
171
+ cache. J = cache. f. jac (u, p)
172
+ else
173
+ cache. J = DI. jacobian (cache. f, cache. di_extras, cache. autodiff, u, Constant (p))
174
+ end
175
+ return cache. J
165
176
end
166
177
end
167
178
0 commit comments