Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP adjoint #126

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct LinearCache{TA,Tb,Tu,Tp,Talg,Tc,Tl,Tr,Ttol}
isfresh::Bool # false => cacheval is set wrt A, true => update cacheval wrt A
Pl::Tl # preconditioners
Pr::Tr
solve_adjoint::Bool # solve adjoint problem
abstol::Ttol
reltol::Ttol
maxiters::Int
Expand Down Expand Up @@ -77,6 +78,7 @@ default_tol(::Type{Any}) = 0

function SciMLBase.init(prob::LinearProblem, alg::Union{SciMLLinearSolveAlgorithm,Nothing}, args...;
alias_A = false, alias_b = false,
solve_adjoint = false,
abstol=default_tol(eltype(prob.A)),
reltol=default_tol(eltype(prob.A)),
maxiters=length(prob.b),
Expand All @@ -94,6 +96,11 @@ function SciMLBase.init(prob::LinearProblem, alg::Union{SciMLLinearSolveAlgorith
fill!(u0,false)
end

if solve_adjoint & !(alg isa Union{AbstractFactorization,
AbstractSolveFunction})
A = A'
Comment on lines +99 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exclude? It should be done for all algs?

end

cacheval = init_cacheval(alg, A, b, u0, Pl, Pr, maxiters, abstol, reltol, verbose)
isfresh = true
Tc = typeof(cacheval)
Expand Down Expand Up @@ -121,6 +128,7 @@ function SciMLBase.init(prob::LinearProblem, alg::Union{SciMLLinearSolveAlgorith
isfresh,
Pl,
Pr,
solve_adjoint,
abstol,
reltol,
maxiters,
Expand Down
4 changes: 3 additions & 1 deletion src/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ function SciMLBase.solve(cache::LinearCache, alg::AbstractFactorization; kwargs.
fact = do_factorization(alg, cache.A, cache.b, cache.u)
cache = set_cacheval(cache, fact)
end
y = _ldiv!(cache.u, cache.cacheval, cache.b)
fact = cache.solve_adjoint ? cache.cacheval' : cache.cacheval

y = _ldiv!(cache.u, fact, cache.b)
Comment on lines +14 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why adjoint the factorization object?

SciMLBase.build_linear_solution(alg,y,nothing,cache)
end

Expand Down