Skip to content

Commit 9474b35

Browse files
committed
improve performance
1 parent dc0161e commit 9474b35

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ using DiffEqBase
1515

1616
import LinearAlgebra
1717
import LinearAlgebra: Diagonal, I, UniformScaling, diagind, mul!, lmul!, axpby!, opnorm, lu
18+
import LinearAlgebra: LowerTriangular, UpperTriangular
1819
import SparseArrays: SparseMatrixCSC, AbstractSparseMatrix, nonzeros
1920

2021
import InteractiveUtils
2122
import ArrayInterface
2223

2324
import StaticArrayInterface
25+
import StaticArrays
2426
import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA,
2527
StaticMatrix
2628

lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ struct StaticWOperator{isinv, T, F} <: AbstractSciMLOperator{T}
44
W::T
55
F::F
66
function StaticWOperator(W::T, callinv = true) where {T}
7-
isinv = size(W, 1) <= ROSENBROCK_INV_CUTOFF
7+
n = size(W, 1)
8+
isinv = n <= ROSENBROCK_INV_CUTOFF
89

9-
F = lu(W, check=false)
10+
F = if isinv && callinv
11+
# this should be in ArrayInterface but can't be for silly reasons
12+
# doing to how StaticArrays and StaticArraysCore are split up
13+
StaticArrays.LU(LowerTriangular(W), UpperTriangular(W), SVector{n}(1:n))
14+
else
15+
lu(W, check=false)
16+
end
1017
# when constructing W for the first time for the type
1118
# inv(W) can be singular
1219
_W = if isinv && callinv
13-
F\typeof(W)(I)
20+
inv(W)
1421
else
1522
W
1623
end

0 commit comments

Comments
 (0)