@@ -113,6 +113,7 @@ function TangentDynamicalSystem(ds::CoreDynamicalSystem{IIP};
113
113
u0_correct = correct_state (Val {IIP} (), u0)
114
114
Q0_correct = correct_matrix_type (Val {IIP} (), Q0)
115
115
newstate = hcat (u0_correct, Q0_correct)
116
+ J = isnothing (J) ? jacobian (ds) : J
116
117
newrule = tangent_rule (f, J, J0, Val {IIP} (), Val {k} (), u0_correct)
117
118
118
119
# Pass everything to analytic system constructors
@@ -149,37 +150,12 @@ function tangent_rule(f::F, J::JAC, J0, ::Val{true}, ::Val{k}, u0) where {F, JAC
149
150
end
150
151
return tangentf
151
152
end
152
- # for the case of autodiffed systems, a specialized version is created
153
- # so that f! is not called twice in ForwardDiff
154
- function tangent_rule (f:: F , :: Nothing , J0, :: Val{true} , :: Val{k} , u0) where {F, k}
155
- let
156
- cfg = ForwardDiff. JacobianConfig (
157
- (du, u) -> f (du, u, p, p), deepcopy (u0), deepcopy (u0)
158
- )
159
- tangentf = (du, u, p, t) -> begin
160
- uv = @view u[:, 1 ]
161
- ForwardDiff. jacobian! (
162
- J0, (du, u) -> f (du, u, p, t), view (du, :, 1 ), uv, cfg, Val {false} ()
163
- )
164
- mul! ((@view du[:, 2 : k+ 1 ]), J0, (@view u[:, 2 : k+ 1 ]))
165
- nothing
166
- end
167
- return tangentf
168
- end
169
- end
170
153
171
154
# OOP Tangent space dynamics
172
155
function tangent_rule (f:: F , J:: JAC , J0, :: Val{false} , :: Val{k} , u0) where {F, JAC, k}
173
- # out of place
174
- if JAC == Nothing
175
- # There is no config needed here
176
- Jf = (u, p, t) -> ForwardDiff. jacobian ((x) -> f (x, p, t), u)
177
- else
178
- Jf = J
179
- end
180
156
# Initial matrix `J0` is ignored
181
157
ws_index = SVector {k, Int} (2 : (k+ 1 ). .. )
182
- tangentf = TangentOOP (f, Jf , ws_index)
158
+ tangentf = TangentOOP (f, J , ws_index)
183
159
return tangentf
184
160
end
185
161
struct TangentOOP{F, JAC, k} <: Function
0 commit comments