From f407908388705c839448cabd051683d877929ba9 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 26 Apr 2024 16:40:58 +0530 Subject: [PATCH] Make tests modular --- test/mymatrix.jl | 22 ++++++++++++++++++++++ test/runtests.jl | 4 +--- test/test_banded.jl | 28 +++++----------------------- test/test_bandedlu.jl | 4 ++++ test/test_bandedqr.jl | 4 ++++ test/test_broadcasting.jl | 8 ++++++-- test/test_dot.jl | 4 ++++ test/test_indexing.jl | 4 ++++ test/test_interface.jl | 8 ++++++-- test/test_linalg.jl | 4 +++- test/test_miscs.jl | 6 +++++- test/test_subarray.jl | 7 ++++++- test/test_symbanded.jl | 4 ++++ test/test_tribanded.jl | 4 ++++ 14 files changed, 78 insertions(+), 33 deletions(-) create mode 100644 test/mymatrix.jl diff --git a/test/mymatrix.jl b/test/mymatrix.jl new file mode 100644 index 00000000..7a04fcc4 --- /dev/null +++ b/test/mymatrix.jl @@ -0,0 +1,22 @@ +# used to test general matrix backends +struct MyMatrix{T} <: AbstractMatrix{T} + A::Matrix{T} +end + +MyMatrix{T}(::UndefInitializer, n::Int, m::Int) where T = MyMatrix{T}(Array{T}(undef, n, m)) +MyMatrix(A::AbstractMatrix{T}) where T = MyMatrix{T}(Matrix{T}(A)) +Base.convert(::Type{MyMatrix{T}}, A::MyMatrix{T}) where T = A +Base.convert(::Type{MyMatrix{T}}, A::MyMatrix) where T = MyMatrix(convert(AbstractArray{T}, A.A)) +Base.convert(::Type{MyMatrix}, A::MyMatrix)= A +Base.convert(::Type{AbstractArray{T}}, A::MyMatrix) where T = MyMatrix(convert(AbstractArray{T}, A.A)) +Base.convert(::Type{AbstractMatrix{T}}, A::MyMatrix) where T = MyMatrix(convert(AbstractArray{T}, A.A)) +Base.convert(::Type{MyMatrix{T}}, A::AbstractArray{T}) where T = MyMatrix{T}(A) +Base.convert(::Type{MyMatrix{T}}, A::AbstractArray) where T = MyMatrix{T}(convert(AbstractArray{T}, A)) +Base.convert(::Type{MyMatrix}, A::AbstractArray{T}) where T = MyMatrix{T}(A) +Base.getindex(A::MyMatrix, kj...) = A.A[kj...] +Base.getindex(A::MyMatrix, ::Colon, j::AbstractVector) = MyMatrix(A.A[:,j]) +Base.setindex!(A::MyMatrix, v, kj...) = setindex!(A.A, v, kj...) +Base.size(A::MyMatrix) = size(A.A) +Base.similar(::Type{MyMatrix{T}}, m::Int, n::Int) where T = MyMatrix{T}(undef, m, n) +Base.similar(::MyMatrix{T}, m::Int, n::Int) where T = MyMatrix{T}(undef, m, n) +Base.similar(::MyMatrix, ::Type{T}, m::Int, n::Int) where T = MyMatrix{T}(undef, m, n) diff --git a/test/runtests.jl b/test/runtests.jl index 5caa9ee4..2e536839 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,9 +1,7 @@ using BandedMatrices -using LinearAlgebra -using SparseArrays using Test -using Aqua +import Aqua @testset "Project quality" begin Aqua.test_all(BandedMatrices, ambiguities=false, piracies=false) end diff --git a/test/test_banded.jl b/test/test_banded.jl index 66e39cdd..2560aea9 100644 --- a/test/test_banded.jl +++ b/test/test_banded.jl @@ -1,3 +1,5 @@ +module TestBanded + using ArrayLayouts using BandedMatrices import BandedMatrices: _BandedMatrix @@ -6,29 +8,7 @@ using LinearAlgebra using SparseArrays using Test -# used to test general matrix backends -struct MyMatrix{T} <: AbstractMatrix{T} - A::Matrix{T} -end - -MyMatrix{T}(::UndefInitializer, n::Int, m::Int) where T = MyMatrix{T}(Array{T}(undef, n, m)) -MyMatrix(A::AbstractMatrix{T}) where T = MyMatrix{T}(Matrix{T}(A)) -Base.convert(::Type{MyMatrix{T}}, A::MyMatrix{T}) where T = A -Base.convert(::Type{MyMatrix{T}}, A::MyMatrix) where T = MyMatrix(convert(AbstractArray{T}, A.A)) -Base.convert(::Type{MyMatrix}, A::MyMatrix)= A -Base.convert(::Type{AbstractArray{T}}, A::MyMatrix) where T = MyMatrix(convert(AbstractArray{T}, A.A)) -Base.convert(::Type{AbstractMatrix{T}}, A::MyMatrix) where T = MyMatrix(convert(AbstractArray{T}, A.A)) -Base.convert(::Type{MyMatrix{T}}, A::AbstractArray{T}) where T = MyMatrix{T}(A) -Base.convert(::Type{MyMatrix{T}}, A::AbstractArray) where T = MyMatrix{T}(convert(AbstractArray{T}, A)) -Base.convert(::Type{MyMatrix}, A::AbstractArray{T}) where T = MyMatrix{T}(A) -Base.getindex(A::MyMatrix, kj...) = A.A[kj...] -Base.getindex(A::MyMatrix, ::Colon, j::AbstractVector) = MyMatrix(A.A[:,j]) -Base.setindex!(A::MyMatrix, v, kj...) = setindex!(A.A, v, kj...) -Base.size(A::MyMatrix) = size(A.A) -Base.similar(::Type{MyMatrix{T}}, m::Int, n::Int) where T = MyMatrix{T}(undef, m, n) -Base.similar(::MyMatrix{T}, m::Int, n::Int) where T = MyMatrix{T}(undef, m, n) -Base.similar(::MyMatrix, ::Type{T}, m::Int, n::Int) where T = MyMatrix{T}(undef, m, n) - +include("mymatrix.jl") @testset "BandedMatrix" begin @testset "Undef BandedMatrix" begin @@ -566,3 +546,5 @@ Base.similar(::MyMatrix, ::Type{T}, m::Int, n::Int) where T = MyMatrix{T}(undef, @test BandedMatrices.colrange(A, 4) == 4:4 end end + +end # module diff --git a/test/test_bandedlu.jl b/test/test_bandedlu.jl index d8f03a16..1086e675 100644 --- a/test/test_bandedlu.jl +++ b/test/test_bandedlu.jl @@ -1,3 +1,5 @@ +module TestBandedLU + using BandedMatrices, LinearAlgebra, Test, Random import BandedMatrices: _BandedMatrix @@ -161,3 +163,5 @@ struct _foo <: Number end end end end + +end # module diff --git a/test/test_bandedqr.jl b/test/test_bandedqr.jl index 77d6be8b..74e34119 100644 --- a/test/test_bandedqr.jl +++ b/test/test_bandedqr.jl @@ -1,3 +1,5 @@ +module TestBandedQR + using BandedMatrices, LinearAlgebra, Test, Random import BandedMatrices: banded_qr! Random.seed!(0) @@ -131,3 +133,5 @@ Random.seed!(0) end end end + +end # module diff --git a/test/test_broadcasting.jl b/test/test_broadcasting.jl index 6752a7a6..de9582fe 100644 --- a/test/test_broadcasting.jl +++ b/test/test_broadcasting.jl @@ -1,3 +1,5 @@ +module TestBroadcasting + using BandedMatrices, LinearAlgebra, ArrayLayouts, FillArrays, Test import Base: BroadcastStyle import Base.Broadcast: broadcasted @@ -683,8 +685,8 @@ import BandedMatrices: BandedStyle, BandedRows, BandError A = brand(5,4,2,1) x = randn(5) B = Base.Broadcast.broadcasted(*, Base.Broadcast.broadcasted(+, 2, x), A) - @test bandwidths(B) == bandwidths(A) == bandwidths(materialize(B)) == (2,1) - @test materialize(B) == (2 .+ x) .* Matrix(A) + @test bandwidths(B) == bandwidths(A) == bandwidths(Broadcast.materialize(B)) == (2,1) + @test Broadcast.materialize(B) == (2 .+ x) .* Matrix(A) B = Base.Broadcast.broadcasted(+, Base.Broadcast.broadcasted(+, A, A), A) @test bandwidths(B) == bandwidths(A) @@ -764,3 +766,5 @@ import BandedMatrices: BandedStyle, BandedRows, BandError @test_throws BandError B[band(-100)] .= 10 end end + +end # module diff --git a/test/test_dot.jl b/test/test_dot.jl index 41ac527d..60bd1a6c 100644 --- a/test/test_dot.jl +++ b/test/test_dot.jl @@ -1,3 +1,5 @@ +module TestDot + using BandedMatrices, LinearAlgebra, FillArrays, Test import BandedMatrices: _BandedMatrix using Random @@ -36,3 +38,5 @@ using Random end end end + +end # module diff --git a/test/test_indexing.jl b/test/test_indexing.jl index ee841ef3..f514453d 100644 --- a/test/test_indexing.jl +++ b/test/test_indexing.jl @@ -1,3 +1,5 @@ +module TestIndexing + using BandedMatrices, LinearAlgebra, ArrayLayouts, Test import BandedMatrices: rowstart, rowstop, colstart, colstop, @@ -811,3 +813,5 @@ import BandedMatrices: rowstart, rowstop, colstart, colstop, @test A[2:2:5,Base.OneTo(6)] isa Matrix end end + +end # module diff --git a/test/test_interface.jl b/test/test_interface.jl index 7173eaca..6dbdb2f4 100644 --- a/test/test_interface.jl +++ b/test/test_interface.jl @@ -1,6 +1,8 @@ +module TestInterface + using BandedMatrices, LinearAlgebra, ArrayLayouts, FillArrays, Test -import BandedMatrices: banded_mul!, isbanded, AbstractBandedLayout, BandedStyle, - rowsupport, colsupport, _BandedMatrix, BandedColumns, bandeddata +import BandedMatrices: isbanded, AbstractBandedLayout, BandedStyle, + BandedColumns, bandeddata import ArrayLayouts: OnesLayout, UnknownLayout using InfiniteArrays @@ -352,3 +354,5 @@ end S = Symmetric(brand(10,10,1,2)) @test permutedims(S) ≡ S end + +end # module diff --git a/test/test_linalg.jl b/test/test_linalg.jl index 3908523c..5fe320c5 100644 --- a/test/test_linalg.jl +++ b/test/test_linalg.jl @@ -1,3 +1,5 @@ +module TestLinalg + using ArrayLayouts using BandedMatrices using FillArrays @@ -5,7 +7,6 @@ using LinearAlgebra using Quaternions using Test -import Base.Broadcast: materialize, broadcasted import BandedMatrices: BandedColumns, _BandedMatrix @testset "Linear Algebra" begin @@ -479,3 +480,4 @@ import BandedMatrices: BandedColumns, _BandedMatrix end end +end # module diff --git a/test/test_miscs.jl b/test/test_miscs.jl index a3fc5e3a..23c06e1f 100644 --- a/test/test_miscs.jl +++ b/test/test_miscs.jl @@ -1,4 +1,6 @@ -using BandedMatrices, LinearAlgebra, FillArrays, Test +module TestMisc + +using BandedMatrices, LinearAlgebra, FillArrays, Test, SparseArrays import BandedMatrices: _BandedMatrix, DefaultBandedMatrix @testset "misc tests" begin @@ -125,3 +127,5 @@ import BandedMatrices: _BandedMatrix, DefaultBandedMatrix @test_throws BoundsError A[-5,-5+3] end end + +end # module diff --git a/test/test_subarray.jl b/test/test_subarray.jl index 854b28c9..a5eddb4d 100644 --- a/test/test_subarray.jl +++ b/test/test_subarray.jl @@ -1,7 +1,10 @@ -using BandedMatrices, FillArrays, ArrayLayouts, Test +module TestSubArray + +using BandedMatrices, FillArrays, ArrayLayouts, Test, LinearAlgebra import LinearAlgebra: axpy! import BandedMatrices: BandedColumns, bandeddata, MemoryLayout, BandedSubBandedMatrix, _BandedMatrix, sub_materialize, isbanded +include("mymatrix.jl") @testset "BandedMatrix SubArray" begin @testset "BandedMatrix SubArray interface" begin @@ -123,3 +126,5 @@ import BandedMatrices: BandedColumns, bandeddata, MemoryLayout, BandedSubBandedM end end end + +end # module diff --git a/test/test_symbanded.jl b/test/test_symbanded.jl index 8174f884..c1ac0fb1 100644 --- a/test/test_symbanded.jl +++ b/test/test_symbanded.jl @@ -1,3 +1,5 @@ +module TestSymBanded + using ArrayLayouts using BandedMatrices import BandedMatrices: MemoryLayout, SymmetricLayout, HermitianLayout, BandedColumns, isbanded @@ -401,3 +403,5 @@ end B = BandedMatrix(1=>Float64[1:4;], 0=>Float64[2:2:10;], -1=>Float64[1:4;]) @test isposdef(B) == isposdef(Matrix(B)) == true end + +end # module diff --git a/test/test_tribanded.jl b/test/test_tribanded.jl index 13802ad6..517bf366 100644 --- a/test/test_tribanded.jl +++ b/test/test_tribanded.jl @@ -1,3 +1,5 @@ +module TestTriBanded + using BandedMatrices, LinearAlgebra, ArrayLayouts, Test import BandedMatrices: BandedColumns, BandedRows, isbanded @@ -113,3 +115,5 @@ import BandedMatrices: BandedColumns, BandedRows, isbanded @test rot180(UnitLowerTriangular(B)) == rot180(Matrix(UnitLowerTriangular(B))) end end + +end # module