Skip to content

Commit 68fcbbf

Browse files
committed
rm isset in favor of iscached
1 parent 029292b commit 68fcbbf

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

src/basic.jl

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,8 @@ struct ComposedOperator{T,O,C} <: AbstractSciMLOperator{T}
423423
ops::O
424424
""" cache for 3 and 5 argument mul! """
425425
cache::C
426-
""" is cache set """
427-
isset::Bool
428426

429-
function ComposedOperator(ops, cache, isset::Bool)
427+
function ComposedOperator(ops, cache)
430428
@assert !isempty(ops)
431429
for i in reverse(2:length(ops))
432430
opcurr = ops[i]
@@ -436,14 +434,12 @@ struct ComposedOperator{T,O,C} <: AbstractSciMLOperator{T}
436434
end
437435

438436
T = promote_type(eltype.(ops)...)
439-
isset = cache !== nothing
440-
new{T,typeof(ops),typeof(cache)}(ops, cache, isset)
437+
new{T,typeof(ops),typeof(cache)}(ops, cache)
441438
end
442439
end
443440

444441
function ComposedOperator(ops::AbstractSciMLOperator...; cache = nothing)
445-
isset = cache !== nothing
446-
ComposedOperator(ops, cache, isset)
442+
ComposedOperator(ops, cache)
447443
end
448444

449445
# constructors
@@ -504,7 +500,7 @@ for op in (
504500
)
505501
@eval Base.$op(L::ComposedOperator) = ComposedOperator(
506502
$op.(reverse(L.ops))...;
507-
cache=L.isset ? reverse(L.cache) : nothing,
503+
cache=iscached(L) ? reverse(L.cache) : nothing,
508504
)
509505
end
510506
Base.conj(L::ComposedOperator) = ComposedOperator(conj.(L.ops); cache=L.cache)
@@ -581,7 +577,7 @@ function cache_self(L::ComposedOperator, u::AbstractVecOrMat)
581577
end
582578

583579
function cache_internals(L::ComposedOperator, u::AbstractVecOrMat)
584-
if !(L.isset)
580+
if !iscached(L)
585581
L = cache_self(L, u)
586582
end
587583

@@ -594,7 +590,7 @@ function cache_internals(L::ComposedOperator, u::AbstractVecOrMat)
594590
end
595591

596592
function LinearAlgebra.mul!(v::AbstractVecOrMat, L::ComposedOperator, u::AbstractVecOrMat)
597-
@assert L.isset "cache needs to be set up for operator of type $(typeof(L)).
593+
@assert iscached(L) "cache needs to be set up for operator of type $(typeof(L)).
598594
set up cache by calling cache_operator(L::AbstractSciMLOperator, u::AbstractArray)"
599595

600596
vecs = (v, L.cache[1:end-1]..., u)
@@ -605,7 +601,7 @@ function LinearAlgebra.mul!(v::AbstractVecOrMat, L::ComposedOperator, u::Abstrac
605601
end
606602

607603
function LinearAlgebra.mul!(v::AbstractVecOrMat, L::ComposedOperator, u::AbstractVecOrMat, α, β)
608-
@assert L.isset "cache needs to be set up for operator of type $(typeof(L)).
604+
@assert iscached(L) "cache needs to be set up for operator of type $(typeof(L)).
609605
set up cache by calling cache_operator(L::AbstractSciMLOperator, u::AbstractArray)"
610606

611607
cache = L.cache[end]
@@ -617,7 +613,7 @@ function LinearAlgebra.mul!(v::AbstractVecOrMat, L::ComposedOperator, u::Abstrac
617613
end
618614

619615
function LinearAlgebra.ldiv!(v::AbstractVecOrMat, L::ComposedOperator, u::AbstractVecOrMat)
620-
@assert L.isset "cache needs to be set up for operator of type $(typeof(L)).
616+
@assert iscached(L) "cache needs to be set up for operator of type $(typeof(L)).
621617
set up cache by calling cache_operator(L::AbstractSciMLOperator, u::AbstractArray)"
622618

623619
vecs = (u, reverse(L.cache[1:end-1])..., v)
@@ -641,17 +637,14 @@ end
641637
struct InvertedOperator{T, LType, C} <: AbstractSciMLOperator{T}
642638
L::LType
643639
cache::C
644-
isset::Bool
645640

646-
function InvertedOperator(L::AbstractSciMLOperator{T}, cache, isset) where{T}
647-
isset = cache !== nothing
648-
new{T,typeof(L),typeof(cache)}(L, cache, isset)
641+
function InvertedOperator(L::AbstractSciMLOperator{T}, cache) where{T}
642+
new{T,typeof(L),typeof(cache)}(L, cache)
649643
end
650644
end
651645

652646
function InvertedOperator(L::AbstractSciMLOperator{T}; cache=nothing) where{T}
653-
isset = cache !== nothing
654-
InvertedOperator(L, cache, isset)
647+
InvertedOperator(L, cache)
655648
end
656649

657650
Base.inv(L::AbstractSciMLOperator) = InvertedOperator(L)
@@ -662,8 +655,8 @@ Base.:/(A::AbstractSciMLOperator, B::AbstractSciMLOperator) = A * inv(B)
662655
Base.convert(::Type{AbstractMatrix}, L::InvertedOperator) = inv(convert(AbstractMatrix, L.L))
663656

664657
Base.size(L::InvertedOperator) = size(L.L) |> reverse
665-
Base.transpose(L::InvertedOperator) = InvertedOperator(transpose(L.L); cache = L.isset ? L.cache' : nothing)
666-
Base.adjoint(L::InvertedOperator) = InvertedOperator(adjoint(L.L); cache = L.isset ? L.cache' : nothing)
658+
Base.transpose(L::InvertedOperator) = InvertedOperator(transpose(L.L); cache = iscached(L) ? L.cache' : nothing)
659+
Base.adjoint(L::InvertedOperator) = InvertedOperator(adjoint(L.L); cache = iscached(L) ? L.cache' : nothing)
667660
Base.conj(L::InvertedOperator) = InvertedOperator(conj(L.L); cache=L.cache)
668661

669662
getops(L::InvertedOperator) = (L.L,)
@@ -704,7 +697,7 @@ function LinearAlgebra.mul!(v::AbstractVecOrMat, L::InvertedOperator, u::Abstrac
704697
end
705698

706699
function LinearAlgebra.mul!(v::AbstractVecOrMat, L::InvertedOperator, u::AbstractVecOrMat, α, β)
707-
@assert L.isset "cache needs to be set up for operator of type $(typeof(L)).
700+
@assert iscached(L) "cache needs to be set up for operator of type $(typeof(L)).
708701
set up cache by calling cache_operator(L::AbstractSciMLOperator, u::AbstractArray)"
709702

710703
copy!(L.cache, v)
@@ -718,7 +711,7 @@ function LinearAlgebra.ldiv!(v::AbstractVecOrMat, L::InvertedOperator, u::Abstra
718711
end
719712

720713
function LinearAlgebra.ldiv!(L::InvertedOperator, u::AbstractVecOrMat)
721-
@assert L.isset "cache needs to be set up for operator of type $(typeof(L)).
714+
@assert iscached(L) "cache needs to be set up for operator of type $(typeof(L)).
722715
set up cache by calling cache_operator(L::AbstractSciMLOperator, u::AbstractArray)"
723716

724717
copy!(L.cache, u)

src/func.jl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ mutable struct FunctionOperator{iip,oop,T<:Number,F,Fa,Fi,Fai,Tr,P,Tt,C} <: Abst
1717
p::P
1818
""" Time """
1919
t::Tt
20-
""" Is cache set? """
21-
isset::Bool
2220
""" Cache """
2321
cache::C
2422

@@ -30,16 +28,13 @@ mutable struct FunctionOperator{iip,oop,T<:Number,F,Fa,Fi,Fai,Tr,P,Tt,C} <: Abst
3028
traits,
3129
p,
3230
t,
33-
isset,
3431
cache
3532
)
3633

3734
iip = traits.isinplace
3835
oop = traits.outofplace
3936
T = traits.T
4037

41-
isset = cache !== nothing
42-
4338
new{
4439
iip,
4540
oop,
@@ -60,7 +55,6 @@ mutable struct FunctionOperator{iip,oop,T<:Number,F,Fa,Fi,Fai,Tr,P,Tt,C} <: Abst
6055
traits,
6156
p,
6257
t,
63-
isset,
6458
cache,
6559
)
6660
end
@@ -160,7 +154,6 @@ function FunctionOperator(op,
160154
)
161155

162156
cache = zero.((input, output))
163-
isset = true
164157

165158
FunctionOperator(
166159
op,
@@ -170,7 +163,6 @@ function FunctionOperator(op,
170163
traits,
171164
p,
172165
t,
173-
isset,
174166
cache,
175167
)
176168
end
@@ -205,8 +197,7 @@ function Base.adjoint(L::FunctionOperator)
205197
p = L.p
206198
t = L.t
207199

208-
isset = L.isset
209-
cache = if isset
200+
cache = if iscached(L)
210201
cache = reverse(L.cache)
211202
else
212203
nothing
@@ -219,7 +210,6 @@ function Base.adjoint(L::FunctionOperator)
219210
traits,
220211
p,
221212
t,
222-
isset,
223213
cache,
224214
)
225215
end
@@ -249,8 +239,7 @@ function Base.inv(L::FunctionOperator)
249239
p = L.p
250240
t = L.t
251241

252-
isset = L.cache !== nothing
253-
cache = if isset
242+
cache = if iscached(L)
254243
cache = reverse(L.cache)
255244
else
256245
nothing
@@ -263,7 +252,6 @@ function Base.inv(L::FunctionOperator)
263252
traits,
264253
p,
265254
t,
266-
isset,
267255
cache,
268256
)
269257
end

src/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535

3636
function iscached(L::AbstractSciMLOperator)
3737
has_cache = hasfield(typeof(L), :cache) # TODO - confirm this is static
38-
isset = has_cache ? L.cache !== nothing : true
38+
isset = has_cache ? L.cache !== nothing : true
3939

4040
return isset & all(iscached, getops(L))
4141
end

0 commit comments

Comments
 (0)