Skip to content

Commit 988206d

Browse files
Merge pull request #185 from ArnoStrouwen/patch-4
example blocks
2 parents 605410a + b5db038 commit 988206d

File tree

5 files changed

+30
-51
lines changed

5 files changed

+30
-51
lines changed

docs/src/advanced/custom.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface to be easily extendable by users. To that end, the linear solve algori
77
user can pass in their custom linear solve function, say `my_linsolve`, to
88
`LinearSolveFunction()`. A contrived example of solving a linear system with a custom solver is below.
99

10-
```julia
10+
```@example advanced1
1111
using LinearSolve, LinearAlgebra
1212
1313
function my_linsolve(A,b,u,p,newA,Pl,Pr,solverdata;verbose=true, kwargs...)
@@ -21,6 +21,7 @@ end
2121
prob = LinearProblem(Diagonal(rand(4)), rand(4))
2222
alg = LinearSolveFunction(my_linsolve)
2323
sol = solve(prob, alg)
24+
sol.u
2425
```
2526
The inputs to the function are as follows:
2627
- `A`, the linear operator
@@ -36,7 +37,7 @@ The inputs to the function are as follows:
3637
The function `my_linsolve` must accept the above specified arguments, and return
3738
the solution, `u`. As memory for `u` is already allocated, the user may choose
3839
to modify `u` in place as follows:
39-
```julia
40+
```@example advanced1
4041
function my_linsolve!(A,b,u,p,newA,Pl,Pr,solverdata;verbose=true, kwargs...)
4142
if verbose == true
4243
println("solving Ax=b")
@@ -47,4 +48,5 @@ end
4748
4849
alg = LinearSolveFunction(my_linsolve!)
4950
sol = solve(prob, alg)
51+
sol.u
5052
```

docs/src/basics/FAQ.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,40 @@ IterativeSolvers.jl computes the norm after the application of the left precondt
3939
`Pl`. Thus in order to use a vector tolerance `weights`, one can mathematically
4040
hack the system via the following formulation:
4141

42-
```julia
42+
```@example FAQPrec
4343
using LinearSolve, LinearAlgebra
44-
Pl = LinearSolve.InvPreconditioner(Diagonal(weights))
45-
Pr = Diagonal(weights)
4644
45+
n = 2
4746
A = rand(n,n)
4847
b = rand(n)
4948
49+
weights = [1e-1, 1]
50+
Pl = LinearSolve.InvPreconditioner(Diagonal(weights))
51+
Pr = Diagonal(weights)
52+
53+
5054
prob = LinearProblem(A,b)
5155
sol = solve(prob,IterativeSolversJL_GMRES(),Pl=Pl,Pr=Pr)
56+
57+
sol.u
5258
```
5359

5460
If you want to use a "real" preconditioner under the norm `weights`, then one
5561
can use `ComposePreconditioner` to apply the preconditioner after the application
5662
of the weights like as follows:
5763

58-
```julia
64+
```@example FAQ2
5965
using LinearSolve, LinearAlgebra
60-
Pl = ComposePreconitioner(LinearSolve.InvPreconditioner(Diagonal(weights),realprec))
61-
Pr = Diagonal(weights)
6266
67+
n = 4
6368
A = rand(n,n)
6469
b = rand(n)
6570
71+
weights = rand(n)
72+
realprec = lu(rand(n,n)) # some random preconditioner
73+
Pl = LinearSolve.ComposePreconditioner(LinearSolve.InvPreconditioner(Diagonal(weights)),realprec)
74+
Pr = Diagonal(weights)
75+
6676
prob = LinearProblem(A,b)
6777
sol = solve(prob,IterativeSolversJL_GMRES(),Pl=Pl,Pr=Pr)
6878
```

docs/src/basics/Preconditioners.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ preconditioned system which first divides by some random numbers and then
4141
multiplies by the same values. This is commonly used in the case where if, instead
4242
of random, `s` is an approximation to the eigenvalues of a system.
4343

44-
```julia
44+
```@example precon
4545
using LinearSolve, LinearAlgebra
46+
n = 4
4647
s = rand(n)
4748
Pl = Diagonal(s)
4849
@@ -51,6 +52,7 @@ b = rand(n)
5152
5253
prob = LinearProblem(A,b)
5354
sol = solve(prob,IterativeSolversJL_GMRES(),Pl=Pl)
55+
sol.u
5456
```
5557

5658
## Preconditioner Interface

docs/src/tutorials/caching_interface.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LinearSolve.jl's caching interface automates this process to use the most effici
2020
means of solving and resolving linear systems. To do this with LinearSolve.jl,
2121
you simply `init` a cache, `solve`, replace `b`, and solve again. This looks like:
2222

23-
```julia
23+
```@example linsys2
2424
using LinearSolve
2525
2626
n = 4
@@ -32,42 +32,22 @@ linsolve = init(prob)
3232
sol1 = solve(linsolve)
3333
3434
sol1.u
35-
#=
36-
4-element Vector{Float64}:
37-
-0.9247817429364165
38-
-0.0972021708185121
39-
0.6839050402960025
40-
1.8385599677530706
41-
=#
42-
35+
```
36+
```@example linsys2
4337
linsolve = LinearSolve.set_b(sol1.cache,b2)
4438
sol2 = solve(linsolve)
4539
4640
sol2.u
47-
#=
48-
4-element Vector{Float64}:
49-
1.0321556637762768
50-
0.49724400693338083
51-
-1.1696540870182406
52-
-0.4998342686003478
53-
=#
5441
```
5542

5643
Then refactorization will occur when a new `A` is given:
5744

58-
```julia
45+
```@example linsys2
5946
A2 = rand(n,n)
6047
linsolve = LinearSolve.set_A(sol2.cache,A2)
6148
sol3 = solve(linsolve)
6249
6350
sol3.u
64-
#=
65-
4-element Vector{Float64}:
66-
-6.793605395935224
67-
2.8673042300837466
68-
1.1665136934977371
69-
-0.4097250749016653
70-
=#
7151
```
7252

7353
The factorization occurs on the first solve, and it stores the factorization in

docs/src/tutorials/linear.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,14 @@ of simplicity, this tutorial will only showcase concrete matrices.
88
The following defines a matrix and a `LinearProblem` which is subsequently solved
99
by the default linear solver.
1010

11-
```julia
11+
```@example linsys1
1212
using LinearSolve
1313
1414
A = rand(4,4)
1515
b = rand(4)
1616
prob = LinearProblem(A, b)
1717
sol = solve(prob)
1818
sol.u
19-
20-
#=
21-
4-element Vector{Float64}:
22-
0.3784870087078603
23-
0.07275749718047864
24-
0.6612816064734302
25-
-0.10598367531463938
26-
=#
2719
```
2820

2921
Note that `solve(prob)` is equivalent to `solve(prob,nothing)` where `nothing`
@@ -35,16 +27,9 @@ has some nice methods like GMRES which can be faster in some cases. With
3527
LinearSolve.jl, there is one interface and changing linear solvers is simply
3628
the switch of the algorithm choice:
3729

38-
```julia
30+
```@example linsys1
3931
sol = solve(prob,IterativeSolversJL_GMRES())
40-
41-
#=
42-
u: 4-element Vector{Float64}:
43-
0.37848700870786
44-
0.07275749718047908
45-
0.6612816064734302
46-
-0.10598367531463923
47-
=#
32+
sol.u
4833
```
4934

5035
Thus a package which uses LinearSolve.jl simply needs to allow the user to

0 commit comments

Comments
 (0)