Skip to content

Commit 09d8c8a

Browse files
JakobAsslaenderdpo
authored andcommitted
add test
1 parent 919d65d commit 09d8c8a

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

test/test_adjtrans.jl

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,88 @@ function test_adjtrans()
3434
end
3535

3636
test_adjtrans()
37+
38+
##
39+
function test_derived_adjoint()
40+
@testset ExtendedTestSet "Derived Adjoint" begin
41+
A = rand(5, 3) + im * rand(5, 3)
42+
43+
opA = LinearOperator{eltype(A)}(size(A,1), size(A,2), false, false,
44+
(y,x) -> (mul!(y,A,x)),
45+
(x,y) -> (mul!(x,transpose(A),y)),
46+
nothing)
47+
48+
aopA = AdjointLinearOperator(opA)
49+
copA = ConjugateLinearOperator(opA)
50+
topA = TransposeLinearOperator(opA)
51+
52+
for (foo, fop) in [(adjoint, aopA), (conj, copA), (transpose, topA)]
53+
@test foo(opA) === fop
54+
@test Matrix(fop) == foo(A)
55+
@test foo(fop) === opA
56+
57+
@test Matrix(-fop) == foo(-A)
58+
@test Matrix((2 + 3im) * fop) (2 + 3im) * foo(A)
59+
@test Matrix(fop * (2 + 3im)) foo(A) * (2 + 3im)
60+
end
61+
62+
@test adjoint(topA) === copA
63+
@test adjoint(copA) === topA
64+
@test conj(aopA) === topA
65+
@test conj(topA) === aopA
66+
@test transpose(copA) === aopA
67+
@test transpose(aopA) === copA
68+
69+
v = rand(5) + im * rand(5)
70+
@test aopA * v == adjoint(A) * v
71+
@test topA * v == transpose(A) * v
72+
73+
v = rand(3) + im * rand(3)
74+
@test copA * v == conj(A) * v
75+
end
76+
end
77+
78+
test_derived_adjoint()
79+
80+
81+
##
82+
function test_derived_transpose()
83+
@testset ExtendedTestSet "Derived Transpose" begin
84+
A = rand(5, 3) + im * rand(5, 3)
85+
86+
opA = LinearOperator{eltype(A)}(size(A,1), size(A,2), false, false,
87+
(y,x) -> (mul!(y,A,x)),
88+
nothing,
89+
(x,y) -> (mul!(x,adjoint(A),y)))
90+
91+
aopA = AdjointLinearOperator(opA)
92+
copA = ConjugateLinearOperator(opA)
93+
topA = TransposeLinearOperator(opA)
94+
95+
for (foo, fop) in [(adjoint, aopA), (conj, copA), (transpose, topA)]
96+
@test foo(opA) === fop
97+
@test Matrix(fop) == foo(A)
98+
@test foo(fop) === opA
99+
100+
@test Matrix(-fop) == foo(-A)
101+
@test Matrix((2 + 3im) * fop) (2 + 3im) * foo(A)
102+
@test Matrix(fop * (2 + 3im)) foo(A) * (2 + 3im)
103+
end
104+
105+
@test adjoint(topA) === copA
106+
@test adjoint(copA) === topA
107+
@test conj(aopA) === topA
108+
@test conj(topA) === aopA
109+
@test transpose(copA) === aopA
110+
@test transpose(aopA) === copA
111+
112+
v = rand(5) + im * rand(5)
113+
@test aopA * v == adjoint(A) * v
114+
@test topA * v == transpose(A) * v
115+
116+
v = rand(3) + im * rand(3)
117+
@test copA * v == conj(A) * v
118+
end
119+
end
120+
121+
test_derived_transpose()

0 commit comments

Comments
 (0)