JuliaLinearAlgebra / IterativeSolvers.jl

Iterative algorithms for solving linear systems, eigensystems, and singular value problems
MIT License
399 stars 105 forks source link

Simple diagonal preconditioners for linear maps #221

Closed clason closed 1 month ago

clason commented 6 years ago

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)?

mohamed82008 commented 6 years ago

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).

clason commented 6 years ago

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$.

mohamed82008 commented 5 years ago

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