-
Notifications
You must be signed in to change notification settings - Fork 2
halve
silently fails on zip collections
#68
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
Comments
@perrutquist Can you check which version you're using? This is what I see currently: julia> using SplittablesBase: halve
julia> halve(zip([1,2], [1,2,3]))
ERROR: ArgumentError: `halve(zip(...))` requires collections with identical `size`
Stacktrace:
[1] shape
@ ~/.julia/packages/SplittablesBase/FeYNd/src/implementations.jl:264 [inlined]
[2] checkshape
@ ~/.julia/packages/SplittablesBase/FeYNd/src/implementations.jl:258 [inlined]
[3] halve(xs::Base.Iterators.Zip{Tuple{Vector{Int64}, Vector{Int64}}})
@ SplittablesBase.Implementations ~/.julia/packages/SplittablesBase/FeYNd/src/implementations.jl:270
[4] top-level scope
@ REPL[5]:1 and it seems this was fixed back in 2020 by this PR: https://github.com/JuliaFolds/SplittablesBase.jl/pull/28/files If you have an example on a recent version of SplittablesBase.jl where this still fails though, please let me know so we can think up a fix. |
Here's an example of what I mean. Let Vector{Float64} be a stand-in for a user type, for which I define a (@v1.8) pkg> status SplittablesBase
Status `~/.julia/environments/v1.8/Project.toml`
[171d559e] SplittablesBase v0.1.15
julia> import SplittablesBase: halve
julia> function halve(xs::Vector{Float64})
mid = ceil(Int, length(xs)/2)
left = @view xs[firstindex(xs):firstindex(xs)-1+mid]
right = @view xs[firstindex(xs)+mid:end]
return (left, right)
end
halve (generic function with 20 methods)
julia> a = collect(1:5); b = float.(a);
julia> halve(zip(a,b))
(zip([1, 2], [1.0, 2.0, 3.0]), zip([3, 4, 5], [4.0, 5.0]))
julia> collect.(ans)
([(1, 1.0), (2, 2.0)], [(3, 4.0), (4, 5.0)]) |
The current implementation of
halve(zip(xs...))
essentially amounts tozip(map(halve, xs)...)
. This causes a problem whenhalve
splits collections differently. Each half is then a zip of different-length collections, and since zip stops iterating at the end of the shortest collection, some elements are silently left out.The text was updated successfully, but these errors were encountered: