How to pass a matrix free preconditioner to IterativeSolver of KrylovKit?

Say I have a matrix A and a linear function P that takes as argument a vector and returns a vector of the same size. How can I use a preconditioned conjugate gradient from IterativeSolver.jl of KrylovKit.jl for solving Ax=b preconditioned by P?

Hi Frédéric,

One way to achieve this would be create a type that wraps your function, say the identity function

foo(x) = x

then create a type to wrap your function

struct MyPreconditioner{F}
P = MyPreconditioner(foo)

and finally add whatever method IterativeSolver.jl or KrylovKit.jl will need :

using LinearAlgebra
LinearAlgebra.ldiv!(y, P::MyPreconditioner, x) = y .=
1 Like

IterativeSolvers.jl requires ldiv! and \: Preconditioning · IterativeSolvers.jl

KrylovKit.jl doesn’t currently support preconditioning (Preconditionning · Issue #7 · Jutho/KrylovKit.jl · GitHub).

many thanks!


You can easily use left preconditioning in KrylovKit, see here