Skip to content

Commit 6939c3e

Browse files
committed
fix isadjoint test to work with complex range operators, move examples to test
1 parent e6b1ebd commit 6939c3e

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

Diff for: examples/LinearFunction_ForwardAndTranspose.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313

1414
# transpose function
1515
function fwdT(A::AbstractMatrix,vin::AbstractVector,RDT::DataType)
16-
vout=A'*vin
16+
vout=transpose(A)*vin
1717
return jo_convert(RDT,vout)
1818
end
1919

Diff for: src/joAbstractLinearOperator/extra_functions.jl

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function isadjoint(A::joAbstractLinearOperator{DDT,RDT},samples::Integer=3;tol::
6666
nfd=convert(DDT, normfactor)
6767
Axy=dot((A*x)/nfr,y)
6868
xAty=dot(x,(adjoint(A)*y)*nfd)
69+
xor(DDT<:Real, RDT<:Real) && (Axy = real(Axy); xAty = real(xAty))
6970
dif=abs(xAty-Axy); push!(DIF,dif)
7071
rer=abs(dif/Axy); push!(RER,rer)
7172
rto=abs(xAty/Axy); push!(RTO,rto)

Diff for: test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ verbose=false
1414

1515
# write your own tests here
1616
stime=time()
17+
include("test_type.jl")
1718
include("test_joMatrixSingle.jl")
1819
include("test_joMatrixProduct.jl")
1920
include("test_joMatrixSum.jl")

Diff for: test/test_type.jl

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
T=6
2+
tsname="joLinearFunction Type-enforced forward, transpose, adjoint and conj"
3+
@testset "$tsname" begin
4+
5+
# forward function
6+
function fwd(A::AbstractMatrix,vin::AbstractVector,RDT::DataType)
7+
vout=A*vin
8+
return jo_convert(RDT,vout)
9+
end
10+
11+
# adjoint function
12+
function fwdCT(A::AbstractMatrix,vin::AbstractVector,RDT::DataType)
13+
vout=A'*vin
14+
return jo_convert(RDT,vout)
15+
end
16+
17+
# transpose function
18+
function fwdT(A::AbstractMatrix,vin::AbstractVector,RDT::DataType)
19+
vout=transpose(A)*vin
20+
return jo_convert(RDT,vout)
21+
end
22+
23+
# define matrix for mapping functions
24+
a=rand(ComplexF32,3,3)
25+
26+
# define JOLI operator with real domain and complex range
27+
A1=joLinearFunctionFwd_A(3,3,
28+
v->fwd(a,v,ComplexF64),v->fwdCT(a,v,Float32),
29+
Float32,ComplexF64;name="my_A1")
30+
A2=joLinearFunctionFwd_T(3,3,
31+
v->fwd(a,v,ComplexF64),v->fwdT(a,v,Float32),
32+
Float32,ComplexF64;name="my_A2")
33+
34+
# disable warining for implicit inacurate conversions - use only after debugging your code
35+
jo_convert_warn_set(false)
36+
37+
x = rand(Float32, 3)
38+
y1 = A1 * x
39+
y2 = A2 * x
40+
@test typeof(y1) == Vector{ComplexF64}
41+
@test typeof(y2) == Vector{ComplexF64}
42+
43+
# note forced dropping imaginary part for transpose/adjoint operators
44+
y = randn(ComplexF64, 3)
45+
x1 = A1' * y
46+
x2 = A2' * y
47+
x3 = transpose(A1) * y
48+
x4 = transpose(A2) * y
49+
@test typeof(x1) == Vector{Float32}
50+
@test typeof(x2) == Vector{Float32}
51+
@test typeof(x3) == Vector{Float32}
52+
@test typeof(x4) == Vector{Float32}
53+
54+
@test isadjoint(A1)[1]
55+
@test isadjoint(A2)[1]
56+
57+
end

0 commit comments

Comments
 (0)