Skip to content

Commit

Permalink
Rearrange tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Dec 22, 2024
1 parent 8d9b14f commit dd9fe42
Show file tree
Hide file tree
Showing 10 changed files with 1,116 additions and 1,043 deletions.
38 changes: 16 additions & 22 deletions test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ using LinearAlgebra: BlasReal, BlasFloat

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")

isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
using .Main.Furlongs

isdefined(Main, :Quaternions) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Quaternions.jl"))
using .Main.Quaternions

Expand Down Expand Up @@ -354,36 +351,33 @@ Random.seed!(1)
@test norm(x-tx,Inf) <= 4*condT*max(eps()*norm(tx,Inf), eps(promty)*norm(x,Inf))
end
@testset "Specialized multiplication/division" begin
getval(x) = x
getval(x::Furlong) = x.val
function _bidiagdivmultest(T,
x,
typemul=T.uplo == 'U' ? UpperTriangular : Matrix,
typediv=T.uplo == 'U' ? UpperTriangular : Matrix,
typediv2=T.uplo == 'U' ? UpperTriangular : Matrix)
TM = Matrix(T)
@test map(getval, (T*x)::typemul) map(getval, TM*x)
@test map(getval, (x*T)::typemul) map(getval, x*TM)
@test map(getval, (x\T)::typediv) map(getval, x\TM)
@test map(getval, (T/x)::typediv) map(getval, TM/x)
@test (T*x)::typemul TM*x
@test (x*T)::typemul x*TM
@test (x\T)::typediv x\TM
@test (T/x)::typediv TM/x
if !isa(x, Number)
@test map(getval, Array((T\x)::typediv2)) map(getval, Array(TM\x))
@test map(getval, Array((x/T)::typediv2)) map(getval, Array(x/TM))
@test Array((T\x)::typediv2) Array(TM\x)
@test Array((x/T)::typediv2) Array(x/TM)
end
return nothing
end
A = Matrix(T)
for t in (T, Furlong.(T)), (A, dv, ev) in ((A, dv, ev), (Furlong.(A), Furlong.(dv), Furlong.(ev)))
_bidiagdivmultest(t, 5, Bidiagonal, Bidiagonal)
_bidiagdivmultest(t, 5I, Bidiagonal, Bidiagonal, t.uplo == 'U' ? UpperTriangular : LowerTriangular)
_bidiagdivmultest(t, Diagonal(dv), Bidiagonal, Bidiagonal, t.uplo == 'U' ? UpperTriangular : LowerTriangular)
_bidiagdivmultest(t, UpperTriangular(A))
_bidiagdivmultest(t, UnitUpperTriangular(A))
_bidiagdivmultest(t, LowerTriangular(A), t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix)
_bidiagdivmultest(t, UnitLowerTriangular(A), t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix)
_bidiagdivmultest(t, Bidiagonal(dv, ev, :U), Matrix, Matrix, Matrix)
_bidiagdivmultest(t, Bidiagonal(dv, ev, :L), Matrix, Matrix, Matrix)
end
t = T
_bidiagdivmultest(t, 5, Bidiagonal, Bidiagonal)
_bidiagdivmultest(t, 5I, Bidiagonal, Bidiagonal, t.uplo == 'U' ? UpperTriangular : LowerTriangular)
_bidiagdivmultest(t, Diagonal(dv), Bidiagonal, Bidiagonal, t.uplo == 'U' ? UpperTriangular : LowerTriangular)
_bidiagdivmultest(t, UpperTriangular(A))
_bidiagdivmultest(t, UnitUpperTriangular(A))
_bidiagdivmultest(t, LowerTriangular(A), t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix)
_bidiagdivmultest(t, UnitLowerTriangular(A), t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix, t.uplo == 'L' ? LowerTriangular : Matrix)
_bidiagdivmultest(t, Bidiagonal(dv, ev, :U), Matrix, Matrix, Matrix)
_bidiagdivmultest(t, Bidiagonal(dv, ev, :L), Matrix, Matrix, Matrix)
end
end

Expand Down
19 changes: 0 additions & 19 deletions test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ using Test, LinearAlgebra, Random
using LinearAlgebra: BlasFloat, BlasComplex

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
using .Main.Furlongs

isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
using .Main.OffsetArrays
Expand Down Expand Up @@ -470,23 +468,6 @@ Random.seed!(1)
@test svdvals(D) == s
@test svd(D).V == V
end

@testset "svd/eigen with Diagonal{Furlong}" begin
Du = Furlong.(D)
@test Du isa Diagonal{<:Furlong{1}}
F = svd(Du)
U, s, V = F
@test map(x -> x.val, Matrix(F)) map(x -> x.val, Du)
@test svdvals(Du) == s
@test U isa AbstractMatrix{<:Furlong{0}}
@test V isa AbstractMatrix{<:Furlong{0}}
@test s isa AbstractVector{<:Furlong{1}}
E = eigen(Du)
vals, vecs = E
@test Matrix(E) == Du
@test vals isa AbstractVector{<:Furlong{1}}
@test vecs isa AbstractMatrix{<:Furlong{0}}
end
end

@testset "axes" begin
Expand Down
10 changes: 0 additions & 10 deletions test/givens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ using LinearAlgebra: Givens, Rotation, givensAlgorithm
end
end

# 36430
# dimensional correctness:
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
using .Main.Furlongs

@testset "testing dimensions with Furlongs" begin
@test_throws MethodError givens(Furlong(1.0), Furlong(2.0), 1, 2)
end

const TNumber = Union{Float64,ComplexF64}
struct MockUnitful{T<:TNumber} <: Number
data::T
Expand Down
61 changes: 16 additions & 45 deletions test/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ module TestHessenberg
using Test, LinearAlgebra, Random

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
using .Main.Furlongs

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
using .Main.SizedArrays

Expand Down Expand Up @@ -68,29 +65,20 @@ let n = 10
@test Array(Hc + H) == Array(Hc) + Array(H)
@test Array(Hc - H) == Array(Hc) - Array(H)
@testset "Preserve UpperHessenberg shape (issue #39388)" begin
for H = (UpperHessenberg(Areal), UpperHessenberg(Furlong.(Areal)))
if eltype(H) <: Furlong
A = Furlong.(rand(n,n))
d = Furlong.(rand(n))
dl = Furlong.(rand(n-1))
du = Furlong.(rand(n-1))
us = Furlong(1)*I
else
A = rand(n,n)
d = rand(n)
dl = rand(n-1)
du = rand(n-1)
us = 1*I
end
@testset "$op" for op = (+,-)
for x = (us, Diagonal(d), Bidiagonal(d,dl,:U), Bidiagonal(d,dl,:L),
Tridiagonal(dl,d,du), SymTridiagonal(d,dl),
UpperTriangular(A), UnitUpperTriangular(A))
@test op(H,x) == op(Array(H),x)
@test op(x,H) == op(x,Array(H))
@test op(H,x) isa UpperHessenberg
@test op(x,H) isa UpperHessenberg
end
H = UpperHessenberg(Areal)
A = rand(n,n)
d = rand(n)
dl = rand(n-1)
du = rand(n-1)
us = 1*I
@testset "$op" for op = (+,-)
for x = (us, Diagonal(d), Bidiagonal(d,dl,:U), Bidiagonal(d,dl,:L),
Tridiagonal(dl,d,du), SymTridiagonal(d,dl),
UpperTriangular(A), UnitUpperTriangular(A))
@test op(H,x) == op(Array(H),x)
@test op(x,H) == op(x,Array(H))
@test op(H,x) isa UpperHessenberg
@test op(x,H) isa UpperHessenberg
end
end
H = UpperHessenberg(Areal)
Expand All @@ -102,8 +90,8 @@ let n = 10
UpperTriangular(A), UnitUpperTriangular(A))
@test (H*x)::UpperHessenberg Array(H)*x
@test (x*H)::UpperHessenberg x*Array(H)
@test H/x Array(H)/x# broken = eltype(H) <: Furlong && x isa UpperTriangular
@test x\H x\Array(H)# broken = eltype(H) <: Furlong && x isa UpperTriangular
@test H/x Array(H)/x
@test x\H x\Array(H)
@test H/x isa UpperHessenberg
@test x\H isa UpperHessenberg
end
Expand All @@ -113,23 +101,6 @@ let n = 10
@test H/x == Array(H)/x
@test x\H == x\Array(H)
end
H = UpperHessenberg(Furlong.(Areal))
for A in (A, Furlong.(A))
@testset "Multiplication/division Furlong" begin
for x = (5, 5I, Diagonal(d), Bidiagonal(d,dl,:U),
UpperTriangular(A), UnitUpperTriangular(A))
@test map(x -> x.val, (H*x)::UpperHessenberg) map(x -> x.val, Array(H)*x)
@test map(x -> x.val, (x*H)::UpperHessenberg) map(x -> x.val, x*Array(H))
@test map(x -> x.val, (H/x)::UpperHessenberg) map(x -> x.val, Array(H)/x)
@test map(x -> x.val, (x\H)::UpperHessenberg) map(x -> x.val, x\Array(H))
end
x = Bidiagonal(d, dl, :L)
@test H*x == Array(H)*x
@test x*H == x*Array(H)
@test H/x == Array(H)/x
@test x\H == x\Array(H)
end
end
end
end

Expand Down
16 changes: 0 additions & 16 deletions test/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,22 +338,6 @@ include("trickyarithmetic.jl")
@test B isa LinearAlgebra.LU{ElT,Matrix{ElT}}
end

# dimensional correctness:
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
using .Main.Furlongs

@testset "lu factorization with dimension type" begin
n = 4
A = Matrix(Furlong(1.0) * I, n, n)
F = lu(A).factors
@test Diagonal(F) == Diagonal(A)
# upper triangular part has a unit Furlong{1}
@test all(x -> typeof(x) == Furlong{1, Float64}, F[i,j] for j=1:n for i=1:j)
# lower triangular part is unitless Furlong{0}
@test all(x -> typeof(x) == Furlong{0, Float64}, F[i,j] for j=1:n for i=j+1:n)
end

@testset "Issue #30917. Determinant of integer matrix" begin
@test det([1 1 0 0 1 0 0 0
1 0 1 0 0 1 0 0
Expand Down
26 changes: 0 additions & 26 deletions test/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ end
end
end

# for testing types with a dimension
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
using .Main.Furlongs

@testset "zero and one for structured matrices" begin
for elty in (Int64, Float64, ComplexF64)
D = Diagonal(rand(elty, 10))
Expand Down Expand Up @@ -440,27 +435,6 @@ using .Main.Furlongs
@test one(T) isa Tridiagonal
@test zero(S) isa SymTridiagonal
@test one(S) isa SymTridiagonal

# eltype with dimensions
D0 = Diagonal{Furlong{0, Int64}}([1, 2, 3, 4])
Bu0 = Bidiagonal{Furlong{0, Int64}}([1, 2, 3, 4], [1, 2, 3], 'U')
Bl0 = Bidiagonal{Furlong{0, Int64}}([1, 2, 3, 4], [1, 2, 3], 'L')
T0 = Tridiagonal{Furlong{0, Int64}}([1, 2, 3], [1, 2, 3, 4], [1, 2, 3])
S0 = SymTridiagonal{Furlong{0, Int64}}([1, 2, 3, 4], [1, 2, 3])
F2 = Furlongs.Furlong{2}(1)
D2 = Diagonal{Furlong{2, Int64}}([1, 2, 3, 4].*F2)
Bu2 = Bidiagonal{Furlong{2, Int64}}([1, 2, 3, 4].*F2, [1, 2, 3].*F2, 'U')
Bl2 = Bidiagonal{Furlong{2, Int64}}([1, 2, 3, 4].*F2, [1, 2, 3].*F2, 'L')
T2 = Tridiagonal{Furlong{2, Int64}}([1, 2, 3].*F2, [1, 2, 3, 4].*F2, [1, 2, 3].*F2)
S2 = SymTridiagonal{Furlong{2, Int64}}([1, 2, 3, 4].*F2, [1, 2, 3].*F2)
mats = Any[D0, Bu0, Bl0, T0, S0, D2, Bu2, Bl2, T2, S2]
for A in mats
@test iszero(zero(A))
@test isone(one(A))
@test zero(A) == zero(Matrix(A))
@test one(A) == one(Matrix(A))
@test eltype(one(A)) == typeof(one(eltype(A)))
end
end

@testset "== for structured matrices" begin
Expand Down
2 changes: 2 additions & 0 deletions test/testgroups
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
triangular
triangular2
addmul
bidiag
bitarray
matmul
dense
symmetric
diagonal
unitful
special
qr
cholesky
Expand Down
Loading

0 comments on commit dd9fe42

Please sign in to comment.