Skip to content

Commit 65c10e6

Browse files
committed
optimize StaticWOperator by using lu to allow saving the factorization
1 parent dc0e1e7 commit 65c10e6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
const ROSENBROCK_INV_CUTOFF = 7 # https://github.com/SciML/OrdinaryDiffEq.jl/pull/1539
22

3-
struct StaticWOperator{isinv, T} <: AbstractSciMLOperator{T}
3+
struct StaticWOperator{isinv, T, F} <: AbstractSciMLOperator{T}
44
W::T
5+
F::F
56
function StaticWOperator(W::T, callinv = true) where {T}
67
isinv = size(W, 1) <= ROSENBROCK_INV_CUTOFF
78

9+
F = lu(W, check=false)
810
# when constructing W for the first time for the type
911
# inv(W) can be singular
1012
_W = if isinv && callinv
11-
inv(W)
13+
F\typeof(W)(I)
1214
else
1315
W
1416
end
15-
new{isinv, T}(_W)
17+
new{isinv, T, typeof(F)}(_W, F)
1618
end
1719
end
1820
isinv(W::StaticWOperator{S}) where {S} = S
19-
Base.:\(W::StaticWOperator, v::AbstractArray) = isinv(W) ? W.W * v : W.W \ v
21+
Base.:\(W::StaticWOperator, v::AbstractArray) = isinv(W) ? W.W * v : W.F \ v
2022

2123
function calc_tderivative!(integrator, cache, dtd1, repeat_step)
2224
@inbounds begin

0 commit comments

Comments
 (0)