|
1 | | -using Pkg |
2 | | -using SafeTestsets, Test |
3 | | - |
4 | | -const GROUP = get(ENV, "GROUP", "All") |
5 | | - |
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 |
12 | | - |
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 |
114 | | - end |
115 | | - |
116 | | - # Allocation tests run separately to avoid precompilation interference |
117 | | - include("alloc_tests.jl") |
118 | | -end |
| 1 | +using SciMLTesting |
| 2 | +run_tests() |
0 commit comments