Skip to content

Commit

Permalink
Merge pull request #16 from avik-pal/ap/gmres
Browse files Browse the repository at this point in the history
Add Krylov.jl wrapper
  • Loading branch information
ChrisRackauckas authored Oct 7, 2021
2 parents 4579213 + 12be621 commit 55e82cf
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 236 deletions.
24 changes: 8 additions & 16 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI
on:
# - push
- push
- pull_request
jobs:
test:
Expand Down Expand Up @@ -42,21 +42,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@latest
with:
version: '1'
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using LinearSolvers
DocMeta.setdocmeta!(LinearSolvers, :DocTestSetup, :(using LinearSolvers); recursive=true)
doctest(LinearSolvers)'
- run: julia --project=docs docs/make.jl
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ docs/make.jl
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.1.0"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
Expand All @@ -14,7 +14,6 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"

[compat]
ArrayInterface = "3"
IterativeSolvers = "0.9"
Reexport = "1"
SciMLBase = "1.18.6"
Setfield = "0.7, 0.8"
Expand Down
92 changes: 0 additions & 92 deletions docs/Manifest.toml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/Project.toml
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"
12 changes: 6 additions & 6 deletions docs/make.jl
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=[
Expand All @@ -19,5 +19,5 @@ makedocs(;
)

deploydocs(;
repo="github.com/EdelmanJonathan/LinearSolvers.jl",
repo="github.com/SciML/LinearSolve.jl",
)
8 changes: 4 additions & 4 deletions docs/src/index.md
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]
```
124 changes: 12 additions & 112 deletions src/LinearSolve.jl
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
Loading

0 comments on commit 55e82cf

Please sign in to comment.