|
88 | 88 | @test !(adjoint(M) == transpose(M))
|
89 | 89 | @test transpose(M') * v ≈ transpose(A') * v
|
90 | 90 | @test transpose(LinearMap(M')) * v ≈ transpose(A') * v
|
91 |
| - @test LinearMap(transpose(M))' * v ≈ copy(transpose(A))' * v |
| 91 | + @test LinearMap(transpose(M))' * v ≈ transpose(A)' * v |
92 | 92 | @test transpose(LinearMap(transpose(M))) * v ≈ Av
|
93 | 93 | @test adjoint(LinearMap(adjoint(M))) * v ≈ Av
|
| 94 | + |
| 95 | + @test mul!(copy(w), transpose(LinearMap(M')), v) ≈ transpose(A') * v |
| 96 | + @test mul!(copy(w), LinearMap(transpose(M))', v) ≈ transpose(A)' * v |
| 97 | + @test mul!(copy(w), transpose(LinearMap(transpose(M))), v) ≈ Av |
| 98 | + @test mul!(copy(w), adjoint(LinearMap(adjoint(M))), v) ≈ Av |
94 | 99 | @test mul!(copy(V), transpose(M), W) ≈ transpose(A) * W
|
| 100 | + @test mul!(copy(V), adjoint(M), W) ≈ A' * W |
95 | 101 |
|
96 | 102 | B = LinearMap(Symmetric(rand(10, 10)))
|
97 | 103 | @test transpose(B) == B
|
@@ -129,11 +135,17 @@ end
|
129 | 135 | @test Matrix(CS) == [1. 0.; 1. 1.]
|
130 | 136 | @test Array(CS) == [1. 0.; 1. 1.]
|
131 | 137 | CS = LinearMap(cumsum, 10; ismutating=false)
|
132 |
| - v = rand(ComplexF64, 10) |
| 138 | + v = rand(10) |
133 | 139 | cv = cumsum(v)
|
134 | 140 | @test CS * v == cv
|
135 | 141 | @test *(CS, v) == cv
|
136 | 142 | @test_throws ErrorException CS' * v
|
| 143 | + CS = LinearMap(cumsum, x -> cumsum(reverse(x)), 10; ismutating=false) |
| 144 | + cv = cumsum(v) |
| 145 | + @test CS * v == cv |
| 146 | + @test *(CS, v) == cv |
| 147 | + @test CS' * v == cumsum(reverse(v)) |
| 148 | + @test mul!(similar(v), transpose(CS), v) == cumsum(reverse(v)) |
137 | 149 |
|
138 | 150 | CS! = LinearMap(cumsum!, 10; ismutating=true)
|
139 | 151 | @test LinearMaps.ismutating(CS!)
|
|
143 | 155 | @test_throws ErrorException CS!'v
|
144 | 156 | @test_throws ErrorException transpose(CS!) * v
|
145 | 157 |
|
| 158 | + CS! = LinearMap{ComplexF64}(cumsum!, 10; ismutating=true) |
| 159 | + v = rand(ComplexF64, 10) |
| 160 | + cv = cumsum(v) |
| 161 | + @test LinearMaps.ismutating(CS!) |
| 162 | + @test CS! * v == cv |
| 163 | + @test *(CS!, v) == cv |
| 164 | + @test mul!(similar(v), CS!, v) == cv |
| 165 | + @test_throws ErrorException CS!'v |
| 166 | + @test_throws ErrorException adjoint(CS!) * v |
| 167 | + CS! = LinearMap{ComplexF64}(cumsum!, x -> cumsum!(reverse!(x)), 10; ismutating=true) |
| 168 | + @test LinearMaps.ismutating(CS!) |
| 169 | + @test CS! * v == cv |
| 170 | + @test *(CS!, v) == cv |
| 171 | + @test mul!(similar(v), CS!, v) == cv |
| 172 | + @test CS' * v == cumsum(reverse(v)) |
| 173 | + @test mul!(similar(v), transpose(CS), v) == cumsum(reverse(v)) |
| 174 | + @test mul!(similar(v), adjoint(CS), v) == cumsum(reverse(v)) |
| 175 | + |
146 | 176 | # Test fallback methods:
|
147 | 177 | L = LinearMap(x -> x, x -> x, 10)
|
148 | 178 | v = randn(10)
|
@@ -205,10 +235,13 @@ struct SimpleFunctionMap <: LinearMap{Float64}
|
205 | 235 | f::Function
|
206 | 236 | N::Int
|
207 | 237 | end
|
208 |
| -Base.size(A::SimpleFunctionMap) = (A.N, A.N) |
209 |
| -LinearAlgebra.issymmetric(A::SimpleFunctionMap) = false |
210 |
| -*(A::SimpleFunctionMap, v::Vector) = A.f(v) |
211 |
| -mul!(y::Vector, A::SimpleFunctionMap, x::Vector) = copyto!(y, *(A, x)) |
| 238 | +struct SimpleComplexFunctionMap <: LinearMap{Complex{Float64}} |
| 239 | + f::Function |
| 240 | + N::Int |
| 241 | +end |
| 242 | +Base.size(A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}) = (A.N, A.N) |
| 243 | +*(A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}, v::Vector) = A.f(v) |
| 244 | +mul!(y::Vector, A::Union{SimpleFunctionMap,SimpleComplexFunctionMap}, x::Vector) = copyto!(y, *(A, x)) |
212 | 245 |
|
213 | 246 | @testset "composition" begin
|
214 | 247 | F = LinearMap(cumsum, 10; ismutating=false)
|
@@ -249,11 +282,15 @@ mul!(y::Vector, A::SimpleFunctionMap, x::Vector) = copyto!(y, *(A, x))
|
249 | 282 | @test w ≈ LF * v
|
250 | 283 |
|
251 | 284 | # test new type
|
252 |
| - |
253 | 285 | F = SimpleFunctionMap(cumsum, 10)
|
| 286 | + FC = SimpleComplexFunctionMap(cumsum, 10) |
254 | 287 | @test ndims(F) == 2
|
255 | 288 | @test size(F, 1) == 10
|
256 | 289 | @test length(F) == 100
|
| 290 | + @test !issymmetric(F) |
| 291 | + @test !ishermitian(F) |
| 292 | + @test !ishermitian(FC) |
| 293 | + @test !isposdef(F) |
257 | 294 | w = similar(v)
|
258 | 295 | mul!(w, F, v)
|
259 | 296 | @test w == F * v
|
@@ -328,6 +365,8 @@ v = rand(ComplexF64, 10)
|
328 | 365 | w = similar(v)
|
329 | 366 | @testset "identity map" begin
|
330 | 367 | Id = LinearMaps.IdentityMap(10)
|
| 368 | + @test_throws ErrorException LinearMaps.IdentityMap(10, 20) |
| 369 | + @test_throws ErrorException LinearMaps.IdentityMap((10, 20)) |
331 | 370 | @test size(Id) == (10, 10)
|
332 | 371 | @test isreal(Id)
|
333 | 372 | @test issymmetric(Id)
|
|
0 commit comments