Skip to content

Commit

Permalink
fix: in length handling of OperateOn
Browse files Browse the repository at this point in the history
I'm not certain the old implementation is buggy, but it is much easier to
verify the correctness of the new implementation
  • Loading branch information
haberdashPI committed Feb 3, 2020
1 parent 2d9e576 commit 5cd0ae2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/mapsignal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ SignalTrait(x::Type{<:MapSignal{<:Any,<:Any,<:Any,T,Fs,L}}) where {Fs,T,L} =
nchannels(x::MapSignal) = length(x.val)
framerate(x::MapSignal) = x.framerate

isnumbers(::Tuple{<:Number}) = true
isnumbers(xs) = false
function duration(x::MapSignal)
durs = duration.(x.padded_signals)
Ns = nframes_helper.(x.padded_signals)
Expand Down Expand Up @@ -146,14 +144,13 @@ function OperateOn(fn,xs...;
bychannel)
end

maxlen(x::Extended,y::Number) = max(x.len,y)
maxlen(x::Extended,y::Extended) = max(x.len,y.len)
maxlen(x::Extended,y::Infinite) = x.len
maxlen(x::NumberExtended,y) = y
maxlen(x::NumberExtended,y::Extended) = y.len
maxlen(x,y) = max(x,y)
maxlen(x,y::Extended) = max(x,y.len)
maxlen(x,y::NumberExtended) = x
tolen(x::Extended) = x.len
tolen(x::Number) = x
tolen(x::NumberExtended) = 0
tolen(x::InfiniteLength) = inflen
tolen(x::Missing) = missing
maxlen(x,y) = max(tolen(x),tolen(y))
maxlen(x::NumberExtended,y::NumberExtended) = x
nframes_helper(x::MapSignal) = reduce(maxlen,nframes_helper.(x.signals))

"""
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,15 @@ progress = Progress(total_test_groups,desc="Running tests...")

@test Extend(x,one) |> nframes == inflen
@test Mix(Extend(x,one),y) |> nframes == 15
@test Mix(y,Extend(x,one)) |> nframes == 15
@test Mix(Pad(x,one),y) |> nframes |> isinf
@test Mix(1,rand(10,2)) |> nframes == 10
@test Mix(1,Extend(rand(10,2),zero)) |> nframes == 10
@test Mix(rand(10,2),1) |> nframes == 10
@test Mix(Extend(rand(10,2),zero),1) |> nframes == 10
@test Mix(sin,1,rand(10,2)) |> nframes |> isinf
@test Mix(1,sin,rand(10,2)) |> nframes |> isinf
@test Mix(1,rand(10,2),sin) |> nframes |> isinf
end
end
next!(progress)
Expand Down Expand Up @@ -629,6 +635,8 @@ progress = Progress(total_test_groups,desc="Running tests...")
"100×2 Array{Float64,2}: … (10.0 Hz) |>\n Append(50×2 Array{Float64,2}: … (10.0 Hz))"
@test x |> Pad(zero) |> showstring ==
"100×2 Array{Float64,2}: … (10.0 Hz) |> Pad(zero)"
@test x |> Extend(zero) |> showstring ==
"100×2 Array{Float64,2}: … (10.0 Hz) |> Extend(zero)"
@test x |> Filt(Lowpass,3Hz) |> showstring ==
"100×2 Array{Float64,2}: … (10.0 Hz) |> Filt(Lowpass,3 Hz)"
@test x |> Normpower |> showstring ==
Expand Down

2 comments on commit 5cd0ae2

@haberdashPI
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/8846

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" 5cd0ae26e697e9faea0eb3dff508e0b2851254b7
git push origin v0.4.0

Please sign in to comment.