Skip to content

Commit 83335a0

Browse files
authored
Merge pull request #188 from vpuri3/inv
fix InvertibleOperator caching, add tests
2 parents 8ff4225 + 1225300 commit 83335a0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/matrix.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ islinear(L::InvertibleOperator) = islinear(L.L)
238238
has_ldiv(L::InvertibleOperator) = has_mul(L.F)
239239
has_ldiv!(L::InvertibleOperator) = has_ldiv!(L.F)
240240

241+
function cache_internals(L::InvertibleOperator, u::AbstractVecOrMat)
242+
243+
@set! L.L = cache_operator(L.L, u)
244+
@set! L.F = cache_operator(L.F, u)
245+
246+
L
247+
end
248+
241249
# operator application
242250
Base.:*(L::InvertibleOperator, x::AbstractVecOrMat) = L.L * x
243251
Base.:\(L::InvertibleOperator, x::AbstractVecOrMat) = L.F \ x

test/matrix.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using SciMLOperators, LinearAlgebra
22
using Random
33

4-
using SciMLOperators: InvertibleOperator,
4+
using SciMLOperators: InvertibleOperator, InvertedOperator,
55
using FFTW
66

77
Random.seed!(0)
@@ -60,6 +60,32 @@ K = 19
6060
v=rand(N,K); w=copy(v); @test mul!(v, AA, u, α, β) α*A*u + β*w
6161
end
6262

63+
@testset "InvertibleOperator test" begin
64+
u = rand(N,K)
65+
p = nothing
66+
t = 0
67+
α = rand()
68+
β = rand()
69+
70+
d = rand(N, K)
71+
D = DiagonalOperator(d)
72+
Di = DiagonalOperator(inv.(d)) |> InvertedOperator
73+
74+
L = InvertibleOperator(D, Di)
75+
L = cache_operator(L, u)
76+
77+
@test iscached(L)
78+
79+
@test L * u d .* u
80+
@test L \ u d .\ u
81+
82+
v=rand(N,K); @test mul!(v, L, u) d .* u
83+
v=rand(N,K); w=copy(v); @test mul!(v, L, u, α, β) α*(d .* u) + β*w
84+
85+
v=rand(N,K); @test ldiv!(v, L, u) d .\ u
86+
v=copy(u); @test ldiv!(L, v) d .\ u
87+
end
88+
6389
@testset "MatrixOperator update test" begin
6490
u = rand(N,K)
6591
p = rand(N)

0 commit comments

Comments
 (0)