Skip to content

Commit 6fdc8f7

Browse files
committed
make iterators doctest less expensive
1 parent c14da85 commit 6fdc8f7

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

docs/src/iterators.md

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,55 +31,44 @@ Now if you apply Jacobi iteration multiple times with the same matrix for just a
3131
```jldoctest
3232
julia> using LinearAlgebra, SparseArrays, IterativeSolvers
3333
34-
julia> A = sprand(10_000, 10_000, 10 / 10_000) + 20I;
34+
julia> A = spdiagm(-1 => -ones(3), 0 => 2*ones(4), 1 => -ones(3));
3535
36-
julia> b1 = rand(10_000);
36+
julia> b1 = [1.0, 2, 3, 4];
3737
38-
julia> b2 = rand(10_000);
38+
julia> b2 = [-1.0, 1, -1, 1];
3939
40-
julia> x = rand(10_000);
40+
julia> x = [0.0, -1, 1, 0];
4141
42-
julia> my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter = 4);
42+
julia> my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter = 2);
43+
44+
julia> norm(b1 - A * x) / norm(b1)
45+
1.2909944487358056
4346
4447
julia> for item in my_iterable
4548
println("Iteration for rhs 1")
4649
end
4750
Iteration for rhs 1
4851
Iteration for rhs 1
49-
Iteration for rhs 1
50-
Iteration for rhs 1
5152
52-
julia> relative_residual = norm(b1 - A * x) / norm(b1);
53+
julia> norm(b1 - A * x) / norm(b1)
54+
0.8228507357554791
5355
5456
julia> # Copy the next right-hand side into the iterable
5557
copyto!(my_iterable.b, b2);
5658
59+
julia> norm(b2 - A * x) / norm(b2)
60+
2.6368778887161235
61+
5762
julia> for item in my_iterable
5863
println("Iteration for rhs 2")
5964
end
6065
Iteration for rhs 2
6166
Iteration for rhs 2
62-
Iteration for rhs 2
63-
Iteration for rhs 2
6467
65-
julia> relative_residual ≈ norm(b2 - A * x) / norm(b2)
66-
false
68+
julia> norm(b2 - A * x) / norm(b2)
69+
1.610815496107484
6770
```
6871

69-
This would output:
70-
71-
```
72-
Iteration for rhs 1
73-
Iteration for rhs 1
74-
Iteration for rhs 1
75-
Iteration for rhs 1
76-
norm(b1 - A * x) / norm(b1) = 0.08388528015119746
77-
Iteration for rhs 2
78-
Iteration for rhs 2
79-
Iteration for rhs 2
80-
Iteration for rhs 2
81-
norm(b2 - A * x) / norm(b2) = 0.0003681972775644809
82-
```
8372

8473
## Other use cases
8574
Other use cases include:

0 commit comments

Comments
 (0)