@@ -4,32 +4,32 @@ using LinearMaps
4
4
5
5
srand (1234321 )
6
6
7
- include (" getDivGrad .jl" )
7
+ include (" poisson_matrix .jl" )
8
8
9
9
facts (" cg" ) do
10
10
11
11
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
15
15
rhs = randn (N)
16
16
tol = 1e-12
17
17
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= 2 N )
19
+ @fact norm (A* x - rhs) --> less_than (cond (A) * √ tol)
20
20
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= 2 N , log= true )
22
+ @fact norm (A * x - rhs) --> less_than (cond (A) * √ tol)
23
23
@fact ch. isconverged --> true
24
24
25
25
# 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= 10 tol , log= true )
27
27
@fact niters (ch2) --> less_than_or_equal (1 )
28
28
@fact nprods (ch2) --> less_than_or_equal (2 )
29
29
30
30
# Test with cholfact should converge immediately
31
31
F = cholfact (A)
32
- x2,ch2 = cg (A, rhs; Pl= F, log= true )
32
+ x2, ch2 = cg (A, rhs; Pl= F, log= true )
33
33
@fact niters (ch2) --> less_than_or_equal (2 )
34
34
@fact nprods (ch2) --> less_than_or_equal (2 )
35
35
@@ -39,45 +39,45 @@ context("Small full system") do
39
39
end
40
40
41
41
context (" Sparse Laplacian" ) do
42
- A = getDivGrad ( 32 , 32 ,32 )
42
+ A = poisson_matrix (Float64, 32 , 3 )
43
43
L = tril (A)
44
44
D = diag (A)
45
45
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))
48
48
49
- rhs = randn (size (A,2 ))
50
- rhs/= norm (rhs)
49
+ rhs = randn (size (A, 2 ))
50
+ rhs /= norm (rhs)
51
51
tol = 1e-5
52
52
53
53
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)
60
60
end
61
61
62
62
Af = LinearMap (A)
63
63
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)
70
70
end
71
71
72
72
context (" function with specified starting guess" ) do
73
73
tol = 1e-4
74
74
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)
81
81
82
82
iterCG = niters (hCG)
83
83
iterJAC = niters (hJAC)
0 commit comments