From 4c99ca357d7a1b568d27cb4db2a35c89de671557 Mon Sep 17 00:00:00 2001 From: Michel Schanen Date: Tue, 30 Apr 2024 12:04:06 -0500 Subject: [PATCH] Support of preconditioners through adjoint() --- src/EnzymeRules/enzymerules.jl | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/EnzymeRules/enzymerules.jl b/src/EnzymeRules/enzymerules.jl index 5dc2545..834f778 100644 --- a/src/EnzymeRules/enzymerules.jl +++ b/src/EnzymeRules/enzymerules.jl @@ -155,20 +155,12 @@ for AMT in (:Matrix, :SparseMatrixCSC) if verbose > 0 @info "($psolver, $pamt) reverse" end - if M == I - nothing - elseif isa(M, IncompleteLU.ILUFactorization) - U = copy(M.U) - L = copy(M.L) - transpose!(U, M.L) - transpose!(L, M.U) - N = IncompleteLU.ILUFactorization(L, U) - M = I - else - error("Preconditioner not supported") + adjM = adjoint(N) + adjN = adjoint(M) + _b.dval .= Krylov.$solver(adjoint(A), bx[]; M=adjM, N=adjN, verbose=verbose, options...)[1] + if isa(_A, Duplicated) + _A.dval .= -x .* _b.dval' end - _b.dval .= Krylov.$solver(adjoint(A), bx[]; M=M, N=N, verbose=verbose, options...)[1] - _A.dval .= -x .* _b.dval' return (nothing, nothing) end end