Skip to content

Commit 9cf9bb0

Browse files
author
Pawel Latawiec
committed
Explicitly pass rng to test random numbers
1 parent 324a88b commit 9cf9bb0

17 files changed

+112
-101
lines changed

test/bicgstabl.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ using LinearAlgebra
77

88
@testset ("BiCGStab(l)") begin
99

10-
Random.seed!(1234321)
10+
rng = Random.Xoshiro(12345)
1111
n = 20
1212

1313
@testset "Matrix{$T}" for T in (Float32, Float64, ComplexF32, ComplexF64)
14-
Random.seed!(123) # Issue #316 (test sensitive to the rng)
15-
A = rand(T, n, n) + 15I
14+
rng_temp = Random.Xoshiro(12345) # Issue #316 (test sensitive to the rng)
15+
A = rand(rng_temp, T, n, n) + 15I
1616
x = ones(T, n)
1717
b = A * x
1818

@@ -25,7 +25,7 @@ n = 20
2525
@test norm(A * x1 - b) / norm(b) reltol
2626

2727
# With an initial guess
28-
x_guess = rand(T, n)
28+
x_guess = rand(rng, T, n)
2929
x2, his2 = bicgstabl!(x_guess, A, b, l, max_mv_products = 100, log = true, reltol = reltol)
3030
@test isa(his2, ConvergenceHistory)
3131
@test x2 == x_guess
@@ -37,7 +37,7 @@ n = 20
3737
continue
3838
end
3939
# Do an exact LU decomp of a nearby matrix
40-
F = lu(A + rand(T, n, n))
40+
F = lu(A + rand(rng, T, n, n))
4141
x3, his3 = bicgstabl(A, b, Pl = F, l, max_mv_products = 100, log = true, reltol = reltol)
4242
@test norm(A * x3 - b) / norm(b) reltol
4343
end

test/cg.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ ldiv!(y, P::JacobiPrec, x) = y .= x ./ P.diagonal
1919

2020
@testset "Conjugate Gradients" begin
2121

22-
Random.seed!(1234321)
22+
rng = Random.Xoshiro(1234)
2323

2424
@testset "Small full system" begin
2525
n = 10
2626

2727
@testset "Matrix{$T}" for T in (Float32, Float64, ComplexF32, ComplexF64)
28-
A = rand(T, n, n)
28+
A = rand(rng, T, n, n)
2929
A = A' * A + I
30-
b = rand(T, n)
30+
b = rand(rng, T, n)
3131
reltol = eps(real(T))
3232

3333
x,ch = cg(A, b; reltol=reltol, maxiter=2n, log=true)

test/chebyshev.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ using Test
55
using Random
66
using LinearAlgebra
77

8-
function randSPD(T, n)
9-
A = rand(T, n, n) + n * I
8+
function randSPD(rng, T, n)
9+
A = rand(rng, T, n, n) + n * I
1010
A' * A
1111
end
1212

@@ -21,11 +21,11 @@ end
2121
@testset "Chebyshev" begin
2222

2323
n = 10
24-
Random.seed!(1234321)
24+
rng = Random.Xoshiro(1234)
2525

2626
@testset "Matrix{$T}" for T in (Float32, Float64, ComplexF32, ComplexF64)
27-
A = randSPD(T, n)
28-
b = rand(T, n)
27+
A = randSPD(rng, T, n)
28+
b = rand(rng, T, n)
2929
reltol = (eps(real(T)))
3030
abstol = reltol
3131

@@ -40,15 +40,15 @@ Random.seed!(1234321)
4040

4141
@testset "With an initial guess" begin
4242
λ_min, λ_max = approx_eigenvalue_bounds(A)
43-
x0 = rand(T, n)
43+
x0 = rand(rng, T, n)
4444
initial_residual = norm(A * x0 - b)
4545
x, history = chebyshev!(x0, A, b, λ_min, λ_max, reltol=reltol, maxiter=10n, log=true)
4646
@test isa(history, ConvergenceHistory)
4747
@test history.isconverged
4848
@test x == x0
4949
@test norm(A * x - b) reltol * initial_residual
5050

51-
x0 = rand(T, n)
51+
x0 = rand(rng, T, n)
5252
x, history = chebyshev!(x0, A, b, λ_min, λ_max, abstol=abstol, reltol=zero(real(T)), maxiter=10n, log=true)
5353
@test isa(history, ConvergenceHistory)
5454
@test history.isconverged
@@ -57,7 +57,7 @@ Random.seed!(1234321)
5757
end
5858

5959
@testset "With a preconditioner" begin
60-
B = randSPD(T, n)
60+
B = randSPD(rng, T, n)
6161
B_fact = cholesky!(B, Val(false))
6262
λ_min, λ_max = approx_eigenvalue_bounds(B_fact \ A)
6363
x, history = chebyshev(A, b, λ_min, λ_max, Pl = B_fact, reltol=reltol, maxiter=10n, log=true)

test/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using IterativeSolvers
66
using Test
77
using Random
88

9-
Random.seed!(1234321)
9+
rng = Random.Xoshiro(1234)
1010

1111
@testset "Basic operations" begin
1212

test/gmres.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ using SparseArrays
1010
#GMRES
1111
@testset "GMRES" begin
1212

13-
Random.seed!(1234321)
13+
rng = Random.Xoshiro(1234)
1414
n = 10
1515

1616
@testset "Matrix{$T}" for T in (Float32, Float64, ComplexF32, ComplexF64)
17-
A = rand(T, n, n) + I
18-
b = rand(T, n)
17+
A = rand(rng, T, n, n) + I
18+
b = rand(rng, T, n)
1919
F = lu(A)
2020
reltol = eps(real(T))
2121

@@ -36,8 +36,8 @@ n = 10
3636
end
3737

3838
@testset "SparseMatrixCSC{$T, $Ti}" for T in (Float64, ComplexF64), Ti in (Int64, Int32)
39-
A = sprand(T, n, n, 0.5) + I
40-
b = rand(T, n)
39+
A = sprand(rng, T, n, n, 0.5) + I
40+
b = rand(rng, T, n)
4141
F = lu(A)
4242
reltol = eps(real(T))
4343

@@ -58,7 +58,7 @@ end
5858

5959
@testset "Linear operator defined as a function" begin
6060
A = LinearMap(cumsum!, 100; ismutating=true)
61-
b = rand(100)
61+
b = rand(rng, 100)
6262
reltol = 1e-5
6363

6464
x = gmres(A, b; reltol=reltol, maxiter=2000)

test/idrs.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ using SparseArrays
1010

1111
n = 10
1212
m = 6
13-
Random.seed!(1234567)
13+
rng = Random.Xoshiro(12345)
1414

1515
@testset "Matrix{$T}" for T in (Float32, Float64, ComplexF32, ComplexF64)
16-
A = rand(T, n, n) + n * I
17-
b = rand(T, n)
16+
A = rand(rng, T, n, n) + n * I
17+
b = rand(rng, T, n)
1818
reltol = eps(real(T))
1919

2020
@testset "Without residual smoothing" begin
@@ -33,8 +33,8 @@ Random.seed!(1234567)
3333
end
3434

3535
@testset "SparseMatrixCSC{$T, $Ti}" for T in (Float64, ComplexF64), Ti in (Int64, Int32)
36-
A = sprand(T, n, n, 0.5) + n * I
37-
b = rand(T, n)
36+
A = sprand(rng, T, n, n, 0.5) + n * I
37+
b = rand(rng, T, n)
3838
reltol = eps(real(T))
3939

4040
x, history = idrs(A, b, log=true)
@@ -43,8 +43,8 @@ end
4343
end
4444

4545
@testset "SparseMatrixCSC{$T, $Ti} with preconditioner" for T in (Float64, ComplexF64), Ti in (Int64, Int32)
46-
A = sprand(T, 1000, 1000, 0.1) + 30 * I
47-
b = rand(T, 1000)
46+
A = sprand(rng, T, 1000, 1000, 0.1) + 30 * I
47+
b = rand(rng, T, 1000)
4848
reltol = eps(real(T))
4949

5050
x, history = idrs(A, b, log=true)

test/lal.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ using SparseArrays
44
using Test
55
import Random
66

7+
@testset "LAL" begin
8+
9+
rng = Random.Xoshiro(1234)
10+
711
# Equation references and identities from:
812
# Freund, R. W., & Nachtigal, N. M. (1994). An Implementation of the QMR Method Based on Coupled Two-Term Recurrences. SIAM Journal on Scientific Computing, 15(2), 313–337. https://doi.org/10.1137/0915022
913

@@ -238,4 +242,5 @@ end
238242

239243
test_lal_identities(ld_results)
240244
end
245+
end
241246
end

test/limited_memory_matrices.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ using LinearAlgebra
33
using SparseArrays
44
using Test
55

6+
@testset "Limited Memory Matrices" begin
7+
68
@testset "LimitedMemoryMatrix" begin
79
A = IS.LimitedMemoryMatrix{Float64, Matrix{Float64}}(fill(1.0, 4, 4), 4, 4)
810
@test A[1, 1] == 1
@@ -67,4 +69,6 @@ end
6769
0.0 0.0 3.0 4.0
6870
0.0 0.0 0.0 4.0
6971
]
72+
end
73+
7074
end

0 commit comments

Comments
 (0)