Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests modular #441

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/mymatrix.jl
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 5 additions & 23 deletions test/test_banded.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestBanded

using ArrayLayouts
using BandedMatrices
import BandedMatrices: _BandedMatrix
Expand All @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/test_bandedlu.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestBandedLU

using BandedMatrices, LinearAlgebra, Test, Random
import BandedMatrices: _BandedMatrix

Expand Down Expand Up @@ -161,3 +163,5 @@ struct _foo <: Number end
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/test_bandedqr.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestBandedQR

using BandedMatrices, LinearAlgebra, Test, Random
import BandedMatrices: banded_qr!
Random.seed!(0)
Expand Down Expand Up @@ -131,3 +133,5 @@ Random.seed!(0)
end
end
end

end # module
8 changes: 6 additions & 2 deletions test/test_broadcasting.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestBroadcasting

using BandedMatrices, LinearAlgebra, ArrayLayouts, FillArrays, Test
import Base: BroadcastStyle
import Base.Broadcast: broadcasted
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -764,3 +766,5 @@ import BandedMatrices: BandedStyle, BandedRows, BandError
@test_throws BandError B[band(-100)] .= 10
end
end

end # module
4 changes: 4 additions & 0 deletions test/test_dot.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestDot

using BandedMatrices, LinearAlgebra, FillArrays, Test
import BandedMatrices: _BandedMatrix
using Random
Expand Down Expand Up @@ -36,3 +38,5 @@ using Random
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/test_indexing.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestIndexing

using BandedMatrices, LinearAlgebra, ArrayLayouts, Test

import BandedMatrices: rowstart, rowstop, colstart, colstop,
Expand Down Expand Up @@ -811,3 +813,5 @@ import BandedMatrices: rowstart, rowstop, colstart, colstop,
@test A[2:2:5,Base.OneTo(6)] isa Matrix
end
end

end # module
8 changes: 6 additions & 2 deletions test/test_interface.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -352,3 +354,5 @@ end
S = Symmetric(brand(10,10,1,2))
@test permutedims(S) ≡ S
end

end # module
4 changes: 3 additions & 1 deletion test/test_linalg.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module TestLinalg

using ArrayLayouts
using BandedMatrices
using FillArrays
using LinearAlgebra
using Quaternions
using Test

import Base.Broadcast: materialize, broadcasted
import BandedMatrices: BandedColumns, _BandedMatrix

@testset "Linear Algebra" begin
Expand Down Expand Up @@ -479,3 +480,4 @@ import BandedMatrices: BandedColumns, _BandedMatrix
end
end

end # module
6 changes: 5 additions & 1 deletion test/test_miscs.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -125,3 +127,5 @@ import BandedMatrices: _BandedMatrix, DefaultBandedMatrix
@test_throws BoundsError A[-5,-5+3]
end
end

end # module
7 changes: 6 additions & 1 deletion test/test_subarray.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -123,3 +126,5 @@ import BandedMatrices: BandedColumns, bandeddata, MemoryLayout, BandedSubBandedM
end
end
end

end # module
4 changes: 4 additions & 0 deletions test/test_symbanded.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestSymBanded

using ArrayLayouts
using BandedMatrices
import BandedMatrices: MemoryLayout, SymmetricLayout, HermitianLayout, BandedColumns, isbanded
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/test_tribanded.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module TestTriBanded

using BandedMatrices, LinearAlgebra, ArrayLayouts, Test
import BandedMatrices: BandedColumns, BandedRows, isbanded

Expand Down Expand Up @@ -113,3 +115,5 @@ import BandedMatrices: BandedColumns, BandedRows, isbanded
@test rot180(UnitLowerTriangular(B)) == rot180(Matrix(UnitLowerTriangular(B)))
end
end

end # module
Loading