Skip to content

Commit 461aee7

Browse files
authored
Minor fixes and cleaned up/more tests (#30)
* fix typo in identitymap * generate undef Vectors * tests: clean up and add new
1 parent 164f67e commit 461aee7

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

src/identitymap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ At_mul_B!(y::AbstractVector, A::IdentityMap, x::AbstractVector) =
2424
(length(x) == length(y) == A.M ? copyto!(y, x) : throw(DimensionMismatch("At_mul_B!")))
2525

2626
Ac_mul_B!(y::AbstractVector, A::IdentityMap, x::AbstractVector) =
27-
(length(x) == length(y) == A.M ? copyto!(y, x) : throw(tMismatch("Ac_mul_B!")))
27+
(length(x) == length(y) == A.M ? copyto!(y, x) : throw(DimensionMismatch("Ac_mul_B!")))
2828

2929
# combine LinearMap and UniformScaling objects in linear combinations
3030
Base.:(+)(A1::LinearMap, A2::UniformScaling{T}) where {T} = A1 + A2[1,1] * IdentityMap{T}(size(A1, 1))

test/runtests.jl

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,61 +22,39 @@ end
2222
A = 2 * rand(ComplexF64, (20, 10)) .- 1
2323
v = rand(ComplexF64, 10)
2424
w = rand(ComplexF64, 20)
25-
wdest = copy(w)
2625
V = rand(ComplexF64, 10, 3)
2726
W = rand(ComplexF64, 20, 3)
28-
Wdest = copy(W)
2927
α = rand()
3028
β = rand()
3129

3230
# test wrapped map for matrix
3331
M = LinearMap(A)
3432
@test M * v == A * v
35-
mul!(Wdest, M, V)
36-
@test Wdest A * V
33+
@test mul!(w, M, v) == A * v
34+
@test mul!(copy(W), M, V) A * V
3735
@test typeof(M * V) <: LinearMap
36+
@test LinearMap(M) * v == A * v
3837

3938
# test of mul!
40-
mul!(wdest, M, v, 0, 0)
41-
@test wdest == zero(w)
42-
wdest = copy(w)
43-
mul!(wdest, M, v, 0, 1)
44-
@test wdest == w
45-
wdest = copy(w)
46-
mul!(wdest, M, v, 0, β)
47-
@test wdest == β * w
48-
wdest = copy(w)
49-
mul!(wdest, M, v, 1, 1)
50-
@test wdest A * v + w
51-
wdest = copy(w)
52-
mul!(wdest, M, v, 1, β)
53-
@test wdest A * v + β * w
54-
wdest = copy(w)
55-
mul!(wdest, M, v, α, 1)
56-
@test wdest α * A * v + w
57-
wdest = copy(w)
58-
mul!(wdest, M, v, α, β)
59-
@test wdest α * A * v + β * w
60-
wdest = copy(w)
61-
mul!(wdest, M, v, α)
62-
@test wdest α * A * v
39+
@test mul!(copy(w), M, v, 0, 0) == zero(w)
40+
@test mul!(copy(w), M, v, 0, 1) == w
41+
@test mul!(copy(w), M, v, 0, β) == β * w
42+
@test mul!(copy(w), M, v, 1, 1) A * v + w
43+
@test mul!(copy(w), M, v, 1, β) A * v + β * w
44+
@test mul!(copy(w), M, v, α, 1) α * A * v + w
45+
@test mul!(copy(w), M, v, α, β) α * A * v + β * w
46+
@test mul!(copy(w), M, v, α) α * A * v
6347

6448
# test matrix-mul!
65-
Wdest = copy(W)
66-
mul!(Wdest, M, V, α, β)
67-
@test Wdest α * A * V + β * W
68-
Wdest = copy(W)
69-
mul!(Wdest, M, V, α)
70-
@test Wdest α * A * V
49+
@test mul!(copy(W), M, V, α, β) α * A * V + β * W
50+
@test mul!(copy(W), M, V, α) α * A * V
7151

7252
# test transposition and Matrix
7353
@test M' * w == A' * w
74-
mul!(V, adjoint(M), W)
75-
@test V A' * W
76-
54+
@test mul!(copy(V), adjoint(M), W) A' * W
7755
@test transpose(M) * w == transpose(A) * w
78-
mul!(V, transpose(M), W)
79-
@test V transpose(A) * W
56+
@test transpose(M') * v transpose(A') * v
57+
@test mul!(copy(V), transpose(M), W) transpose(A) * W
8058

8159
@test Matrix(M) == A
8260
@test Array(M) == A
@@ -99,7 +77,7 @@ B = LinearMap(Hermitian(rand(ComplexF64, 10, 10)))
9977
@test convert(SparseMatrixCSC, M) == sparse(Array(M))
10078

10179
B = copy(A)
102-
B[rand(1:length(A), 30)] .= 0.
80+
B[rand(1:length(A), 30)] .= 0
10381
MS = LinearMap(B)
10482
@test sparse(MS) == sparse(Array(MS))
10583

@@ -130,7 +108,9 @@ v = randn(10);
130108

131109
# test linear combinations
132110
A = 2 * rand(ComplexF64, (10, 10)) .- 1
111+
B = rand(size(A)...)
133112
M = LinearMap(A)
113+
N = LinearMap(B)
134114
v = rand(ComplexF64, 10)
135115

136116
@test Matrix(3 * M) == 3 * A
@@ -140,20 +120,33 @@ v = rand(ComplexF64, 10)
140120
@test (3 * M - 1im * F)' == 3 * M' + 1im * F'
141121

142122
@test (2 * M' + 3 * I) * v (2 * A' + 3 * I) * v
123+
@test transpose(LinearMap(2 * M' + 3 * I)) * v transpose(2 * A' + 3 * I) * v
124+
@test LinearMap(2 * M' + 3 * I)' * v (2 * A' + 3 * I)' * v
143125

144126
# test composition
145127
@test (F * F) * v == F * (F * v)
146128
@test (F * A) * v == F * (A * v)
147129
@test Matrix(M * transpose(M)) A * transpose(A)
148130
@test !isposdef(M * transpose(M))
149131
@test isposdef(M * M')
132+
@test issymmetric(N * N')
133+
@test ishermitian(N * N')
134+
@test !issymmetric(M' * M)
135+
@test ishermitian(M' * M)
150136
@test isposdef(transpose(F) * F)
151137
@test isposdef((M * F)' * M * F)
152138
@test transpose(M * F) == transpose(F) * transpose(M)
153-
154139
L = 3 * F + 1im * A + F * M' * F
155140
LF = 3 * Matrix(F) + 1im * A + Matrix(F) * Matrix(M)' * Matrix(F)
156141
@test Array(L) LF
142+
R1 = rand(ComplexF64, 10, 10)
143+
R2 = rand(ComplexF64, 10, 10)
144+
R3 = rand(ComplexF64, 10, 10)
145+
CompositeR = prod(R -> LinearMap(R), [R1, R2, R3])
146+
Lt = transpose(LinearMap(CompositeR))
147+
@test Lt * v transpose(R3) * transpose(R2) * transpose(R1) * v
148+
Lc = adjoint(LinearMap(CompositeR))
149+
@test Lc * v R3' * R2' * R1' * v
157150

158151
# test inplace operations
159152
w = similar(v)

0 commit comments

Comments
 (0)