Skip to content

Commit 8d94f09

Browse files
committed
More dot syntax & update use of Compat
Revert changes of 29d641d and 8d90bae that avoided a::Number + r::Range (related to https://discourse.julialang.org/t/broadcast-operations-with-ranges/10139, which has been fixed in Julia 0.7-alpha). Add using StatsBase Remove @compat for Julia < 0.6, add Compat.SparseArrays.sparse
1 parent a466ace commit 8d94f09

File tree

8 files changed

+37
-35
lines changed

8 files changed

+37
-35
lines changed

REQUIRE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
julia 0.6
22
Distances 0.3.1
33
Compat 0.62.0
4+
StatsBase
5+

src/RecurrenceAnalysis.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module RecurrenceAnalysis
22

3-
using Distances, Compat
3+
using Distances, StatsBase, Compat
44
using Compat.SparseArrays, Compat.LinearAlgebra
55
import Compat.String
66
import Base.Meta.parse
@@ -47,7 +47,7 @@ end
4747
function colvals(x::SparseMatrixCSC)
4848
cv = zeros(Int,nnz(x))
4949
@inbounds for c=1:size(x,2)
50-
cv[nzrange(x,c)] = c
50+
cv[nzrange(x,c)] .= c
5151
end
5252
cv
5353
end
@@ -75,7 +75,7 @@ function embed_indices(x::AbstractMatrix, indices)
7575
dx = size(x)
7676
dxm = size(indices)
7777
ix_rep = repeat(indices, inner=[1,dx[2]])
78-
ix_rep += repeat(dx[1]*(0:dx[2]-1)', outer=[dxm...])
78+
ix_rep .+= repeat(dx[1].*(0:dx[2]-1)', outer=[dxm...])
7979
x[ix_rep]
8080
end
8181

@@ -117,7 +117,7 @@ function recurrencematrix(x, radius; scale=1, kwargs...)
117117
argsdm = haskey(kwargs,:metric) ? (x, kwargs[:metric]) : (x,)
118118
dm = distancematrix(argsdm...)
119119
(typeof(scale) <: Function) && (scale = scale(dm))
120-
sparse(dm .< radius*scale)
120+
Compat.SparseArrays.sparse(dm .< radius*scale)
121121
end
122122

123123
"""
@@ -132,7 +132,7 @@ function crossrecurrencematrix(x, y, radius; scale=1, kwargs...)
132132
argsdm = haskey(kwargs,:metric) ? (x, y, kwargs[:metric]) : (x, y)
133133
dm = distancematrix(argsdm...)
134134
(typeof(scale) <: Function) && (scale = scale(dm))
135-
sparse(dm .< radius*scale)
135+
Compat.SparseArrays.sparse(dm .< radius*scale)
136136
end
137137

138138
"""

src/delay.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function gmi(x, delay::Integer, radius::Real)
128128
rm1 = rmfull[1:n, 1:n]
129129
h2 = -log2(nnz(rm1)/n^2)
130130
# Joint entropy
131-
rmj = rm1 .* rmfull[delay+(1:n), delay+(1:n)]
131+
rmj = rm1 .* rmfull[delay.+(1:n), delay.+(1:n)]
132132
h2tau = -log2(nnz(rmj)/n^2)
133133
# Maximum entropy for a given radius corresponds to uniform distribution
134134
maxh2 = log2((maximum(x)-minimum(x))/radius)
@@ -146,7 +146,7 @@ function gmi(x, delay::Union{Array, AbstractRange}, radius::Real)
146146
# Joint entropy
147147
rmj = spzeros(n, n)
148148
for d in delay
149-
rmj = rm1 .* rmfull[(1+d):(n+d), (1+d):(n+d)]
149+
rmj = rm1 .* rmfull[d.+(1:n), d.+(1:n)]
150150
h2tau[d+1] = -log2(nnz(rmj)/n^2)
151151
end
152152
# Maximum entropy for a given radius corresponds to uniform distribution

src/dimension.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ function embedmatrix1(x::Array{T, 2}, delay, metric = "max") where T
33
dist = getmetric(metric)
44
fun = Dict(Euclidean()=>+, Chebyshev()=>max)[dist]
55
nr, nc = size(x)
6-
@compat x .= abs2.(x)
7-
@compat y = sqrt.(fun.(x[1:nr-delay, 1:nc-delay], x[1+delay:nr, 1+delay:nc]))
6+
x .= abs2.(x)
7+
y = sqrt.(fun.(x[1:nr-delay, 1:nc-delay], x[1+delay:nr, 1+delay:nc]))
88
Array{T,2}(y)
99
end
1010

@@ -29,7 +29,7 @@ function fnn(x, mbounds, delay, thresholds; metric="max")
2929
# Start with matrix embedded at m=m1
3030
dm = distancematrix(embed(x, m1, delay), metric)
3131
n = size(dm)[1]
32-
dm[1:n+1:end] = maximum(dm)
32+
dm[1:n+1:end] .= maximum(dm)
3333
for m = 1:length(nfnn)
3434
# Look for nearest neighbours within the first n-delay
3535
n -= delay
@@ -39,7 +39,7 @@ function fnn(x, mbounds, delay, thresholds; metric="max")
3939
nnv2 = dm[1:n,1:n][nnpos]
4040
fnn1 = ( ((nnv2.^2)./(nnv1.^2) .- 1) .> Rtol2 )
4141
fnn2 = ( (nnv2/Ra) .> Atol )
42-
@compat nfnn[m] = sum(fnn1 .| fnn2)
42+
nfnn[m] = sum(fnn1 .| fnn2)
4343
end
4444
nfnn
4545
end
@@ -58,7 +58,7 @@ function afnn(x, mbounds, delay; metric="max")
5858
m1, m2 = mbounds
5959
dm = distancematrix(embed(x, m1, delay), metric)
6060
n = size(dm)[1]
61-
dm[1:n+1:end] = maximum(dm)
61+
dm[1:n+1:end] .= maximum(dm)
6262
mean_ratio = zeros(m2-m1+2)
6363
mean_increment = zeros(m2-m1+2)
6464
for m = 1:length(mean_ratio)
@@ -71,7 +71,7 @@ function afnn(x, mbounds, delay; metric="max")
7171
# Project nnpos in original series
7272
nnx = [coord[2] for coord in nnpos]
7373
d = (m1+m-1)*delay
74-
@compat mean_increment[m] = mean(abs.(x[(1+d):(n+d)] .- x[nnx .+ d]))
74+
mean_increment[m] = mean(abs.(x[(1:n).+d] .- x[nnx .+ d]))
7575
end
7676
e1 = mean_ratio[2:end]./mean_ratio[1:end-1]
7777
e2 = mean_increment[2:end]./mean_increment[1:end-1]
@@ -92,7 +92,7 @@ function ffnn(x, mbounds, delay; metric="max")
9292
m1, m2 = mbounds
9393
dm = distancematrix(embed(x, m1, delay), metric)
9494
n = size(dm)[1]
95-
dm[1:n+1:end] = maximum(dm)
95+
dm[1:n+1:end] .= maximum(dm)
9696
fnn_ratio = zeros(m2-m1+1)
9797
for m = 1:length(fnn_ratio)
9898
n -= delay

src/radius.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function radius_mrr(x::AbstractVector, rr::Real)
77
d = zeros(lx)
88
for i=1:lx
99
dxs = xs[max(1,i-nr+1):min(lx,i+nr-1)] - xs[i]
10-
@compat d[i] = sort(abs.(dxs))[nr]
10+
d[i] = sort(abs.(dxs))[nr]
1111
end
1212
median(d)
1313
end
@@ -39,7 +39,7 @@ function sorteddistances(x; theiler::Integer=0, scale=maximum, kwargs...)
3939
pos = 0
4040
for d = theiler:n-1
4141
tmp = dm[n*d+1 : n+1 : n^2]
42-
distarray[(1+pos):(length(tmp)+pos)] = tmp
42+
distarray[pos .+ (1:length(tmp))] = tmp
4343
pos += length(tmp)
4444
end
4545
sort(distarray), (1.:length(distarray))/length(distarray)

src/rqa.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function diagonalhistogram(x::AbstractMatrix{Bool}; theiler::Integer=1, kwargs..
3737
# Iterate over diagonals - excluding LOI and Theiler window
3838
# If the matrix is symmetric, examine only the upper triangle
3939
diag_collection = collect(theiler:n-2)
40-
@compat xsym = issymmetric(x)
40+
xsym = issymmetric(x)
4141
!xsym && prepend!(diag_collection, collect(-(m-2):-max(theiler,1)))
4242
for d in diag_collection
4343
increment = (xsym && d > 0) ? 2 : 1
@@ -74,15 +74,15 @@ function diagonalhistogram(x::SparseMatrixCSC{Bool}; theiler::Integer=1, kwargs.
7474
m,n=size(x)
7575
rv = rowvals(x)
7676
dv = colvals(x) - rowvals(x)
77-
@compat if issymmetric(x)
77+
if issymmetric(x)
7878
valid = (dv .>= theiler)
7979
f = 2
8080
else
81-
@compat valid = (abs.(dv) .>= theiler)
81+
valid = (abs.(dv) .>= theiler)
8282
f = 1
8383
end
84-
vmat = sparse(rv[valid], dv[valid]+m+1, true)
85-
f*verticalhistogram(vmat)
84+
vmat = sparse(rv[valid], dv[valid] .+ (m+1), true)
85+
f .* verticalhistogram(vmat)
8686
end
8787

8888
"""
@@ -154,7 +154,7 @@ function entropy(diag_hist::Vector; lmin=2, kwargs...)
154154
if lmin <= nbins
155155
prob_bins = diag_hist[lmin:nbins] ./ sum(diag_hist[lmin:nbins])
156156
prob_bins = prob_bins[findall(!iszero, prob_bins)]
157-
@compat typeof(0.0)( -sum(prob_bins .* log.(prob_bins)) )
157+
typeof(0.0)( -sum(prob_bins .* log.(prob_bins)) )
158158
else
159159
0.0
160160
end
@@ -184,7 +184,7 @@ end
184184

185185
# Number of l-length sequences, based on diagonals
186186
function countsequences(diag_hist::Vector; lmin=2, kwargs...)
187-
overlap = (1:length(diag_hist))' - lmin + 1
187+
overlap = (1:length(diag_hist))' .- (lmin+1)
188188
overlap[overlap .< 0] = 0
189189
overlap * diag_hist
190190
end

src/windowed.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ function ij_block_rmat(x, y, bsize, dindex, vargs...; kwargs...)
2525
rws = (Int)[]
2626
cls = (Int)[]
2727
for i=abs(dindex):n_fullblocks-1
28-
ix = i*bsize + brange
29-
iy = i*bsize + brange
28+
ix = i*bsize .+ brange
29+
iy = i*bsize .+ brange
3030
if dindex < 0
31-
iy -= -dindex*bsize
31+
iy = iy .+ dindex*bsize
3232
elseif dindex > 0
33-
ix -= dindex*bsize
33+
ix = ix .- dindex*bsize
3434
end
3535
rmat_b = crossrecurrencematrix(x[ix,:], y[iy,:], vargs...; kwargs...)
3636
append!(rws, rowvals(rmat_b) .+ix[1] .- 1)
@@ -94,10 +94,10 @@ macro windowed(ex, options...)
9494
if in(f, rqa_funs)
9595
@gensym w s nw i
9696
x = ex.args[2]
97-
submat = :($x[(1+$i):($w+$i), (1+$i):($w+$i)])
97+
submat = :($x[$i.+$w,$i.+$w])
9898
ex.args[2] = submat
9999
ret_ex = quote
100-
$w = $(dict_op[:width])
100+
$w = 1:$(dict_op[:width])
101101
$s = $(dict_op[:step])
102102
$nw = size($x,1) - $(dict_op[:width])
103103
($(rqa_types[f]))[$ex for $i=0:$s:$nw]
@@ -108,10 +108,10 @@ macro windowed(ex, options...)
108108
if f == :rqa
109109
@gensym w s nw ni rqa_dict i rqa_i k v
110110
x = ex.args[2]
111-
submat = :($x[(($i-1)*$s+1):(($i-1)*$s+$w), (($i-1)*$s+1):(($i-1)*$s+$w)])
111+
submat = :($x[($i-1)*$s.+$w,($i-1)*$s.+$w])
112112
ex.args[2] = submat
113113
ret_ex = quote
114-
$w = $(dict_op[:width])
114+
$w = 1:$(dict_op[:width])
115115
$s = $(dict_op[:step])
116116
$nw = size($x,1) - $(dict_op[:width])
117117
$ni = div($nw, $s)+1
@@ -159,7 +159,7 @@ macro windowed(ex, options...)
159159
$exd_upper
160160
append!($i, $ii)
161161
append!($j, $jj)
162-
sparse($i,$j,true,size($x,1),size($y,1))
162+
Compat.SparseArrays.sparse($i,$j,true,size($x,1),size($y,1))
163163
end
164164
return esc(ret_ex)
165165
elseif f == :recurrencematrix
@@ -180,7 +180,7 @@ macro windowed(ex, options...)
180180
append!($i,$ii)
181181
append!($j,$jj)
182182
$n = size($x,1)
183-
sparse($i,$j,true,$n,$n)
183+
Compat.SparseArrays.sparse($i,$j,true,$n,$n)
184184
end
185185
return esc(ret_ex)
186186
elseif f == :jointrecurrencematrix
@@ -199,7 +199,7 @@ macro windowed(ex, options...)
199199
ret_ex = quote
200200
$ex_rmx
201201
$ex_rmy
202-
@compat $rm1 .& $rm2
202+
$rm1 .& $rm2
203203
end
204204
return esc(ret_ex)
205205
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ rqapar = rqa(rmat, theiler=2, lmin=5, border=20)
6767
rmatw = @windowed recurrencematrix(xe, 1.5) 50
6868
crmatw = @windowed(crossrecurrencematrix(x, y, 1.5),30)
6969
@windowed jrmatw = jointrecurrencematrix(x, y, 1.5) 30
70-
@test jrmatw[(34:63),(34:63)] == jrmat[(34:63), (34:63)]
70+
@test jrmatw[33 .+ (1:30), 33 .+ (1:30)] == jrmat[33 .+ (1:30), 33 .+ (1:30)]
7171
@windowed(rrw = recurrencerate(rmatw), width=50, step=40)
7272
@windowed rqaw = rqa(rmatw) width=50 step=40
7373
@test rqaw["RR"] == rrw

0 commit comments

Comments
 (0)