Skip to content

Commit b8e2ed4

Browse files
committed
Formatting
1 parent 386849a commit b8e2ed4

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

test/cg.jl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ include("poisson_matrix.jl")
99
facts("cg") do
1010

1111
context("Small full system") do
12-
N=10
13-
A = randn(N,N)
14-
A = A'*A
12+
N = 10
13+
A = randn(N, N)
14+
A = A' * A
1515
rhs = randn(N)
1616
tol = 1e-12
1717

18-
x = cg(A,rhs;tol=tol, maxiter=2*N)
19-
@fact norm(A*x - rhs) --> less_than(cond(A)*tol)
18+
x = cg(A, rhs; tol=tol, maxiter=2N)
19+
@fact norm(A*x - rhs) --> less_than(cond(A) * tol)
2020

21-
x,ch = cg(A,rhs;tol=tol, maxiter=2*N, log=true)
22-
@fact norm(A*x - rhs) --> less_than(cond(A)*tol)
21+
x,ch = cg(A, rhs; tol=tol, maxiter=2N, log=true)
22+
@fact norm(A * x - rhs) --> less_than(cond(A) * tol)
2323
@fact ch.isconverged --> true
2424

2525
# If you start from the exact solution, you should converge immediately
26-
x2, ch2 = cg!(A\rhs, A, rhs; tol=tol*10, log=true)
26+
x2, ch2 = cg!(A \ rhs, A, rhs; tol=10tol, log=true)
2727
@fact niters(ch2) --> less_than_or_equal(1)
2828
@fact nprods(ch2) --> less_than_or_equal(2)
2929

3030
# Test with cholfact should converge immediately
3131
F = cholfact(A)
32-
x2,ch2 = cg(A, rhs; Pl=F, log=true)
32+
x2, ch2 = cg(A, rhs; Pl=F, log=true)
3333
@fact niters(ch2) --> less_than_or_equal(2)
3434
@fact nprods(ch2) --> less_than_or_equal(2)
3535

@@ -43,41 +43,41 @@ context("Sparse Laplacian") do
4343
L = tril(A)
4444
D = diag(A)
4545
U = triu(A)
46-
JAC(x) = D.\x
47-
SGS(x) = L\(D.*(U\x))
46+
JAC(x) = D .\ x
47+
SGS(x) = L \ (D .* (U \ x))
4848

49-
rhs = randn(size(A,2))
50-
rhs/= norm(rhs)
49+
rhs = randn(size(A, 2))
50+
rhs /= norm(rhs)
5151
tol = 1e-5
5252

5353
context("matrix") do
54-
xCG = cg(A,rhs;tol=tol,maxiter=100)
55-
xJAC = cg(A,rhs;Pl=JAC,tol=tol,maxiter=100)
56-
xSGS = cg(A,rhs;Pl=SGS,tol=tol,maxiter=100)
57-
@fact norm(A*xCG - rhs) --> less_than_or_equal(tol)
58-
@fact norm(A*xSGS - rhs) --> less_than_or_equal(tol)
59-
@fact norm(A*xJAC - rhs) --> less_than_or_equal(tol)
54+
xCG = cg(A, rhs; tol=tol, maxiter=100)
55+
xJAC = cg(A, rhs; Pl=JAC, tol=tol, maxiter=100)
56+
xSGS = cg(A, rhs; Pl=SGS, tol=tol, maxiter=100)
57+
@fact norm(A * xCG - rhs) --> less_than_or_equal(tol)
58+
@fact norm(A * xSGS - rhs) --> less_than_or_equal(tol)
59+
@fact norm(A * xJAC - rhs) --> less_than_or_equal(tol)
6060
end
6161

6262
Af = LinearMap(A)
6363
context("function") do
64-
xCG = cg(Af,rhs;tol=tol,maxiter=100)
65-
xJAC = cg(Af,rhs;Pl=JAC,tol=tol,maxiter=100)
66-
xSGS = cg(Af,rhs;Pl=SGS,tol=tol,maxiter=100)
67-
@fact norm(A*xCG - rhs) --> less_than_or_equal(tol)
68-
@fact norm(A*xSGS - rhs) --> less_than_or_equal(tol)
69-
@fact norm(A*xJAC - rhs) --> less_than_or_equal(tol)
64+
xCG = cg(Af, rhs; tol=tol, maxiter=100)
65+
xJAC = cg(Af, rhs; Pl=JAC, tol=tol, maxiter=100)
66+
xSGS = cg(Af, rhs; Pl=SGS, tol=tol, maxiter=100)
67+
@fact norm(A * xCG - rhs) --> less_than_or_equal(tol)
68+
@fact norm(A * xSGS - rhs) --> less_than_or_equal(tol)
69+
@fact norm(A * xJAC - rhs) --> less_than_or_equal(tol)
7070
end
7171

7272
context("function with specified starting guess") do
7373
tol = 1e-4
7474
x0 = randn(size(rhs))
75-
xCG, hCG = cg!(copy(x0),Af,rhs;Pl=identity,tol=tol,maxiter=100, log=true)
76-
xJAC, hJAC = cg!(copy(x0),Af,rhs;Pl=JAC,tol=tol,maxiter=100, log=true)
77-
xSGS, hSGS = cg!(copy(x0),Af,rhs;Pl=SGS,tol=tol,maxiter=100, log=true)
78-
@fact norm(A*xCG - rhs) --> less_than_or_equal(tol)
79-
@fact norm(A*xSGS - rhs) --> less_than_or_equal(tol)
80-
@fact norm(A*xJAC - rhs) --> less_than_or_equal(tol)
75+
xCG, hCG = cg!(copy(x0), Af, rhs; Pl=identity, tol=tol, maxiter=100, log=true)
76+
xJAC, hJAC = cg!(copy(x0), Af, rhs; Pl=JAC, tol=tol, maxiter=100, log=true)
77+
xSGS, hSGS = cg!(copy(x0), Af, rhs; Pl=SGS, tol=tol, maxiter=100, log=true)
78+
@fact norm(A * xCG - rhs) --> less_than_or_equal(tol)
79+
@fact norm(A * xSGS - rhs) --> less_than_or_equal(tol)
80+
@fact norm(A * xJAC - rhs) --> less_than_or_equal(tol)
8181

8282
iterCG = niters(hCG)
8383
iterJAC = niters(hJAC)

0 commit comments

Comments
 (0)