@@ -2,29 +2,38 @@ using LinearMaps, LinearAlgebra, Test
2
2
3
3
@testset " filled maps" begin
4
4
M, N = 2 , 3
5
- α = rand ()
6
- β = rand ()
7
5
μ = rand ()
8
6
for λ in (true , false , 3 , μ, μ + 2im )
9
7
L = LinearMap (λ, (M, N))
8
+ @test L == LinearMap (λ, M, N)
9
+ @test LinearMaps. MulStyle (L) === LinearMaps. FiveArg ()
10
10
A = fill (λ, (M, N))
11
11
x = rand (typeof (λ) <: Real ? Float64 : ComplexF64, 3 )
12
- X = rand (typeof (λ) <: Real ? Float64 : ComplexF64, 3 , 3 )
12
+ X = rand (typeof (λ) <: Real ? Float64 : ComplexF64, 3 , 4 )
13
13
w = similar (x, 2 )
14
- W = similar (X, 2 , 3 )
14
+ W = similar (X, 2 , 4 )
15
15
@test size (L) == (M, N)
16
16
@test adjoint (L) == LinearMap (adjoint (λ), (3 ,2 ))
17
17
@test transpose (L) == LinearMap (λ, (3 ,2 ))
18
18
@test Matrix (L) == A
19
19
@test L * x ≈ A * x
20
20
@test mul! (w, L, x) ≈ A * x
21
21
@test mul! (W, L, X) ≈ A * X
22
- @test mul! (copy (w), L, x, α, β) ≈ A * x * α + w * β
23
- @test mul! (copy (W), L, X, α, β) ≈ A * X * α + W * β
22
+ for α in (true , false , 1 , 0 , randn ()), β in (true , false , 1 , 0 , randn ())
23
+ @test mul! (copy (w), L, x, α, β) ≈ fill (λ * sum (x) * α, M) + w * β
24
+ @test mul! (copy (W), L, X, α, β) ≈ λ * reduce (vcat, sum (X, dims= 1 ) for _ in 1 : 2 ) * α + W * β
25
+ end
24
26
end
25
- @test issymmetric (LinearMap (μ + 0im , (3 , 3 )))
27
+ @test issymmetric (LinearMap (μ + 1im , (3 , 3 )))
28
+ @test ishermitian (LinearMap (μ + 0im , (3 , 3 )))
29
+ @test isposdef (LinearMap (μ, (1 ,1 ))) == isposdef (μ)
30
+ @test ! isposdef (LinearMap (μ, (3 ,3 )))
31
+ α = rand ()
32
+ β = rand ()
26
33
@test LinearMap (μ, (M, N)) + LinearMap (α, (M, N)) == LinearMap (μ + α, (M, N))
27
34
@test LinearMap (μ, (M, N)) - LinearMap (α, (M, N)) == LinearMap (μ - α, (M, N))
28
35
@test α* LinearMap (μ, (M, N)) == LinearMap (α * μ, (M, N))
29
36
@test LinearMap (μ, (M, N))* α == LinearMap (μ * α, (M, N))
37
+ @test LinearMap (μ, (M, N))* LinearMap (μ, (N, M)) == LinearMap (μ^ 2 * N, (M, M))
38
+ @test Matrix (LinearMap (μ, (M, N))* LinearMap (μ, (N, M))) == fill (μ, (M, N))* fill (μ, (N, M))
30
39
end
0 commit comments