Skip to content

Commit 23bf1f6

Browse files
committed
small changes
1 parent 623e45c commit 23bf1f6

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

src/LinearSolve.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module LinearSolve
33
using ArrayInterface: lu_instance
44
using Base: cache_dependencies, Bool
55
using LinearAlgebra
6-
using Reexport
76
using SciMLBase: AbstractDiffEqOperator, AbstractLinearAlgorithm
87
using Setfield
98
using UnPack
@@ -13,6 +12,7 @@ import Krylov
1312
import KrylovKit
1413
import IterativeSolvers
1514

15+
using Reexport
1616
@reexport using SciMLBase
1717

1818
abstract type SciMLLinearSolveAlgorithm <: SciMLBase.AbstractLinearAlgorithm end
@@ -22,6 +22,6 @@ include("factorization.jl")
2222
include("krylov.jl")
2323

2424
export LUFactorization, SVDFactorization, QRFactorization
25-
export KrylovJL
25+
export KrylovJL, IterativeSolversJL, KrylovKitJL
2626

2727
end

src/default.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
mutable struct DefaultLinSolve
3+
iterable
4+
end
5+
6+
DefaultLinSolve() = DefaultLinSolve(nothing, nothing, nothing)
7+
8+
function SciMLBase.solve(cache::LinearCache,
9+
alg::DefaultLinSolve,
10+
args...;kwargs...)
11+
@unpack iterable = alg
12+
@unpack A, b, u, cacheval = cache
13+
14+
return A \ u
15+
end
16+
17+
18+
function

src/factorization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ SVDFactorization() = SVDFactorization(false, LinearAlgebra.DivideAndConquer())
5252

5353
function SciMLBase.solve(cache::LinearCache, alg::SVDFactorization)
5454
cache.A isa Union{AbstractMatrix,AbstractDiffEqOperator} ||
55-
error("SVD is not defined for $(typeof(prob.A))")
55+
error("SVD is not defined for $(typeof(cache.A))")
5656
cache = set_cacheval(cache, svd!(cache.A; full = alg.full, alg = alg.alg))
5757
ldiv!(cache.u,cache.cacheval, cache.b)
5858
end

src/krylov.jl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# place Krylov.CGsolver in LinearCache.cacheval, and resule
44

5-
struct KrylovJL{A,K} <: SciMLLinearSolveAlgorithm
6-
solver::Function
5+
struct KrylovJL{F,A,K} <: SciMLLinearSolveAlgorithm
6+
solver::F
77
args::A
88
kwargs::K
99
end
@@ -17,16 +17,33 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL,args...;kwargs...)
1717
u, stats = alg.solver(A, b, args...; M=Pl, N=Pr, kwargs...)
1818
resid = A * u - b
1919
retcode = stats.solved ? :Success : :Failure
20-
return u #SciMLBase.build_solution(prob, alg, x, resid; retcode = retcode)
20+
return u
2121
end
2222

2323
## IterativeSolvers.jl
2424

25-
struct IterativeSolversJL{A,K} <: SciMLLinearSolveAlgorithm
26-
solver::Function
25+
struct IterativeSolversJL{F,A,K} <: SciMLLinearSolveAlgorithm
26+
solver::F
2727
args::A
2828
kwargs::K
2929
end
3030

3131
## KrylovKit.jl
3232

33+
struct KrylovKitJL{F,A,K} <: SciMLLinearSolveAlgorithm
34+
solver::F
35+
args::A
36+
kwargs::K
37+
end
38+
39+
function KrylovKitJL(args...; solver = KrylovKit.CG(), kwargs...)
40+
return KrylovKitJL(solver, args, kwargs)
41+
end
42+
43+
function SciMLBase.solve(cache::LinearCache, alg::KrylovKitJL,args...;kwargs...)
44+
@unpack A, b, u = cache
45+
@unpack solver = alg
46+
u = KrylovKit.linsolve(A, b, u, solver, args...; kwargs...)[1] #no precond?!
47+
return u
48+
end
49+

0 commit comments

Comments
 (0)