IterativeSolvers.jl icon indicating copy to clipboard operation
IterativeSolvers.jl copied to clipboard

Simple diagonal preconditioners for linear maps

Open clason opened this issue 7 years ago • 3 comments

The following used to work

δx = cg(H, g; Pl=x -> ([πe;πte]) .\ x, tol=γ, maxiter=N)    

where H is a LinearMap and Pl implements a diagonal preconditioner for it (I don't think the details are relevant, but let me know if you need more code), but now gives a

ERROR: LoadError: MethodError: no method matching ldiv!(::Array{Float64,1}, ::getfield(Main, Symbol("##3#6")){Array{Float64,1},Array{Float64,1}}, ::Array{Float64,1})

What is now the recommended way of implementing such a simple preconditioner? Do I need to define a full structure implementing all the different methods from the manual (which seems like overkill)?

clason avatar Aug 17 '18 11:08 clason

See this https://github.com/JuliaMath/IterativeSolvers.jl/blob/01af27fe76069e6be566abfd862664f928997638/test/cg.jl#L12 for reference. There is only one function to be defined ldiv!(y, P, x).

mohdibntarek avatar Aug 22 '18 03:08 mohdibntarek

Yes, that works, thank you!

Still, for this use case, the old behavior was much more convenient. Could I make the feature request to again provide a method that accepts an anonymous function for Pl -- or was there some compelling technical reason for dropping this?

Another convenience function might be to accept a LinearMap representing $P^{-1}$ -- i.e., whose mul! function implements ldiv! for $P$.

clason avatar Aug 22 '18 10:08 clason

Check out Preconditioners.jl, which lets you do Pl = DiagonalPreconditioner([πe;πte]).

mohdibntarek avatar Jan 15 '19 22:01 mohdibntarek