-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from avik-pal/ap/gmres
Add Krylov.jl wrapper
- Loading branch information
Showing
11 changed files
with
200 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[deps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
LinearSolvers = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" | ||
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
using LinearSolvers | ||
using LinearSolve | ||
using Documenter | ||
|
||
DocMeta.setdocmeta!(LinearSolvers, :DocTestSetup, :(using LinearSolvers); recursive=true) | ||
DocMeta.setdocmeta!(LinearSolve, :DocTestSetup, :(using LinearSolve); recursive=true) | ||
|
||
makedocs(; | ||
modules=[LinearSolvers], | ||
modules=[LinearSolve], | ||
authors="Jonathan <[email protected]> and contributors", | ||
repo="https://github.com/EdelmanJonathan/LinearSolvers.jl/blob/{commit}{path}#{line}", | ||
repo="https://github.com/SciML/LinearSolve.jl/blob/{commit}{path}#{line}", | ||
sitename="LinearSolvers.jl", | ||
format=Documenter.HTML(; | ||
prettyurls=get(ENV, "CI", "false") == "true", | ||
canonical="https://EdelmanJonathan.github.io/LinearSolvers.jl", | ||
canonical="https://linearsolve.sciml.ai/", | ||
assets=String[], | ||
), | ||
pages=[ | ||
|
@@ -19,5 +19,5 @@ makedocs(; | |
) | ||
|
||
deploydocs(; | ||
repo="github.com/EdelmanJonathan/LinearSolvers.jl", | ||
repo="github.com/SciML/LinearSolve.jl", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
```@meta | ||
CurrentModule = LinearSolvers | ||
CurrentModule = LinearSolve | ||
``` | ||
|
||
# LinearSolvers | ||
# LinearSolve | ||
|
||
Documentation for [LinearSolvers](https://github.com/EdelmanJonathan/LinearSolvers.jl). | ||
Documentation for [LinearSolve](https://github.com/SciML/LinearSolve.jl). | ||
|
||
```@index | ||
``` | ||
|
||
```@autodocs | ||
Modules = [LinearSolvers] | ||
Modules = [LinearSolve] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,23 @@ | ||
module LinearSolve | ||
|
||
using Base: cache_dependencies, Bool | ||
using SciMLBase: AbstractLinearAlgorithm, AbstractDiffEqOperator | ||
using ArrayInterface: lu_instance | ||
using UnPack | ||
using Reexport | ||
using Base: cache_dependencies, Bool | ||
using Krylov | ||
using LinearAlgebra | ||
using Reexport | ||
using SciMLBase: AbstractDiffEqOperator, AbstractLinearAlgorithm | ||
using Setfield | ||
@reexport using SciMLBase | ||
|
||
export LUFactorization, QRFactorization, SVDFactorization | ||
|
||
#mutable?# | ||
struct LinearCache{TA,Tb,Tp,Talg,Tc,Tr,Tl} | ||
A::TA | ||
b::Tb | ||
p::Tp | ||
alg::Talg | ||
cacheval::Tc | ||
isfresh::Bool | ||
Pr::Tr | ||
Pl::Tl | ||
end | ||
|
||
function set_A(cache, A) | ||
@set! cache.A = A | ||
@set! cache.isfresh = true | ||
end | ||
|
||
function set_b(cache, b) | ||
@set! cache.b = b | ||
end | ||
|
||
function set_p(cache, p) | ||
@set! cache.p = p | ||
# @set! cache.isfresh = true | ||
end | ||
|
||
function set_cacheval(cache::LinearCache,alg) | ||
if cache.isfresh | ||
@set! cache.cacheval = alg | ||
@set! cache.isfresh = false | ||
end | ||
return cache | ||
end | ||
|
||
function SciMLBase.init(prob::LinearProblem, alg; | ||
alias_A = false, alias_b = false, | ||
kwargs...) | ||
@unpack A, b, p = prob | ||
if alg isa LUFactorization | ||
fact = lu_instance(A) | ||
Tfact = typeof(fact) | ||
else | ||
fact = nothing | ||
Tfact = Any | ||
end | ||
Pr = nothing | ||
Pl = nothing | ||
|
||
A = alias_A ? A : copy(A) | ||
b = alias_b ? b : copy(b) | ||
|
||
cache = LinearCache{typeof(A),typeof(b),typeof(p),typeof(alg),Tfact,typeof(Pr),typeof(Pl)}( | ||
A, b, p, alg, fact, true, Pr, Pl | ||
) | ||
return cache | ||
end | ||
|
||
SciMLBase.solve(prob::LinearProblem, alg; kwargs...) = solve(init(prob, alg; kwargs...)) | ||
SciMLBase.solve(cache) = solve(cache, cache.alg) | ||
|
||
struct LUFactorization{P} <: AbstractLinearAlgorithm | ||
pivot::P | ||
end | ||
function LUFactorization() | ||
pivot = @static if VERSION < v"1.7beta" | ||
Val(true) | ||
else | ||
RowMaximum() | ||
end | ||
LUFactorization(pivot) | ||
end | ||
|
||
function SciMLBase.solve(cache::LinearCache, alg::LUFactorization) | ||
cache.A isa Union{AbstractMatrix, AbstractDiffEqOperator} || error("LU is not defined for $(typeof(prob.A))") | ||
cache = set_cacheval(cache,lu!(cache.A, alg.pivot)) | ||
ldiv!(cache.cacheval, cache.b) | ||
end | ||
using UnPack | ||
|
||
struct QRFactorization{P} <: AbstractLinearAlgorithm | ||
pivot::P | ||
blocksize::Int | ||
end | ||
function QRFactorization() | ||
pivot = @static if VERSION < v"1.7beta" | ||
Val(false) | ||
else | ||
NoPivot() | ||
end | ||
QRFactorization(pivot, 16) | ||
end | ||
@reexport using SciMLBase | ||
|
||
function SciMLBase.solve(cache::LinearCache, alg::QRFactorization) | ||
cache.A isa Union{AbstractMatrix, AbstractDiffEqOperator} || error("QR is not defined for $(typeof(prob.A))") | ||
cache = set_cacheval(cache,qr!(cache.A.A, alg.pivot; blocksize=alg.blocksize)) | ||
ldiv!(cache.cacheval, cache.b) | ||
end | ||
abstract type SciMLLinearSolveAlgorithm end | ||
|
||
struct SVDFactorization{A} <: AbstractLinearAlgorithm | ||
full::Bool | ||
alg::A | ||
end | ||
SVDFactorization() = SVDFactorization(false, LinearAlgebra.DivideAndConquer()) | ||
include("common.jl") | ||
include("factorization.jl") | ||
include("krylov.jl") | ||
|
||
function SciMLBase.solve(cache::LinearCache, alg::SVDFactorization) | ||
cache.A isa Union{AbstractMatrix, AbstractDiffEqOperator} || error("SVD is not defined for $(typeof(prob.A))") | ||
cache = set_cacheval(cache,svd!(cache.A; full=alg.full, alg=alg.alg)) | ||
ldiv!(cache.cacheval, cache.b) | ||
end | ||
export LUFactorization, SVDFactorization, QRFactorization | ||
export KrylovJL | ||
|
||
end |
Oops, something went wrong.