@@ -286,11 +286,21 @@ struct FunctionOperator{isinplace,T,F,Fa,Fi,Fai,Tr,P,Tt,C} <: AbstractSciMLOpera
286286 """ Cache """
287287 cache:: C
288288
289- function FunctionOperator (op, op_adjoint, op_inverse, op_adjoint_inverse, traits, p, t, isset, cache)
289+ function FunctionOperator (op,
290+ op_adjoint,
291+ op_inverse,
292+ op_adjoint_inverse,
293+ traits,
294+ p,
295+ t,
296+ isset,
297+ cache
298+ )
299+
290300 iip = traits. isinplace
291301 T = traits. T
292302
293- isset = cache isa Nothing
303+ isset = cache != = nothing
294304
295305 new{iip,
296306 T,
@@ -303,7 +313,15 @@ struct FunctionOperator{isinplace,T,F,Fa,Fi,Fai,Tr,P,Tt,C} <: AbstractSciMLOpera
303313 typeof (t),
304314 typeof (cache),
305315 }(
306- op, op_adjoint, op_inverse, op_adjoint_inverse, traits, p, t, isset, cache,
316+ op,
317+ op_adjoint,
318+ op_inverse,
319+ op_adjoint_inverse,
320+ traits,
321+ p,
322+ t,
323+ isset,
324+ cache,
307325 )
308326 end
309327end
@@ -367,7 +385,7 @@ function FunctionOperator(op;
367385 size = size,
368386 )
369387
370- isset = cache isa Nothing
388+ isset = cache != = nothing
371389
372390 FunctionOperator (
373391 op,
@@ -411,10 +429,19 @@ function Base.adjoint(L::FunctionOperator)
411429 t = L. t
412430
413431 cache = issquare (L) ? cache : nothing
414- isset = cache isa Nothing
432+ isset = cache != = nothing
415433
416434
417- FuncitonOperator (op, op_adjoint, op_inverse, op_adjoint_inverse, traits, p, t, isset, cache)
435+ FuncitonOperator (op,
436+ op_adjoint,
437+ op_inverse,
438+ op_adjoint_inverse,
439+ traits,
440+ p,
441+ t,
442+ isset,
443+ cache
444+ )
418445end
419446
420447function LinearAlgebra. opnorm (L:: FunctionOperator , p)
@@ -441,7 +468,7 @@ has_ldiv!(L::FunctionOperator{iip}) where{iip} = iip & !(L.op_inverse isa Nothin
441468Base.:* (L:: FunctionOperator , u:: AbstractVector ) = L. op (u, L. p, L. t)
442469Base.:\ (L:: FunctionOperator , u:: AbstractVector ) = L. op_inverse (u, L. p, L. t)
443470
444- function update_cache (L:: FunctionOperator , u:: AbstractVector )
471+ function cache_operator (L:: FunctionOperator , u:: AbstractVector )
445472 @set! L. cache = similar (u)
446473 L
447474end
@@ -451,22 +478,20 @@ function LinearAlgebra.mul!(v::AbstractVector, L::FunctionOperator, u::AbstractV
451478end
452479
453480function LinearAlgebra. mul! (v:: AbstractVector , L:: FunctionOperator , u:: AbstractVector , α, β)
454- try
455- L. op (v, u, L. p, L. t, α, β)
456- catch
457- copy! (L. cache, v)
458- mul! (v, u, L. p, L. t)
459- lmul! (α, v)
460- axpy! (β, L. cache, v)
461- end
481+ @assert L. isset " set up cache by calling cache_operator($L , $u )"
482+ copy! (L. cache, v)
483+ mul! (v, L, u)
484+ lmul! (α, v)
485+ axpy! (β, L. cache, v)
462486end
463487
464488function LinearAlgebra. ldiv! (v:: AbstractVector , L:: FunctionOperator , u:: AbstractVector )
465489 L. op_inverse (v, u, L. p, L. t)
466490end
467491
468492function LinearAlgebra. ldiv! (L:: FunctionOperator , u:: AbstractVector )
493+ @assert L. isset " set up cache by calling cache_operator($L , $u )"
469494 copy! (L. cache, u)
470- L . op_inverse (u, L. cache , L. p, L . t )
495+ ldiv! (u, L, L. cache )
471496end
472497#
0 commit comments