Skip to content

Commit

Permalink
Merge 6fdc8f7 into c0a9e44
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Dec 15, 2020
2 parents c0a9e44 + 6fdc8f7 commit 2495778
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CompatHelper.yml
@@ -1,19 +1,19 @@
name: CompatHelper

on:
schedule:
- cron: '00 00 * * *'

workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: 1.3
version: 1.5
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} # optional
run: julia -e 'using CompatHelper; CompatHelper.main(; subdirs=["", "docs", "test"])'
7 changes: 0 additions & 7 deletions Project.toml
Expand Up @@ -12,10 +12,3 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
[compat]
RecipesBase = "0.6, 0.7, 0.8, 1.0"
julia = "1"

[extras]
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "LinearMaps"]
55 changes: 29 additions & 26 deletions docs/src/iterators.md
Expand Up @@ -28,45 +28,48 @@ jacobi_iterable(x, A::SparseMatrixCSC, b; maxiter::Int = 10) =

Now if you apply Jacobi iteration multiple times with the same matrix for just a few iterations, it makes sense to initialize the iterable only once and reuse it afterwards:

```julia
A = sprand(10_000, 10_000, 10 / 10_000) + 20I
b1 = rand(10_000)
b2 = rand(10_000)
x = rand(10_000)

my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter = 4)
```jldoctest
julia> using LinearAlgebra, SparseArrays, IterativeSolvers
for item in my_iterable
println("Iteration for rhs 1")
end
julia> A = spdiagm(-1 => -ones(3), 0 => 2*ones(4), 1 => -ones(3));
@show norm(b1 - A * x) / norm(b1)
julia> b1 = [1.0, 2, 3, 4];
# Copy the next right-hand side into the iterable
copyto!(my_iterable.b, b2)
julia> b2 = [-1.0, 1, -1, 1];
for item in my_iterable
println("Iteration for rhs 2")
end
julia> x = [0.0, -1, 1, 0];
@show norm(b2 - A * x) / norm(b2)
```
julia> my_iterable = IterativeSolvers.jacobi_iterable(x, A, b1, maxiter = 2);
This would output:
julia> norm(b1 - A * x) / norm(b1)
1.2909944487358056
```
Iteration for rhs 1
Iteration for rhs 1
julia> for item in my_iterable
println("Iteration for rhs 1")
end
Iteration for rhs 1
Iteration for rhs 1
norm(b1 - A * x) / norm(b1) = 0.08388528015119746
Iteration for rhs 2
Iteration for rhs 2
julia> norm(b1 - A * x) / norm(b1)
0.8228507357554791
julia> # Copy the next right-hand side into the iterable
copyto!(my_iterable.b, b2);
julia> norm(b2 - A * x) / norm(b2)
2.6368778887161235
julia> for item in my_iterable
println("Iteration for rhs 2")
end
Iteration for rhs 2
Iteration for rhs 2
norm(b2 - A * x) / norm(b2) = 0.0003681972775644809
julia> norm(b2 - A * x) / norm(b2)
1.610815496107484
```


## Other use cases
Other use cases include:
- computing the (harmonic) Ritz values from the Hessenberg matrix in GMRES;
Expand Down
13 changes: 13 additions & 0 deletions test/Project.toml
@@ -0,0 +1,13 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Documenter = "0.26"
LinearMaps = "3"
RecipesBase = "1"
4 changes: 4 additions & 0 deletions test/bicgstabl.jl
@@ -1,3 +1,5 @@
module TestBiCGStabl

using IterativeSolvers
using Test
using Random
Expand Down Expand Up @@ -66,3 +68,5 @@ end
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/cg.jl
@@ -1,3 +1,5 @@
module TestCG

using IterativeSolvers
using LinearMaps
using Test
Expand Down Expand Up @@ -120,3 +122,5 @@ end
end

end

end # module
4 changes: 4 additions & 0 deletions test/chebyshev.jl
@@ -1,3 +1,5 @@
module TestChebyshev

using IterativeSolvers
using Test
using Random
Expand Down Expand Up @@ -91,3 +93,5 @@ end
end
end
end

end # module
8 changes: 8 additions & 0 deletions test/common.jl
@@ -1,3 +1,6 @@
module TestCommon

using Documenter
using LinearAlgebra
using IterativeSolvers
using Test
Expand Down Expand Up @@ -25,3 +28,8 @@ end
end

end

DocMeta.setdocmeta!(IterativeSolvers, :DocTestSetup, :(using IterativeSolvers); recursive=true)
doctest(IterativeSolvers, manual=true)

end # module
4 changes: 4 additions & 0 deletions test/gmres.jl
@@ -1,3 +1,5 @@
module TestGMRES

using IterativeSolvers
using Test
using LinearMaps
Expand Down Expand Up @@ -96,3 +98,5 @@ end
end
end
end

end # module
5 changes: 5 additions & 0 deletions test/hessenberg.jl
@@ -1,3 +1,6 @@
module TestHessenberg

using LinearAlgebra
using IterativeSolvers
using Test

Expand Down Expand Up @@ -40,3 +43,5 @@ using Test
@test abs(last(solution_with_residual)) norm(H * solution - rhs)
end
end

end # module
4 changes: 4 additions & 0 deletions test/history.jl
@@ -1,3 +1,5 @@
module TestHistory

using IterativeSolvers
using RecipesBase
using Test
Expand Down Expand Up @@ -75,3 +77,5 @@ using Test
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/idrs.jl
@@ -1,3 +1,5 @@
module TestIDRs

using IterativeSolvers
using Test
using Random
Expand Down Expand Up @@ -85,3 +87,5 @@ end
end

end

end # module
11 changes: 7 additions & 4 deletions test/lobpcg.jl
@@ -1,19 +1,20 @@
module TestLOBPCG

using IterativeSolvers
using LinearMaps
using LinearAlgebra
using Test
using Random
using SparseArrays


# Already defined in another file
#=
include("laplace_matrix.jl")

struct JacobiPrec{TD}
diagonal::TD
end

Base.ldiv!(y, P::JacobiPrec, x) = y .= x ./ P.diagonal
=#
LinearAlgebra.ldiv!(y, P::JacobiPrec, x) = y .= x ./ P.diagonal

function max_err(R)
r = zeros(real(eltype(R)), size(R, 2))
Expand Down Expand Up @@ -358,3 +359,5 @@ end
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/lsmr.jl
@@ -1,3 +1,5 @@
module TestLSMR

using IterativeSolvers
using Test
using LinearAlgebra
Expand Down Expand Up @@ -97,3 +99,5 @@ end
@test norm((A'A + Matrix(Diagonal(v)) .^ 2)x - A'b) 1e-3
end
end

end # module
4 changes: 4 additions & 0 deletions test/lsqr.jl
@@ -1,3 +1,5 @@
module TestLSQR

using IterativeSolvers
using Test
using LinearMaps
Expand Down Expand Up @@ -38,3 +40,5 @@ end
@test norm(b - A * x_lsqr) 1e-4
end
end

end # module
4 changes: 4 additions & 0 deletions test/minres.jl
@@ -1,3 +1,5 @@
module TestMINRES

using IterativeSolvers
using Test
using Random
Expand Down Expand Up @@ -94,3 +96,5 @@ end
end

end

end # module
5 changes: 5 additions & 0 deletions test/orthogonalize.jl
@@ -1,3 +1,6 @@
module TestOrthogonalize

using LinearAlgebra
using IterativeSolvers
using Test
using Random
Expand Down Expand Up @@ -58,3 +61,5 @@ m = 3
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/qmr.jl
@@ -1,3 +1,5 @@
module TestQMR

using IterativeSolvers
using Test
using Random
Expand Down Expand Up @@ -64,3 +66,5 @@ end
end

end

end # module
1 change: 0 additions & 1 deletion test/runtests.jl
@@ -1,4 +1,3 @@
using IterativeSolvers

#Common functions and data structures
include("common.jl")
Expand Down
4 changes: 4 additions & 0 deletions test/simple_eigensolvers.jl
@@ -1,3 +1,5 @@
module TestSimpleEigensolver

using IterativeSolvers
using Test
using LinearMaps
Expand Down Expand Up @@ -46,3 +48,5 @@ n = 10
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/stationary.jl
@@ -1,3 +1,5 @@
module TestStationary

import LinearAlgebra.SingularException
import IterativeSolvers: DiagonalIndices, FastLowerTriangular,
FastUpperTriangular, forward_sub!, backward_sub!, OffDiagonal,
Expand Down Expand Up @@ -211,3 +213,5 @@ end
@test x b - tril(A, -1) * y
end
end

end # module
4 changes: 4 additions & 0 deletions test/svdl.jl
@@ -1,3 +1,5 @@
module TestSVDL

using IterativeSolvers
using Test
using Random
Expand Down Expand Up @@ -77,3 +79,5 @@ end #svdl
@test_throws ArgumentError size(B,3)
@test_throws BoundsError B[1,5]
end

end # module

0 comments on commit 2495778

Please sign in to comment.