Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Partition() w/ size greater than the length of the input #529

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,12 @@ end
function complete(rf::R_{Partition}, result)
(i, s, buf), iresult = unwrap(rf, result)
if xform(rf).flush && s != xform(rf).step
iinput = @view buf[i:i + xform(rf).size - 1] # unsafe_view? @inbounds?
iinput = @view iinput[s + 1:end]
if s != 0
iinput = @view buf[i:i + xform(rf).size - 1] # unsafe_view? @inbounds?
iinput = @view iinput[s + 1:end]
else
iinput = @view buf[1:end]
end
iinput :: DenseSubVector
iresult = @next(inner(rf), iresult, iinput)
end
Expand Down
10 changes: 10 additions & 0 deletions test/test_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ end
[[1:4;], [5:8;], [9:i;]]
end
end
for w in 1:4
for s in [w,1]
@testset "w=$w, 1:$i" for i in 1:w
@testset for xs in iterator_variants(1:i)
@test xs |> Partition(w, s, flush=false) |> Map(copy) |> collect == (w == i ? [[1:i;]] : [])
@test xs |> Partition(w, s, flush=true) |> Map(copy) |> collect == [[1:i;]]
end
end
end
end
@testset "Combination with stateful transducers" begin
@testset for xs in iterator_variants(1:6)
@test xs |> Take(5) |> Partition(3, 1) |> Map(copy) |> collect ==
Expand Down