Skip to content

Commit 9c80300

Browse files
committed
update tests
1 parent 5b7e539 commit 9c80300

File tree

10 files changed

+82
-86
lines changed

10 files changed

+82
-86
lines changed

test/blockmap.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays, BenchmarkTools, Interactive
77
A12 = rand(elty, 10, n2)
88
v = rand(elty, 10)
99
L = @inferred hcat(LinearMap(A11), LinearMap(A12))
10+
@test occursin("10×$(10+n2) LinearMaps.BlockMap{$elty}", sprint((t, s) -> show(t, "text/plain", s), L))
1011
@test @inferred(LinearMaps.MulStyle(L)) === matrixstyle
1112
@test L isa LinearMaps.BlockMap{elty}
1213
if elty <: Complex
@@ -45,6 +46,7 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays, BenchmarkTools, Interactive
4546
@test Matrix(L) A11
4647
A21 = rand(elty, 20, 10)
4748
L = @inferred vcat(LinearMap(A11), LinearMap(A21))
49+
@test occursin("30×10 LinearMaps.BlockMap{$elty}", sprint((t, s) -> show(t, "text/plain", s), L))
4850
@test L isa LinearMaps.BlockMap{elty}
4951
@test @inferred(LinearMaps.MulStyle(L)) === matrixstyle
5052
@test (@which [A11; A21]).module != LinearMaps
@@ -193,6 +195,7 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays, BenchmarkTools, Interactive
193195
@test (@which cat(M1, M2, M3, M2, M1; dims=(1,2))).module != LinearMaps
194196
x = randn(elty, size(Md, 2))
195197
Bd = @inferred blockdiag(L1, L2, L3, L2, L1)
198+
@test occursin("25×39 LinearMaps.BlockDiagonalMap{$elty}", sprint((t, s) -> show(t, "text/plain", s), Bd))
196199
@test Matrix(Bd) == Md
197200
@test convert(AbstractMatrix, Bd) isa SparseMatrixCSC
198201
@test sparse(Bd) == Md

test/composition.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays
2222
F2 = F*F
2323
FC2 = FC*FC
2424
F4 = FC2 * F2
25+
@test occursin("10×10 LinearMaps.CompositeMap{Complex{Float64}}", sprint((t, s) -> show(t, "text/plain", s), F4))
2526
@test length(F4.maps) == 4
2627
@test @inferred F4 * v == @inferred F * (F * (F * (F * v)))
2728
@test @inferred Matrix(M * transpose(M)) A * transpose(A)

test/functionmap.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
1717
MyFT = @inferred LinearMap{ComplexF64}(myft, N) / sqrt(N)
1818
U = Matrix(MyFT) # will be a unitary matrix
1919
@test @inferred U'U Matrix{eltype(U)}(I, N, N)
20+
@test occursin("$N×$N LinearMaps.FunctionMap{Complex{Float64}}", sprint((t, s) -> show(t, "text/plain", s), MyFT))
2021

2122
CS = @inferred LinearMap(cumsum, 2)
2223
@test size(CS) == (2, 2)
@@ -33,6 +34,7 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
3334
@test *(CS, v) == cv
3435
@test_throws ErrorException CS' * v
3536
CS = @inferred LinearMap(cumsum, x -> reverse(cumsum(reverse(x))), 10; ismutating=false)
37+
@test occursin("10×10 LinearMaps.FunctionMap{Float64}", sprint((t, s) -> show(t, "text/plain", s), CS))
3638
cv = cumsum(v)
3739
@test @inferred CS * v == cv
3840
@test @inferred *(CS, v) == cv

test/kronecker.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays
99
LB = LinearMap(B)
1010
LK = @inferred kron(LA, LB)
1111
@test_throws AssertionError LinearMaps.KroneckerMap{Float64}((LA, LB))
12+
@test occursin("6×6 LinearMaps.KroneckerMap{Complex{Float64}}", sprint((t, s) -> show(t, "text/plain", s), LK))
1213
@test @inferred size(LK) == size(K)
1314
@test LinearMaps.MulStyle(LK) === LinearMaps.ThreeArg()
1415
for i in (1, 2)
@@ -68,6 +69,7 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays
6869
LA = LinearMap(A)
6970
LB = LinearMap(B)
7071
KS = @inferred kronsum(LA, B)
72+
@test occursin("6×6 LinearMaps.KroneckerSumMap{$elty}", sprint((t, s) -> show(t, "text/plain", s), KS))
7173
@test_throws ArgumentError kronsum(LA, [B B]) # non-square map
7274
KSmat = kron(A, Matrix(I, 2, 2)) + kron(Matrix(I, 3, 3), B)
7375
@test Matrix(KS) Matrix(kron(A, LinearMap(I, 2)) + kron(LinearMap(I, 3), B))

test/linearcombination.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
1111
n = 10
1212
L = sum(fill(CS!, n))
1313
@test_throws AssertionError LinearMaps.LinearCombination{Float64}((CS!, CS!))
14+
@test occursin("10×10 LinearMaps.LinearCombination{Complex{Float64}}", sprint((t, s) -> show(t, "text/plain", s), L))
1415
@test mul!(u, L, v) n * cumsum(v)
1516
b = @benchmarkable mul!($u, $L, $v, 2, 2)
1617
@test run(b, samples=5).allocs <= 1

test/linearmaps.jl

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,6 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays, BenchmarkTools
2121
@test length(M) == length(A)
2222
end
2323

24-
Av = A * v
25-
AV = A * V
26-
27-
@testset "mul! and *" begin
28-
for w in (vec(u), u)
29-
@test M * v == Av
30-
@test N * v == Av
31-
@test @inferred mul!(copy(w), M, v) == mul!(copy(w), A, v)
32-
b = @benchmarkable mul!($w, $M, $v)
33-
@test run(b, samples=3).allocs == 0
34-
@test @inferred mul!(copy(w), N, v) == mul!(copy(w), A, v)
35-
36-
# mat-vec-mul
37-
@test @inferred mul!(copy(w), M, v, 0, 0) == zero(w)
38-
@test @inferred mul!(copy(w), M, v, 0, 1) == w
39-
@test @inferred mul!(copy(w), M, v, 0, β) == β * w
40-
@test @inferred mul!(copy(w), M, v, 1, 1) Av + w
41-
@test @inferred mul!(copy(w), M, v, 1, β) Av + β * w
42-
@test @inferred mul!(copy(w), M, v, α, 1) α * Av + w
43-
@test @inferred mul!(copy(w), M, v, α, β) α * Av + β * w
44-
end
45-
46-
# test mat-mat-mul!
47-
@test @inferred mul!(copy(W), M, V, α, β) α * AV + β * W
48-
@test @inferred mul!(copy(W), M, V) AV
49-
@test typeof(M * V) <: LinearMap
50-
end
51-
5224
@testset "dimension checking" begin
5325
w = vec(u)
5426
@test_throws DimensionMismatch M * similar(v, length(v) + 1)
@@ -70,7 +42,7 @@ struct SimpleComplexFunctionMap <: LinearMap{Complex{Float64}}
7042
N::Int
7143
end
7244
Base.size(A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}) = (A.N, A.N)
73-
Base.:(*)(A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}, v::Vector) = A.f(v)
45+
Base.:(*)(A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}, v::AbstractVector) = A.f(v)
7446
LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}, x::AbstractVector) = copyto!(y, *(A, x))
7547

7648
@testset "new LinearMap type" begin
@@ -83,10 +55,12 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
8355
@test @inferred !ishermitian(F)
8456
@test @inferred !ishermitian(FC)
8557
@test @inferred !isposdef(F)
86-
v = rand(ComplexF64, 10)
87-
w = similar(v)
88-
mul!(w, F, v)
89-
@test w == F * v
58+
@test occursin("10×10 SimpleFunctionMap{Float64}", sprint((t, s) -> show(t, "text/plain", s), F))
59+
@test occursin("10×10 SimpleComplexFunctionMap{Complex{Float64}}", sprint((t, s) -> show(t, "text/plain", s), FC))
60+
α = rand(ComplexF64); β = rand(ComplexF64)
61+
v = rand(ComplexF64, 10); V = rand(ComplexF64, 10, 3)
62+
w = rand(ComplexF64, 10); W = rand(ComplexF64, 10, 3)
63+
@test mul!(w, F, v) === w == F * v
9064
@test_throws ErrorException F' * v
9165
@test_throws ErrorException transpose(F) * v
9266
@test_throws ErrorException mul!(w, adjoint(FC), v)
@@ -95,6 +69,11 @@ LinearAlgebra.mul!(y::AbstractVector, A::Union{SimpleFunctionMap,SimpleComplexFu
9569
L = LowerTriangular(ones(10, 10))
9670
@test FM == L
9771
@test F * v L * v
72+
# generic 5-arg mul! and matrix-mul!
73+
@test mul!(copy(w), F, v, α, β) L*v*α + w*β
74+
@test mul!(copy(W), F, V) L*V
75+
@test mul!(copy(W), F, V, α, β) L*V*α + W*β
76+
9877
Fs = sparse(F)
9978
@test SparseMatrixCSC(F) == Fs == L
10079
@test Fs isa SparseMatrixCSC

test/scaledmap.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
88
# real case
99
α = float(π)
1010
B = @inferred α * A
11+
@test occursin("7×7 LinearMaps.ScaledMap{Float64} with scale: ", sprint((t, s) -> show(t, "text/plain", s), B))
1112
x = rand(N)
1213

1314
@test @inferred size(B) == size(A)

test/transpose.jl

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,15 @@
11
using Test, LinearMaps, LinearAlgebra, SparseArrays
22

33
@testset "transpose/adjoint" begin
4-
A = 2 * rand(ComplexF64, (20, 10)) .- 1
5-
v = rand(ComplexF64, 10)
6-
w = rand(ComplexF64, 20)
7-
V = rand(ComplexF64, 10, 3)
8-
W = rand(ComplexF64, 20, 3)
9-
Av = A * v
10-
AV = A * V
11-
M = @inferred LinearMap(A)
12-
N = @inferred LinearMap(M)
13-
14-
@test @inferred M' * w == A' * w
15-
@test @inferred mul!(copy(V), adjoint(M), W) A' * W
16-
@test @inferred transpose(M) * w == transpose(A) * w
17-
@test @inferred transpose(LinearMap(transpose(M))) * v == A * v
18-
@test @inferred LinearMap(M')' * v == A * v
19-
@test @inferred(transpose(transpose(M))) === M
20-
@test @inferred(adjoint(adjoint(M))) === M
21-
Mherm = @inferred LinearMap(A'A)
22-
@test @inferred ishermitian(Mherm)
23-
@test @inferred !issymmetric(Mherm)
24-
@test @inferred !issymmetric(transpose(Mherm))
25-
@test @inferred ishermitian(transpose(Mherm))
26-
@test @inferred ishermitian(Mherm')
27-
@test @inferred isposdef(Mherm)
28-
@test @inferred isposdef(transpose(Mherm))
29-
@test @inferred isposdef(adjoint(Mherm))
30-
@test @inferred !(transpose(M) == adjoint(M))
31-
@test @inferred !(adjoint(M) == transpose(M))
32-
@test @inferred transpose(M') * v transpose(A') * v
33-
@test @inferred transpose(LinearMap(M')) * v transpose(A') * v
34-
@test @inferred LinearMap(transpose(M))' * v transpose(A)' * v
35-
@test @inferred transpose(LinearMap(transpose(M))) * v Av
36-
@test @inferred adjoint(LinearMap(adjoint(M))) * v Av
37-
38-
@test @inferred mul!(copy(w), transpose(LinearMap(M')), v) transpose(A') * v
39-
@test @inferred mul!(copy(w), LinearMap(transpose(M))', v) transpose(A)' * v
40-
@test @inferred mul!(copy(w), transpose(LinearMap(transpose(M))), v) Av
41-
@test @inferred mul!(copy(w), adjoint(LinearMap(adjoint(M))), v) Av
42-
@test @inferred mul!(copy(W), transpose(LinearMap(M')), V) transpose(A') * V
43-
@test @inferred mul!(copy(W), LinearMap(transpose(M))', V) transpose(A)' * V
44-
@test @inferred mul!(copy(W), transpose(LinearMap(transpose(M))), V) AV
45-
@test @inferred mul!(copy(W), adjoint(LinearMap(adjoint(M))), V) AV
46-
@test @inferred mul!(copy(V), transpose(M), W) transpose(A) * W
47-
@test @inferred mul!(copy(V), adjoint(M), W) A' * W
48-
49-
B = @inferred LinearMap(Symmetric(rand(10, 10)))
50-
@test transpose(B) == B
51-
@test B == transpose(B)
52-
53-
B = @inferred LinearMap(Hermitian(rand(ComplexF64, 10, 10)))
54-
@test adjoint(B) == B
55-
@test B == B'
56-
574
CS = @inferred LinearMap{ComplexF64}(cumsum, x -> reverse(cumsum(reverse(x))), 10; ismutating=false)
585
for transform in (adjoint, transpose)
596
@test transform(CS) != CS
607
@test CS != transform(CS)
618
@test transform(transform(CS)) == CS
629
@test LinearMaps.MulStyle(transform(CS)) === LinearMaps.MulStyle(CS)
6310
end
11+
@test occursin("10×10 LinearMaps.TransposeMap{Complex{Float64}}", sprint((t, s) -> show(t, "text/plain", s), transpose(CS)))
12+
@test occursin("10×10 LinearMaps.AdjointMap{Complex{Float64}}", sprint((t, s) -> show(t, "text/plain", s), adjoint(CS)))
6413
@test !(transpose(CS) == adjoint(CS))
6514
@test !(adjoint(CS) == transpose(CS))
6615
M = Matrix(CS)

test/uniformscalingmap.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
1010
v = rand(ComplexF64, 10)
1111
w = similar(v)
1212
Id = @inferred LinearMap(I, 10)
13+
@test occursin("10×10 LinearMaps.UniformScalingMap{Bool}", sprint((t, s) -> show(t, "text/plain", s), Id))
1314
@test_throws ErrorException LinearMaps.UniformScalingMap(1, 10, 20)
1415
@test_throws ErrorException LinearMaps.UniformScalingMap(1, (10, 20))
1516
@test size(Id) == (10, 10)

test/wrappedmap.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using Test, LinearMaps, LinearAlgebra
66
SA = A'A + I
77
SB = B'B + I
88
L = @inferred LinearMap{Float64}(A)
9+
@test occursin("10×20 LinearMaps.WrappedMap{Float64}", sprint((t, s) -> show(t, "text/plain", s), L))
910
MA = @inferred LinearMap(SA)
1011
MB = @inferred LinearMap(SB)
1112
@test eltype(Matrix{Complex{Float32}}(LinearMap(A))) <: Complex
@@ -15,4 +16,60 @@ using Test, LinearMaps, LinearAlgebra
1516
@test @inferred !issymmetric(MB)
1617
@test @inferred isposdef(MA)
1718
@test @inferred isposdef(MB)
19+
20+
A = 2 * rand(ComplexF64, (20, 10)) .- 1
21+
v = rand(ComplexF64, 10)
22+
w = rand(ComplexF64, 20)
23+
u = rand(ComplexF64, 20, 1)
24+
V = rand(ComplexF64, 10, 3)
25+
W = rand(ComplexF64, 20, 3)
26+
Av = A * v
27+
AV = A * V
28+
M = @inferred LinearMap(A)
29+
N = @inferred LinearMap(M)
30+
31+
@test @inferred M' * w == A' * w
32+
@test @inferred mul!(copy(V), adjoint(M), W) A' * W
33+
@test @inferred transpose(M) * w == transpose(A) * w
34+
@test @inferred transpose(LinearMap(transpose(M))) * v == A * v
35+
@test @inferred LinearMap(M')' * v == A * v
36+
@test @inferred(transpose(transpose(M))) === M
37+
@test @inferred(adjoint(adjoint(M))) === M
38+
Mherm = @inferred LinearMap(A'A)
39+
@test @inferred ishermitian(Mherm)
40+
@test @inferred !issymmetric(Mherm)
41+
@test @inferred !issymmetric(transpose(Mherm))
42+
@test @inferred ishermitian(transpose(Mherm))
43+
@test @inferred ishermitian(Mherm')
44+
@test @inferred isposdef(Mherm)
45+
@test @inferred isposdef(transpose(Mherm))
46+
@test @inferred isposdef(adjoint(Mherm))
47+
@test @inferred !(transpose(M) == adjoint(M))
48+
@test @inferred !(adjoint(M) == transpose(M))
49+
@test @inferred transpose(M') * v transpose(A') * v
50+
@test @inferred transpose(LinearMap(M')) * v transpose(A') * v
51+
@test @inferred LinearMap(transpose(M))' * v transpose(A)' * v
52+
@test @inferred transpose(LinearMap(transpose(M))) * v Av
53+
@test @inferred adjoint(LinearMap(adjoint(M))) * v Av
54+
55+
for w in (vec(u), u)
56+
@test @inferred mul!(copy(w), transpose(LinearMap(M')), v) transpose(A') * v
57+
@test @inferred mul!(copy(w), LinearMap(transpose(M))', v) transpose(A)' * v
58+
@test @inferred mul!(copy(w), transpose(LinearMap(transpose(M))), v) Av
59+
@test @inferred mul!(copy(w), adjoint(LinearMap(adjoint(M))), v) Av
60+
end
61+
@test @inferred mul!(copy(W), transpose(LinearMap(M')), V) transpose(A') * V
62+
@test @inferred mul!(copy(W), LinearMap(transpose(M))', V) transpose(A)' * V
63+
@test @inferred mul!(copy(W), transpose(LinearMap(transpose(M))), V) AV
64+
@test @inferred mul!(copy(W), adjoint(LinearMap(adjoint(M))), V) AV
65+
@test @inferred mul!(copy(V), transpose(M), W) transpose(A) * W
66+
@test @inferred mul!(copy(V), adjoint(M), W) A' * W
67+
68+
B = @inferred LinearMap(Symmetric(rand(10, 10)))
69+
@test transpose(B) == B
70+
@test B == transpose(B)
71+
72+
B = @inferred LinearMap(Hermitian(rand(ComplexF64, 10, 10)))
73+
@test adjoint(B) == B
74+
@test B == B'
1875
end

0 commit comments

Comments
 (0)