|
| 1 | +using Pkg |
1 | 2 | using SafeTestsets, Test |
2 | 3 |
|
3 | | -@testset "FastAlmostBandedMatrices" begin |
4 | | - @safetestset "Constructors" begin |
5 | | - using FastAlmostBandedMatrices |
6 | | - |
7 | | - A = AlmostBandedMatrix{Float64}(undef, (10, 11), (2, 1), 2) |
8 | | - A[1, 1] = 2 |
9 | | - @test A[1, 1] == 2.0 |
10 | | - A[4, 1] = 0 |
11 | | - @test A[4, 1] == 0.0 |
12 | | - @test_throws BandError A[4, 1] = 2 |
13 | | - A[1, 3] = 5 |
14 | | - @test A[1, 3] == 5.0 |
15 | | - |
16 | | - @test almostbandwidths(A) == (2, 1) |
17 | | - @test almostbandedrank(A) == 2 |
18 | | - end |
19 | | - |
20 | | - @safetestset "similar" begin |
21 | | - using FastAlmostBandedMatrices |
22 | | - |
23 | | - A = AlmostBandedMatrix(brand(Float64, 10, 10, 2, 1), rand(Float64, 2, 10)) |
24 | | - |
25 | | - @test similar(A) isa AlmostBandedMatrix |
26 | | - @test similar(A, Float32) isa AlmostBandedMatrix{Float32} |
27 | | - |
28 | | - fallback = similar(A, Float32, 10, 10) |
29 | | - @test fallback isa Matrix{Float32} |
30 | | - @test size(fallback) == size(A) |
31 | | - end |
32 | | - |
33 | | - @safetestset "Copy" begin |
34 | | - using FastAlmostBandedMatrices |
35 | | - |
36 | | - n = 5 |
37 | | - m = 2 |
38 | | - |
39 | | - A1 = AlmostBandedMatrix(brand(Float64, n, n, m + 1, m), rand(Float64, m, n)) |
40 | | - A2 = copy(A1) |
41 | | - |
42 | | - @test !(A2 isa Matrix) |
43 | | - @test A1 == A2 |
44 | | - |
45 | | - A2 = deepcopy(A1) |
| 4 | +const GROUP = get(ENV, "GROUP", "All") |
46 | 5 |
|
47 | | - @test !(A2 isa Matrix) |
48 | | - @test A1 == A2 |
49 | | - end |
50 | | - |
51 | | - @safetestset "QR" begin |
52 | | - using LinearAlgebra, FastAlmostBandedMatrices |
53 | | - import MatrixFactorizations: QRPackedQ |
54 | | - |
55 | | - n = 80 |
56 | | - A = AlmostBandedMatrix(BandedMatrix(fill(2.0, n, n), (1, 1)), fill(3.0, 2, n)) |
57 | | - A[band(0)] .+= 1:n |
58 | | - Ã = deepcopy(A) |
59 | | - B, L = bandpart(A), fillpart(A) |
60 | | - |
61 | | - F = qr(A) |
62 | | - @test F.Q isa LinearAlgebra.QRPackedQ{Float64, <:BandedMatrix} |
63 | | - @test F.R isa UpperTriangular{Float64, <:SubArray{Float64, 2, <:AlmostBandedMatrix}} |
64 | | - @test F.Q' * A ≈ F.R |
65 | | - @test A == Ã |
66 | | - |
67 | | - @inferred qr(A) |
68 | | - |
69 | | - b = randn(n) |
70 | | - @test A \ b ≈ Matrix(A) \ b |
71 | | - @test all(A \ b .=== F \ b) |
72 | | - @test all(A \ b .=== F.R \ (F.Q' * b)) |
73 | | - Q̃ = QRPackedQ(F.factors, F.τ) |
74 | | - @test Matrix(Q̃) ≈ Matrix(F.Q) |
75 | | - @test lmul!(Q̃, copy(b)) ≈ lmul!(F.Q, copy(b)) ≈ Matrix(F.Q) * b |
76 | | - @test lmul!(Q̃', copy(b)) ≈ lmul!(F.Q', copy(b)) ≈ Matrix(F.Q)' * b |
77 | | - end |
78 | | - |
79 | | - @safetestset "Triangular" begin |
80 | | - using LinearAlgebra, ArrayLayouts, FastAlmostBandedMatrices |
81 | | - import FastAlmostBandedMatrices: AlmostBandedLayout |
82 | | - |
83 | | - n = 80 |
84 | | - A = AlmostBandedMatrix(BandedMatrix(fill(2.0, n, n), (1, 1)), fill(3.0, 1, n)) |
85 | | - b = randn(n) |
86 | | - @test MemoryLayout(UpperTriangular(A)) == |
87 | | - TriangularLayout{'U', 'N', AlmostBandedLayout}() |
88 | | - @test_broken UpperTriangular(Matrix(A)) \ b ≈ UpperTriangular(A) \ b |
89 | | - @test_broken UnitUpperTriangular(Matrix(A)) \ b ≈ UnitUpperTriangular(A) \ b |
90 | | - @test LowerTriangular(Matrix(A)) \ b ≈ LowerTriangular(A) \ b |
91 | | - @test UnitLowerTriangular(Matrix(A)) \ b ≈ UnitLowerTriangular(A) \ b |
92 | | - end |
93 | | - |
94 | | - @safetestset "Aqua Q/A" begin |
95 | | - using Aqua, FastAlmostBandedMatrices |
96 | | - |
97 | | - Aqua.test_all(FastAlmostBandedMatrices; ambiguities = false) |
98 | | - end |
99 | | - |
100 | | - # https://github.com/SciML/FastAlmostBandedMatrices.jl/issues/19 |
101 | | - @safetestset "fill! on sparse array with BigFloat" begin |
102 | | - using FastAlmostBandedMatrices, SparseArrays |
| 6 | +if GROUP == "QA" |
| 7 | + Pkg.activate(joinpath(@__DIR__, "qa")) |
| 8 | + Pkg.develop(PackageSpec(path = joinpath(@__DIR__, ".."))) |
| 9 | + Pkg.instantiate() |
| 10 | + include(joinpath(@__DIR__, "qa", "qa.jl")) |
| 11 | +end |
103 | 12 |
|
104 | | - A = sparse([1, 2], [1, 5], big.([1.0, 1.0])) |
105 | | - A1 = AlmostBandedMatrix(brand(BigFloat, 5, 5, 1, 1), A) |
106 | | - fill!(A1, BigFloat(0.0)) |
107 | | - @test length(A1.fill.nzval) == 2 |
| 13 | +if GROUP == "Core" || GROUP == "All" |
| 14 | + @testset "FastAlmostBandedMatrices" begin |
| 15 | + @safetestset "Constructors" begin |
| 16 | + using FastAlmostBandedMatrices |
| 17 | + |
| 18 | + A = AlmostBandedMatrix{Float64}(undef, (10, 11), (2, 1), 2) |
| 19 | + A[1, 1] = 2 |
| 20 | + @test A[1, 1] == 2.0 |
| 21 | + A[4, 1] = 0 |
| 22 | + @test A[4, 1] == 0.0 |
| 23 | + @test_throws BandError A[4, 1] = 2 |
| 24 | + A[1, 3] = 5 |
| 25 | + @test A[1, 3] == 5.0 |
| 26 | + |
| 27 | + @test almostbandwidths(A) == (2, 1) |
| 28 | + @test almostbandedrank(A) == 2 |
| 29 | + end |
| 30 | + |
| 31 | + @safetestset "similar" begin |
| 32 | + using FastAlmostBandedMatrices |
| 33 | + |
| 34 | + A = AlmostBandedMatrix(brand(Float64, 10, 10, 2, 1), rand(Float64, 2, 10)) |
| 35 | + |
| 36 | + @test similar(A) isa AlmostBandedMatrix |
| 37 | + @test similar(A, Float32) isa AlmostBandedMatrix{Float32} |
| 38 | + |
| 39 | + fallback = similar(A, Float32, 10, 10) |
| 40 | + @test fallback isa Matrix{Float32} |
| 41 | + @test size(fallback) == size(A) |
| 42 | + end |
| 43 | + |
| 44 | + @safetestset "Copy" begin |
| 45 | + using FastAlmostBandedMatrices |
| 46 | + |
| 47 | + n = 5 |
| 48 | + m = 2 |
| 49 | + |
| 50 | + A1 = AlmostBandedMatrix(brand(Float64, n, n, m + 1, m), rand(Float64, m, n)) |
| 51 | + A2 = copy(A1) |
| 52 | + |
| 53 | + @test !(A2 isa Matrix) |
| 54 | + @test A1 == A2 |
| 55 | + |
| 56 | + A2 = deepcopy(A1) |
| 57 | + |
| 58 | + @test !(A2 isa Matrix) |
| 59 | + @test A1 == A2 |
| 60 | + end |
| 61 | + |
| 62 | + @safetestset "QR" begin |
| 63 | + using LinearAlgebra, FastAlmostBandedMatrices |
| 64 | + import MatrixFactorizations: QRPackedQ |
| 65 | + |
| 66 | + n = 80 |
| 67 | + A = AlmostBandedMatrix(BandedMatrix(fill(2.0, n, n), (1, 1)), fill(3.0, 2, n)) |
| 68 | + A[band(0)] .+= 1:n |
| 69 | + Ã = deepcopy(A) |
| 70 | + B, L = bandpart(A), fillpart(A) |
| 71 | + |
| 72 | + F = qr(A) |
| 73 | + @test F.Q isa LinearAlgebra.QRPackedQ{Float64, <:BandedMatrix} |
| 74 | + @test F.R isa UpperTriangular{Float64, <:SubArray{Float64, 2, <:AlmostBandedMatrix}} |
| 75 | + @test F.Q' * A ≈ F.R |
| 76 | + @test A == Ã |
| 77 | + |
| 78 | + @inferred qr(A) |
| 79 | + |
| 80 | + b = randn(n) |
| 81 | + @test A \ b ≈ Matrix(A) \ b |
| 82 | + @test all(A \ b .=== F \ b) |
| 83 | + @test all(A \ b .=== F.R \ (F.Q' * b)) |
| 84 | + Q̃ = QRPackedQ(F.factors, F.τ) |
| 85 | + @test Matrix(Q̃) ≈ Matrix(F.Q) |
| 86 | + @test lmul!(Q̃, copy(b)) ≈ lmul!(F.Q, copy(b)) ≈ Matrix(F.Q) * b |
| 87 | + @test lmul!(Q̃', copy(b)) ≈ lmul!(F.Q', copy(b)) ≈ Matrix(F.Q)' * b |
| 88 | + end |
| 89 | + |
| 90 | + @safetestset "Triangular" begin |
| 91 | + using LinearAlgebra, ArrayLayouts, FastAlmostBandedMatrices |
| 92 | + import FastAlmostBandedMatrices: AlmostBandedLayout |
| 93 | + |
| 94 | + n = 80 |
| 95 | + A = AlmostBandedMatrix(BandedMatrix(fill(2.0, n, n), (1, 1)), fill(3.0, 1, n)) |
| 96 | + b = randn(n) |
| 97 | + @test MemoryLayout(UpperTriangular(A)) == |
| 98 | + TriangularLayout{'U', 'N', AlmostBandedLayout}() |
| 99 | + @test_broken UpperTriangular(Matrix(A)) \ b ≈ UpperTriangular(A) \ b |
| 100 | + @test_broken UnitUpperTriangular(Matrix(A)) \ b ≈ UnitUpperTriangular(A) \ b |
| 101 | + @test LowerTriangular(Matrix(A)) \ b ≈ LowerTriangular(A) \ b |
| 102 | + @test UnitLowerTriangular(Matrix(A)) \ b ≈ UnitLowerTriangular(A) \ b |
| 103 | + end |
| 104 | + |
| 105 | + # https://github.com/SciML/FastAlmostBandedMatrices.jl/issues/19 |
| 106 | + @safetestset "fill! on sparse array with BigFloat" begin |
| 107 | + using FastAlmostBandedMatrices, SparseArrays |
| 108 | + |
| 109 | + A = sparse([1, 2], [1, 5], big.([1.0, 1.0])) |
| 110 | + A1 = AlmostBandedMatrix(brand(BigFloat, 5, 5, 1, 1), A) |
| 111 | + fill!(A1, BigFloat(0.0)) |
| 112 | + @test length(A1.fill.nzval) == 2 |
| 113 | + end |
108 | 114 | end |
109 | | -end |
110 | 115 |
|
111 | | -# Allocation tests run separately to avoid precompilation interference |
112 | | -if get(ENV, "GROUP", "all") == "all" || get(ENV, "GROUP", "all") == "nopre" |
| 116 | + # Allocation tests run separately to avoid precompilation interference |
113 | 117 | include("alloc_tests.jl") |
114 | 118 | end |
0 commit comments