-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
map
over several tuples demands equal length
#42216
Comments
Copying from slack: If it is, it could be made consistent by adding these: julia> @eval Base map(f, ::Tuple{}, ::Tuple{Any}) = ()
map (generic function with 61 methods)
julia> @eval Base map(f, ::Tuple{Any}, ::Tuple{}) = ()
map (generic function with 62 methods)
julia> map(+, (1,2,3), (4,5))
(5, 7) though that won't fix the 3+ argument case. Might just need a |
I love that it throws an error, and I wish |
For usability, I think it's great that it throws an error, and it would be nice if The docstring was changed after the release of 1.6, so haven't appeared in any released Julia versions, so I don't think it's breaking to change it back. Arguably, it's the correct behaviour to error, since the canonical docstring says "[ ... ] by applying |
For once I actually wanted the early-stopping behaviour on tuples, yesterday. The fact that apparently nobody else did, for years, does make it seem like this isn't widely used. (And it's obviously easy to roll your own.) Agree that the stricter behaviour would avoid some surprises. But changing it for arrays (and iterators) sounds to me like it would be breaking. It just collects For arrays note also that |
The present behaviour for I don't actually see a test for I doubt that |
For |
python, ruby, haskell, rust ... do no error when lengths mismatch on zip call, so i think this is not a good reco. |
|
For |
I agree that two versions of But the question of this issue is
That difference of behaviour seems really surprising to me. Whichever you prefer, they should surely agree. To fix it, we can change Note also that
If we add an option to zip like |
It seems that julia> map(+, 1:2, 3:5000)
ERROR: DimensionMismatch("dimensions must match: a has dims (Base.OneTo(2),), b has dims (Base.OneTo(4998),), mismatch at 1")
julia> map(+, 1:2, (3,4,5,6,7))
2-element Array{Int64,1}:
4
6
julia> VERSION
v"1.4.2" Is that evidence that we could change it to be an error? |
I have always been a fan of allowing different lengths. But here's a point from triage: it might make sense to check up front and require length/shape matches for anything that has a definitive shape like an array, but for iterators allow mismatches. The reasoning is that with iterators, you have no choice but to start mapping, and only later find out whether the lengths matched, and it seems silly to "throw away" all the work. |
Also from triage: since we can't make this fully consistent now in a non-breaking way, we should probably change the tuple case to match other cases of map and zip like the docs say. |
Slight correction (I think): we can make it consistent, but only in the direction of making it more permissive. We already allow mismatched lengths for arrays and iterators in both map and zip. We also allow mismatched tuple lengths in zip but require matching tuple lengths in map only, i.e. this is an error: If we want a path to stricter length checking, we can do that by adding a |
Instead of stopping early like
zip
, this is an error:Is this a bug? It seems to be present at least since 1.0. The docstring for
map
saysbut I'm not sure I can quote it as authoratative, since I think I wrote it.
The text was updated successfully, but these errors were encountered: