Skip to content

Commit c69a85e

Browse files
authored
Merge pull request #177 from haampie/remove-solve-function
Remove solve function
2 parents 5d9c83c + 6cb00e5 commit c69a85e

File tree

6 files changed

+20
-33
lines changed

6 files changed

+20
-33
lines changed

benchmark/benchmark-hessenberg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function backslash_versus_givens(; n = 1_000, ms = 10 : 10 : 100)
4343
rhs = [i == 1 ? 1.0 : 0.0 for i = 1 : size(H, 1)]
4444

4545
# Run the benchmark
46-
results["givens_qr"][m] = @benchmark IterativeSolvers.solve!(IterativeSolvers.Hessenberg(myH), myRhs) setup = (myH = copy($H); myRhs = copy($rhs))
46+
results["givens_qr"][m] = @benchmark A_ldiv_B!(IterativeSolvers.Hessenberg(myH), myRhs) setup = (myH = copy($H); myRhs = copy($rhs))
4747
results["backslash"][m] = @benchmark $H \ $rhs
4848
end
4949

src/cg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666
#####################
6767

6868
function next(it::PCGIterable, iteration::Int)
69-
solve!(it.c, it.Pl, it.r)
69+
A_ldiv_B!(it.c, it.Pl, it.r)
7070

7171
ρ_prev = it.ρ
7272
it.ρ = dot(it.c, it.r)

src/chebyshev.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ done(c::ChebyshevIterable, iteration::Int) = iteration ≥ c.maxiter || converge
2929
function next(cheb::ChebyshevIterable, iteration::Int)
3030
T = eltype(cheb.x)
3131

32-
solve!(cheb.c, cheb.Pl, cheb.r)
32+
A_ldiv_B!(cheb.c, cheb.Pl, cheb.r)
3333

3434
if iteration == 1
3535
cheb.α = T(2) / cheb.λ_avg

src/common.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,9 @@ Build a zeros vector `Vector{T}`, where `T` is `Adivtype(A,b)`.
1616
"""
1717
zerox(A, b) = zeros(Adivtype(A, b), size(A, 2))
1818

19-
#### Numerics
2019
"""
21-
solve(A,b)
22-
Solve `A\\b` with a direct solver. When `A` is a function `A(b)` is dispatched instead.
20+
No-op preconditioner
2321
"""
24-
solve(A::Function,b) = A(b)
25-
solve(A,b) = A\b
26-
solve!(out::AbstractArray{T},A::Int,b::AbstractArray{T}) where {T} = scale!(out,b, 1/A)
27-
solve!(out::AbstractArray{T},A,b::AbstractArray{T}) where {T} = A_ldiv_B!(out,A,b)
28-
solve!(out::AbstractArray{T},A::Function,b::AbstractArray{T}) where {T} = copy!(out,A(b))
29-
30-
# Identity preconditioner
3122
struct Identity end
3223

3324
\(::Identity, x) = copy(x)

test/cg.jl

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ using IterativeSolvers
22
using LinearMaps
33
using Base.Test
44

5+
import Base.A_ldiv_B!
6+
57
include("laplace_matrix.jl")
68

9+
struct JacobiPrec
10+
diagonal
11+
end
12+
13+
14+
A_ldiv_B!(y, P::JacobiPrec, x) = y .= x ./ P.diagonal
15+
716
@testset "Conjugate Gradients" begin
817

918
srand(1234321)
@@ -40,48 +49,35 @@ srand(1234321)
4049
end
4150

4251
@testset "Sparse Laplacian" begin
43-
A = laplace_matrix(Float64, 10, 3)
44-
L = tril(A)
45-
D = diag(A)
46-
U = triu(A)
47-
48-
JAC(x) = D .\ x
49-
SGS(x) = L \ (D .* (U \ x))
52+
A = laplace_matrix(Float64, 10, 2)
53+
P = JacobiPrec(diag(A))
5054

5155
rhs = randn(size(A, 2))
52-
rhs /= norm(rhs)
56+
scale!(rhs, inv(norm(rhs)))
5357
tol = 1e-5
5458

5559
@testset "Matrix" begin
5660
xCG = cg(A, rhs; tol=tol, maxiter=100)
57-
xJAC = cg(A, rhs; Pl=JAC, tol=tol, maxiter=100)
58-
xSGS = cg(A, rhs; Pl=SGS, tol=tol, maxiter=100)
61+
xJAC = cg(A, rhs; Pl=P, tol=tol, maxiter=100)
5962
@test norm(A * xCG - rhs) tol
60-
@test norm(A * xSGS - rhs) tol
6163
@test norm(A * xJAC - rhs) tol
6264
end
6365

6466
Af = LinearMap(A)
6567
@testset "Function" begin
6668
xCG = cg(Af, rhs; tol=tol, maxiter=100)
67-
xJAC = cg(Af, rhs; Pl=JAC, tol=tol, maxiter=100)
68-
xSGS = cg(Af, rhs; Pl=SGS, tol=tol, maxiter=100)
69+
xJAC = cg(Af, rhs; Pl=P, tol=tol, maxiter=100)
6970
@test norm(A * xCG - rhs) tol
70-
@test norm(A * xSGS - rhs) tol
7171
@test norm(A * xJAC - rhs) tol
7272
end
7373

7474
@testset "Function with specified starting guess" begin
75-
tol = 1e-4
7675
x0 = randn(size(rhs))
7776
xCG, hCG = cg!(copy(x0), Af, rhs; tol=tol, maxiter=100, log=true)
78-
xJAC, hJAC = cg!(copy(x0), Af, rhs; Pl=JAC, tol=tol, maxiter=100, log=true)
79-
xSGS, hSGS = cg!(copy(x0), Af, rhs; Pl=SGS, tol=tol, maxiter=100, log=true)
77+
xJAC, hJAC = cg!(copy(x0), Af, rhs; Pl=P, tol=tol, maxiter=100, log=true)
8078
@test norm(A * xCG - rhs) tol
81-
@test norm(A * xSGS - rhs) tol
8279
@test norm(A * xJAC - rhs) tol
8380
@test niters(hJAC) == niters(hCG)
84-
@test niters(hSGS) niters(hJAC)
8581
end
8682
end
8783

test/hessenberg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using IterativeSolvers
22
using Base.Test
33

4-
import IterativeSolvers: Hessenberg, solve!
4+
import IterativeSolvers: Hessenberg
55

66
@testset "Hessenberg" begin
77

0 commit comments

Comments
 (0)