Skip to content

Commit

Permalink
Merge pull request #44 from JuliaDSP/gfa/julia-compat-update
Browse files Browse the repository at this point in the history
Julia compatibility update
  • Loading branch information
gummif authored Aug 27, 2018
2 parents 2a86c52 + e0f2156 commit b127e4f
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 138 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
after_success:
- julia -e 'cd(Pkg.dir("Wavelets")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'VERSION >= v"0.7.0-DEV.5183" && using Pkg;
VERSION >= v"0.7.0-DEV.5183" || cd(Pkg.dir("Wavelets"));
Pkg.add("Coverage");
using Coverage;
Coveralls.submit(Coveralls.process_folder())'
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ m = 50
threshold!(xtb, BiggestTH(), m)
threshold!(xt, BiggestTH(), m)
# compare sparse approximations in ell_2 norm
vecnorm(x - iwpt(xtb, wt, tree), 2) # best basis wpt
vecnorm(x - idwt(xt, wt), 2) # regular dwt
norm(x - iwpt(xtb, wt, tree), 2) # best basis wpt
norm(x - idwt(xt, wt), 2) # regular dwt
```
```
julia> vecnorm(x - iwpt(xtb, wt, tree), 2)
julia> norm(x - iwpt(xtb, wt, tree), 2)
0.008941070750964843
julia> vecnorm(x - idwt(xt, wt), 2)
julia> norm(x - idwt(xt, wt), 2)
0.05964431178940861
```

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
Reexport 0.0.3
DSP 0.3.4
Compat 0.65
Compat 0.70
3 changes: 2 additions & 1 deletion src/mod/Plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export wplotdots, wplotim
using ..Util, ..WT, ..Transforms
using Compat.LinearAlgebra
using Compat: Nothing, undef
import Compat

# PLOTTING UTILITIES

Expand Down Expand Up @@ -86,7 +87,7 @@ function wplotim(x::AbstractArray, L::Integer, wt::Union{DiscreteWavelet,Nothing
xts[1:nsc,1:nsc,:] .= 0
scale01!(xts)
for j=1:n, i=1:n
@inbounds xts[i,j,:] .= vecnorm(xts[i,j,:],pnorm).^(power)
@inbounds xts[i,j,:] .= Compat.norm(xts[i,j,:],pnorm).^(power)
end

# merge and reshape final image
Expand Down
16 changes: 7 additions & 9 deletions src/mod/Threshold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export
using ..Util, ..WT, ..Transforms

using Compat.LinearAlgebra
using Compat.Statistics: median!
using Compat: copyto!, Nothing, undef, rmul!
import Compat

# THRESHOLD TYPES AND FUNCTIONS

Expand Down Expand Up @@ -191,7 +193,7 @@ function denoise(x::AbstractArray,
if ndims(x) == 1
z = similar(x)
for i = 1:pns
shift = nspin2circ(nspin, i)[1]
shift = i - 1
Util.circshift!(z, x, shift)

Transforms.dwt_oop!(xt, z, wt, L)
Expand Down Expand Up @@ -261,15 +263,11 @@ function mad!(y::AbstractArray)
end
return median!(y)
end
#function mad(x::AbstractArray)
# y = copy(x)
# mad!(y)
#end

# convert index i to a circshift array starting at 0 shift
nspin2circ(nspin::Int, i::Int) = nspin2circ((nspin,), i)
function nspin2circ(nspin::Tuple, i::Int)
c1 = ind2sub(nspin,i)
c1 = Compat.CartesianIndices(nspin)[i].I
c = Vector{Int}(undef, length(c1))
for k in 1:length(c1)
c[k] = c1[k]-1
Expand Down Expand Up @@ -302,7 +300,7 @@ function matchingpursuit(x::AbstractVector, f::Function, ft::Function, tol::Real
spat = zeros(eltype(x), length(y)) # sparse for atom computation
nmax == -1 && (nmax = length(y))

while vecnorm(r) > tol && n <= nmax
while Compat.norm(r) > tol && n <= nmax
# find largest inner product
!oop && (ftr = ft(r))
oop && ft(ftr, r, tmp)
Expand Down Expand Up @@ -362,7 +360,7 @@ function coefentropy(x::T, et::LogEnergyEntropy, nrm::T) where T<:AbstractFloat
return -log(s)
end
end
function coefentropy(x::AbstractArray{T}, et::Entropy, nrm::T=vecnorm(x)) where T<:AbstractFloat
function coefentropy(x::AbstractArray{T}, et::Entropy, nrm::T=Compat.norm(x)) where T<:AbstractFloat
@assert nrm >= 0
sum = zero(T)
nrm == sum && return sum
Expand All @@ -389,7 +387,7 @@ function bestbasistree(y::AbstractVector{T}, wt::DiscreteWavelet, tree::BitVecto
tmp = Vector{T}(undef, n)
ntree = length(tree)
entr_bf = Vector{T}(undef, ntree)
nrm = vecnorm(y)
nrm = Compat.norm(y)

Lmax = maxtransformlevels(n)
L = Lmax
Expand Down
8 changes: 4 additions & 4 deletions src/mod/transforms_maximal_overlap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function modwt_step(v::AbstractVector{T}, j::Integer, h::Array{S,1},
g::Array{S,1}) where {T <: Number, S <: Number}
N = length(v)
L = length(h)
v1 = zeros(v)
w1 = zeros(v)
v1 = zeros(T, N)
w1 = zeros(T, N)
for t in 1:N
k = t
w1[t] = h[1] * v[k]
Expand Down Expand Up @@ -52,7 +52,7 @@ function modwt(x::AbstractVector{T}, wt::OrthoFilter,
g /= sqrt(2)
h /= sqrt(2)
N = length(x)
W = zeros(N, L)
W = zeros(T, N, L)
V = deepcopy(x)
for j in 1:L
V[:], W[:, j] = modwt_step(V, j, h, g)
Expand All @@ -75,7 +75,7 @@ function imodwt_step(v::AbstractVector{T}, w::AbstractVector{T}, j::Integer,
throw(DimensionMismatch("Filter sizes must match"))
N = length(v)
L = length(h)
v0 = zeros(N)
v0 = zeros(T, N)
for t in 1:N
k = t
v0[t] = h[1] * w[k] + g[1] * v[k]
Expand Down
4 changes: 1 addition & 3 deletions test/plot.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@

let
print("plot: execute functions ...\n")
@testset "Utils" begin
J = 8
n = 2^J
x = testfunction(n, "Bumps")
y = dwt(x, wavelet(WT.cdf97, WT.Lifting))
d,l = wplotdots(y, 0.1, n)
A = wplotim(y)


x = randn(64,64)
L = 2
xts = wplotim(x, L, wavelet(WT.db3, WT.Filter))
Expand Down
39 changes: 20 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
using Wavelets
using Base.Test
using Compat.Test
using Compat.LinearAlgebra
using Compat.DelimitedFiles
using Compat: ComplexF64, copyto!, range
import Compat

# modified from Base.Test
function test_vecnorm_eq(va, vb, Eps, astr, bstr)
function vecnorm_eq(va, vb, Eps, astr="a", bstr="b")
if length(va) != length(vb)
error("lengths of ", astr, " and ", bstr, " do not match: ",
"\n ", astr, " (length $(length(va))) = ", va,
"\n ", bstr, " (length $(length(vb))) = ", vb)
#error("lengths of ", astr, " and ", bstr, " do not match: ",
# "\n ", astr, " (length $(length(va))) = ", va,
# "\n ", bstr, " (length $(length(vb))) = ", vb)
return false
end
diff = vecnorm(va - vb)

if !isnan(Eps) && !(diff <= Eps)
sdiff = string("|", astr, " - ", bstr, "| <= ", Eps)
error("assertion failed: ", sdiff,
"\n difference = ", diff, " > ", Eps)
diff = Compat.norm(va - vb)
if !isnan(Eps) && diff > Eps
#sdiff = string("|", astr, " - ", bstr, "| <= ", Eps)
#error("assertion failed: ", sdiff,
# "\n difference = ", diff, " > ", Eps)
return false
end
return true
end
macro test_vecnorm_eq_eps(a, b, c)
:(test_vecnorm_eq($(esc(a)), $(esc(b)), $(esc(c)), $(string(a)), $(string(b))))
macro vecnorm_eq_eps(a, b, c)
:(vecnorm_eq($(esc(a)), $(esc(b)), $(esc(c)), $(string(a)), $(string(b))))
end


include("util.jl")
include("transforms.jl")
include("threshold.jl")
include("plot.jl")

print("\ntesting: success\n")
@testset "Util" begin include("util.jl") end
@testset "Transforms" begin include("transforms.jl") end
@testset "Threshold" begin include("threshold.jl") end
@testset "Plot" begin include("plot.jl") end
14 changes: 4 additions & 10 deletions test/threshold.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

print("threshold: execute functions ...\n")

#threshold
let
@testset "Threshold" begin # TODO @test something
x = randn(200)*2
for th in (BiggestTH(), HardTH(), SoftTH(), SemiSoftTH(), SteinTH())
threshold(x, th, 2)
Expand All @@ -12,8 +9,7 @@ let
end
end

# denoising
let
@testset "Denoising" begin
vs = VisuShrink(10)
n = 2^8
x0 = testfunction(n, "Doppler")
Expand All @@ -25,8 +21,7 @@ let
y = denoise(randn(32,32), TI=true)
end

# best basis
let
@testset "Best basis" begin
wt = wavelet(WT.db4)
x = sin.(4*range(0, stop=2*pi-eps(), length=1024))
tree = bestbasistree(x, wt)
Expand All @@ -39,8 +34,7 @@ let
@test iwpt(xtb, wt, tree) x
end

#matching pursuit
let
@testset "Matching pursuit" begin
N = 128
M = 64
y=randn(N)
Expand Down
Loading

0 comments on commit b127e4f

Please sign in to comment.