Skip to content

Commit

Permalink
assert d -j >= 0 gone
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentcp committed Jan 10, 2017
1 parent b9b34f8 commit a8ae832
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
42 changes: 28 additions & 14 deletions src/dwt/discretewavelets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ function evaluate{T, S<:Real}(side::Side, kind::Scl, w::DiscreteWavelet{T}, j::I
end

function evaluate_periodic_in_dyadic_points{T}(side::Side, kind::Kind, w::DiscreteWavelet{T}, j=0, k=0, d=10; points=false, options...)
a = T(0); b = T(1)
s = evaluate_in_dyadic_points(side, kind, w, j ,k ,d)
L = round(Int, (1<<d)*(b-a))
@assert abs(L-(1<<d)*(b-a)) < eps(real(T))
f = _periodize(L, s, Int((1<<d)*DWT.support(side, kind, w, j, k)[1])+1)
if (d-j) >= 0
a = T(0); b = T(1)
s = evaluate_in_dyadic_points(side, kind, w, j ,k ,d)
L = round(Int, (1<<d)*(b-a))
@assert abs(L-(1<<d)*(b-a)) < eps(real(T))
f = _periodize(L, s, Int((1<<d)*DWT.support(side, kind, w, j, k)[1])+1)
else
f = evaluate_periodic_in_dyadic_points(side, kind, w, j, k, j; points=false, options...)
f = f[1:1<<(j-d):end]
end
if points
f, linspace(a,b,L+1)[1:end-1]
else
Expand All @@ -176,8 +181,12 @@ function evaluate_periodic_in_dyadic_points{T}(side::Side, kind::Kind, w::Discre
end

function evaluate_in_dyadic_points{T}(side::Side, kind::Kind, w::DiscreteWavelet{T}, j=0, k=0, d=10; points=false, options...)
@assert (d-j) >= 0
f = evaluate_in_dyadic_points(filter(side, kind, w), j, k, d; options...)
if (d-j) >= 0
f = evaluate_in_dyadic_points(filter(side, kind, w), j, k, d; points=false, options...)
else
f = evaluate_in_dyadic_points(filter(side, kind, w), j, k, j; options...)
f = f[1:1<<(j-d):end]
end
if points
f, dyadicpointsofcascade(side, kind, w, j, k, d; options...)
else
Expand All @@ -186,13 +195,18 @@ function evaluate_in_dyadic_points{T}(side::Side, kind::Kind, w::DiscreteWavelet
end

function evaluate_in_dyadic_points{T}(side::Side, kind::Wvl, w::DiscreteWavelet{T}, j=0, k=0, d=10; points=false, options...)
s = evaluate_in_dyadic_points(side, Scl(), w, j+1, k, d; options...)
filter = DWT.filter(side, Wvl(), w)
L = DWT.support_length(side, Wvl(), w)
f = zeros(T, (1<<(d-j))*L+1)
for (i,l) in enumerate(firstindex(filter):lastindex(filter))
offset = (1<<(d-1-j))*(i-1)
f[offset+1:offset+length(s)] += filter[l]*s
if (d-j) >= 0
s = evaluate_in_dyadic_points(side, Scl(), w, j+1, k, d; options...)
filter = DWT.filter(side, Wvl(), w)
L = DWT.support_length(side, Wvl(), w)
f = zeros(T, (1<<(d-j))*L+1)
for (i,l) in enumerate(firstindex(filter):lastindex(filter))
offset = (1<<(d-1-j))*(i-1)
f[offset+1:offset+length(s)] += filter[l]*s
end
else
f = evaluate_in_dyadic_points(side, kind, w, j, k, j; options...)
f = f[1:1<<(j-d):end]
end
if points
f, dyadicpointsofcascade(side, kind, w, j, k, d; options...)
Expand Down
1 change: 0 additions & 1 deletion src/dwt/dwttransform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ end
function idwt!
end

dwt_size(x, w::DiscreteWavelet, bnd::WaveletBoundary) = dwt_size(x, w, bnd)
dwt_size(x, w::DiscreteWavelet, bnd::WaveletBoundary) = dwt_size(x, Filterbank(w), bnd)
dwt_size(x, fb::Filterbank, bnd::WaveletBoundary) = length(x)

Expand Down
6 changes: 5 additions & 1 deletion src/dwt/util/cascade.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ dyadicpointsofcascade{T}(side::Side, kind::Kind, w::DiscreteWavelet{T}, j::Int,
function dyadicpointsofcascade{T}(side::Side, kind::Kind, w::DiscreteWavelet{T}, L::Int)
s = support(side, kind, w)
H = support_length(side, kind, w)
linspace(T(s[1]), T(s[2]), (1<<L)*H+1)
if L >= 0
linspace(T(s[1]), T(s[2]), (1<<L)*H+1)
else
[T(s[1])]
end
end

function _get_H(h)
Expand Down
6 changes: 3 additions & 3 deletions test/suite_dwtstep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ end
t = linspace(-1,1,N)
for f in (sin, characteristicfunction, randomfunction)
x = map(f,t)
for filter in (DWT.IMPLEMENTED_DB_WAVELETS..., DWT.IMPLEMENTED_CDF_WAVELETS...)
for w in (DWT.IMPLEMENTED_DB_WAVELETS..., DWT.IMPLEMENTED_CDF_WAVELETS...)
for bound in (DWT.perbound, DWT.symbound)
for L in 1:n
y = DWT.dwt(x, Filterbank(filter), DWT.perbound, L)
xx = DWT.idwt(y, Filterbank(filter), DWT.perbound, L)
y = DWT.dwt(x, w, DWT.perbound, L)
xx = DWT.idwt(y, w, DWT.perbound, L)
@test (norm(xx-x)) < 1e-10
end
end
Expand Down
4 changes: 4 additions & 0 deletions test/suite_evaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ end

function implementation_test()
@testset "$(rpad("Some simple tests",P))" begin
@test DWT.name(DWT.scaling) == "scaling"
@test DWT.name(DWT.wavelet) == "wavelet"
@test DWT.name(DWT.primal) == "primal"
@test DWT.name(DWT.dual) == "dual"
@test DWT.is_symmetric(DWT.TestWavelet{Float16}) == False
@test DWT.is_biorthogonal(DWT.TestWavelet{Float16}) == False
@test DWT.is_orthogonal(DWT.TestWavelet{Float16}) == False
Expand Down

0 comments on commit a8ae832

Please sign in to comment.