Skip to content

Commit 5084059

Browse files
committed
add clamp option to movingwindow
1 parent dcc80e9 commit 5084059

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/userfuncs.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ struct CapturedArgsFunc{F,A,KW}
3737
args::A
3838
kwargs::KW
3939
end
40-
(c::CapturedArgsFunc)(x) = c.f(x,c.args...;c.kwargs...)
41-
(c::CapturedArgsFunc)(x1,x2) = c.f(x1,x2,c.args...;c.kwargs...)
42-
(c::CapturedArgsFunc)(x1,x2,x3) = c.f(x1,x2,x3,c.args...;c.kwargs...)
43-
(c::CapturedArgsFunc)(x1,x2,x3,x4) = c.f(x1,x2,x3,x4,c.args...;c.kwargs...)
44-
(c::CapturedArgsFunc)(x1,x2,x3,x4,x5) = c.f(x1,x2,x3,x4,x5,c.args...;c.kwargs...)
45-
(c::CapturedArgsFunc)(x1,x2,x3,x4,x5,x6) = c.f(x1,x2,x3,x4,x5,x6,c.args...;c.kwargs...)
46-
(c::CapturedArgsFunc)(x...) = c.f(x...,c.args...;c.kwargs...)
40+
(c::CapturedArgsFunc)(x;rkwargs...) = c.f(x,c.args...;rkwargs...,c.kwargs...)
41+
(c::CapturedArgsFunc)(x1,x2;rkwargs...) = c.f(x1,x2,c.args...;rkwargs...,c.kwargs...)
42+
(c::CapturedArgsFunc)(x1,x2,x3;rkwargs...) = c.f(x1,x2,x3,c.args...;rkwargs...,c.kwargs...)
43+
(c::CapturedArgsFunc)(x1,x2,x3,x4;rkwargs...) = c.f(x1,x2,x3,x4,c.args...;rkwargs...,c.kwargs...)
44+
(c::CapturedArgsFunc)(x1,x2,x3,x4,x5;rkwargs...) = c.f(x1,x2,x3,x4,x5,c.args...;rkwargs...,c.kwargs...)
45+
(c::CapturedArgsFunc)(x1,x2,x3,x4,x5,x6;rkwargs...) = c.f(x1,x2,x3,x4,x5,x6,c.args...;rkwargs...,c.kwargs...)
46+
(c::CapturedArgsFunc)(x...;rkwargs...) = c.f(x...,c.args...;rkwargs...,c.kwargs...)
4747
Base.show(io::IO,f::CapturedArgsFunc) = show(io,f.f)
4848

4949
function create_userfunction(

src/windows.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,25 @@ function to_window(r)
138138
Window(r,ordering,overlap,sparsity)
139139
end
140140

141-
struct MovingWindow <: AbstractVector{UnitRange{Int}}
141+
struct MovingWindow{C} <: AbstractVector{UnitRange{Int}}
142142
first::Int
143143
steps::Int
144144
width::Int
145145
n::Int
146+
clamp::C
146147
end
148+
MovingWindow(first, steps, width, n) = MovingWindow(first, steps, width, n, nothing)
149+
147150
Base.size(m::MovingWindow) = (m.n,)
148-
Base.getindex(m::MovingWindow,i::Int) = (m.first+(i-1)*m.steps):(m.first+(i-1)*m.steps+m.width-1)
151+
Base.getindex(m::MovingWindow{Nothing}, i::Int) = (m.first+(i-1)*m.steps):(m.first+(i-1)*m.steps+m.width-1)
152+
Base.getindex(m::MovingWindow, i::Int) = max(first(m.clamp), m.first + (i - 1) * m.steps):min(last(m.clamp), m.first + (i - 1) * m.steps + m.width - 1)
149153
get_ordering(w::MovingWindow) = w.steps > 0 ? Increasing() : Decreasing()
150154
get_overlap(w::MovingWindow) = w.width > abs(w.steps) ? Overlapping() : NonOverlapping()
151155
get_sparsity(w::MovingWindow) = abs(w.steps) > 2*w.width ? Sparse(w.width/abs(w.steps)) : Dense()
152156
to_window(r::MovingWindow) = r
153157

158+
159+
154160
get_ordering(r::AbstractRange{Int}) = step(r)>0 ? Increasing() : Decreasing()
155161
get_overlap(r::AbstractRange{Int}) = NonOverlapping()
156162
get_sparsity(r::AbstractRange{Int}) = abs(step(r)) > 2 ? Sparse(1/abs(step(r))) : Dense()

0 commit comments

Comments
 (0)