-
-
Notifications
You must be signed in to change notification settings - Fork 72
Make FastLapackInterface.jl an extension as well #572
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||||
module LinearSolveFastLapackInterfaceExt | ||||||||
|
||||||||
using LinearSolve, LinearAlgebra | ||||||||
using FastLapackInterface | ||||||||
|
||||||||
struct WorkspaceAndFactors{W, F} | ||||||||
workspace::W | ||||||||
factors::F | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval(::FastLUFactorization, A, b, u, Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||
assumptions::OperatorAssumptions) | ||||||||
ws = LUWs(A) | ||||||||
return WorkspaceAndFactors(ws, LinearSolve.ArrayInterface.lu_instance(convert(AbstractMatrix, A))) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
end | ||||||||
|
||||||||
function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::FastLUFactorization; kwargs...) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
A = cache.A | ||||||||
A = convert(AbstractMatrix, A) | ||||||||
ws_and_fact = LinearSolve.@get_cacheval(cache, :FastLUFactorization) | ||||||||
if cache.isfresh | ||||||||
# we will fail here if A is a different *size* than in a previous version of the same cache. | ||||||||
# it may instead be desirable to resize the workspace. | ||||||||
LinearSolve.@set! ws_and_fact.factors = LinearAlgebra.LU(LAPACK.getrf!(ws_and_fact.workspace, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
A)...) | ||||||||
cache.cacheval = ws_and_fact | ||||||||
cache.isfresh = false | ||||||||
end | ||||||||
y = ldiv!(cache.u, cache.cacheval.factors, cache.b) | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache) | ||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval(alg::FastQRFactorization{NoPivot}, A::AbstractMatrix, b, u, Pl, Pr, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||
assumptions::OperatorAssumptions) | ||||||||
ws = QRWYWs(A; blocksize = alg.blocksize) | ||||||||
return WorkspaceAndFactors(ws, | ||||||||
LinearSolve.ArrayInterface.qr_instance(convert(AbstractMatrix, A))) | ||||||||
end | ||||||||
function LinearSolve.init_cacheval(::FastQRFactorization{ColumnNorm}, A::AbstractMatrix, b, u, Pl, Pr, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||
assumptions::OperatorAssumptions) | ||||||||
ws = QRpWs(A) | ||||||||
return WorkspaceAndFactors(ws, | ||||||||
LinearSolve.ArrayInterface.qr_instance(convert(AbstractMatrix, A))) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
end | ||||||||
|
||||||||
function LinearSolve.init_cacheval(alg::FastQRFactorization, A, b, u, Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||
assumptions::OperatorAssumptions) | ||||||||
return init_cacheval(alg, convert(AbstractMatrix, A), b, u, Pl, Pr, | ||||||||
maxiters::Int, abstol, reltol, verbose::Bool, | ||||||||
assumptions::OperatorAssumptions) | ||||||||
end | ||||||||
|
||||||||
function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::FastQRFactorization{P}; | ||||||||
kwargs...) where {P} | ||||||||
A = cache.A | ||||||||
A = convert(AbstractMatrix, A) | ||||||||
ws_and_fact = LinearSolve.@get_cacheval(cache, :FastQRFactorization) | ||||||||
if cache.isfresh | ||||||||
# we will fail here if A is a different *size* than in a previous version of the same cache. | ||||||||
# it may instead be desirable to resize the workspace. | ||||||||
if P === NoPivot | ||||||||
LinearSolve.@set! ws_and_fact.factors = LinearAlgebra.QRCompactWY(LAPACK.geqrt!( | ||||||||
ws_and_fact.workspace, | ||||||||
A)...) | ||||||||
else | ||||||||
LinearSolve.@set! ws_and_fact.factors = LinearAlgebra.QRPivoted(LAPACK.geqp3!( | ||||||||
ws_and_fact.workspace, | ||||||||
A)...) | ||||||||
end | ||||||||
cache.cacheval = ws_and_fact | ||||||||
cache.isfresh = false | ||||||||
end | ||||||||
y = ldiv!(cache.u, cache.cacheval.factors, cache.b) | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache) | ||||||||
end | ||||||||
|
||||||||
|
||||||||
end | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶