Skip to content

Commit 778c760

Browse files
committed
Update tests
1 parent 919a67e commit 778c760

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/analysis_tools.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ Assumes that both arrays are 2 dimensional
99
* [Rainer Heintzmann, \"Estimating missing information by maximum likelihood deconvolution\"](https://www.sciencedirect.com/science/article/abs/pii/S0968432806001272)
1010
"""
1111
function relative_energy_regain(ground_truth, rec)
12+
T = eltype(ground_truth)
1213
# go to fourier space
1314
ground_truth_fft = fft(ground_truth)
1415
rec_fft = fft(rec)
1516

1617
# a dict to store the values for certain frequencies
1718
# we store a list since some (rounded) frequencies occur more than once
18-
ΔE_R_dict = Dict{Float64, Vector{Float64}}()
19-
E_R_dict = Dict{Float64, Vector{Float64}}()
19+
ΔE_R_dict = Dict{T, Vector{T}}()
20+
E_R_dict = Dict{T, Vector{T}}()
2021

2122
# round the frequencies to 4 digits, alternative would be to bin
22-
round4(x) = round(x, digits=3)
23+
round4(x) = T(round(x, digits=3))
2324

2425

2526
# iterate over the frequencies and calculate the relative energy regain
@@ -37,13 +38,12 @@ function relative_energy_regain(ground_truth, rec)
3738

3839
# finally transform everything into a list of frequencies and
3940
# a list of relative energy regains
40-
freqs = Float64[]
41-
G_R_list = Float64[]
42-
for f in sort(Float64.(keys(ΔE_R_dict)))
41+
freqs = T[]
42+
G_R_list = T[]
43+
for f in sort(T.(keys(ΔE_R_dict)))
4344
push!(freqs, f)
4445
mean_ΔE_r = mean(ΔE_R_dict[f])
4546
mean_E_r = mean(E_R_dict[f])
46-
4747
push!(G_R_list, (mean_E_r - mean_ΔE_r) / mean_E_r)
4848
end
4949

src/hessian_schatten_norm.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ end
6969

7070
function schatten_norm_tullio(H11, H12, H22, p)
7171
λ₁, λ₂ = eigvals_symmetric_tullio(H11, H12, H22)
72-
return @tullio res = (1f-8 + λ₁[i, j]^p + λ₂[i, j]^p)^(1/p)
72+
return @tullio res = abs((1f-8 + λ₁[i, j]^p + λ₂[i, j]^p))^(1/p)
7373
end
7474

7575
"""

test/hessian_schatten_norm.jl

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
@testset "Test eigvals" begin
3+
4+
function f(a1::T,b1,c1) where T
5+
a = Array{T, 2}(undef, 1, 1)
6+
a[1,1] = a1
7+
b = Array{T, 2}(undef, 1, 1)
8+
b[1,1] = b1
9+
c = Array{T, 2}(undef, 1, 1)
10+
c[1,1] = c1
11+
@test all(.≈(DeconvOptim.eigvals_symmetric_tullio(a,b,c), DeconvOptim.eigvals_symmetric(a,b,c)))
12+
end
13+
14+
f(10.0, 20.0, -10.0)
15+
f(0f0, -12f0, 13f0)
16+
end
17+
18+
19+
@testset "Schatten norm consistent" begin
20+
21+
x = [1 2 3; 1 1 1; 0 0 -1f0]
22+
@test DeconvOptim.HSp(x, p = 1) 0.9999999900000001
23+
@test DeconvOptim.HSp(x, p = 2) 1.732050831647567
24+
@test abs.(DeconvOptim.HSp(x, p = 1)) DeconvOptim.HS1(x)
25+
end

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818

1919

2020
include("analysis_tools.jl")
21+
include("hessian_schatten_norm.jl")
2122
include("conv.jl")
2223
include("mappings.jl")
2324

0 commit comments

Comments
 (0)