-
-
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
Define shape of some truncated zips #29927
Conversation
Needs to updated because of #29238, but I think the general idea is right. |
@martinholters Are you willing to look into this? It is perhaps easier for you than for me to understand what has to be done to achieve the same with the new parametrization. |
I think this a relatively direct translation of your approach: diff --git a/base/iterators.jl b/base/iterators.jl
index bebe8ac170..0d52ca4c2a 100644
--- a/base/iterators.jl
+++ b/base/iterators.jl
@@ -312,10 +312,11 @@ function _zip_min_length(is)
end
end
_zip_min_length(is::Tuple{}) = nothing
-size(z::Zip) = _promote_shape(map(size, z.is)...)
-axes(z::Zip) = _promote_shape(map(axes, z.is)...)
-_promote_shape(a, b...) = promote_shape(a, _promote_shape(b...))
-_promote_shape(a) = a
+size(z::Zip) = mapreduce(size, _zip_promote_shape, z.is)
+axes(z::Zip) = mapreduce(axes, _zip_promote_shape, z.is)
+_zip_promote_shape((a,)::Tuple{OneTo}, (b,)::Tuple{OneTo}) = (intersect(a, b),)
+_zip_promote_shape((m,)::Tuple{Integer},(n,)::Tuple{Integer}) = (min(m,n),)
+_zip_promote_shape(a, b) = promote_shape(a, b)
eltype(::Type{Zip{Is}}) where {Is<:Tuple} = _zip_eltype(Is)
_zip_eltype(::Type{Is}) where {Is<:Tuple} =
tuple_type_cons(eltype(tuple_type_head(Is)), _zip_eltype(tuple_type_tail(Is))) Please feel free to go ahead and update your PR with this. |
Thank you! I updated the PR with your help. |
Maybe helpful as a summary: Before
Now
|
Regarding the news, would this be considered a change, a fix, or an extension of functionality? The technical description of the change would be:
|
Ping? |
I added a news item. |
When would be a good time for you to review this? |
Bump. I was just bitten by this. |
Ping |
@JeffBezanson Please allow me to ping you on this. |
@maleadt, how do we run PkgEval on this? |
@nanosoldier I had to look it up as well... (It's only part of the README in JuliaCI/Nanosoldier.jl#64) |
Your test job has completed - possible new issues were detected. A full report can be found here. cc @maleadt |
Looks good. Nanosoldier reports 7 packages failed tests only on the current version, 10 packages passed tests only on the current version. Failures are due to lack of random seeding or time outs. |
The release candidate for Julia v1.4.0 is out, does this mean this also won't make the cut for 1.4 anymore?? |
I see, so maybe 1.5. |
Bump |
1 similar comment
Bump |
If CI passes I'm going to merge. This hasn't gotten discussed, but my general approach with stalled PRs that can't get dev attention is to merge so as to prevent passive stonewalling. |
(2, 5) | ||
(3, 6) ] | ||
@test eltype(z) == Tuple{Int,Int} | ||
@test_throws DimensionMismatch size(z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a test for axes
?
(-2, -2) (2, 2) | ||
(-3, -3) (3, 3)] | ||
@test eltype(z) == Tuple{Int,Int} | ||
@test size(z) == (3, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a test for axes
?
Co-Authored-By: Rafael Fourquet <[email protected]>
I incorporated @rfourquet ’s suggestions |
Thank you @mschauer and sorry this took so long to get merged! |
"Closes" #17928 (#17928 is closed, but should be open and would be closed... )
Zip truncates iterators to the shortest length. Currently,
length
reports the effective length if possible, butsize
gives aDimensionMismatch
. For azip
iteratorz
with one-dimensional components (HasShape{1}
components) defining the size as(length(z), )
andaxes
correspondingly allows fast collection and it is also whatcollect
expects to be defined as the iterator itself hasHasShape{1}
. But it is not clear how to define the size of truncated higher-dimensional iterators, so this is spared out. This makes the PR rather small and it should be not-breaking.#20499 was closed so I think truncating
zip
s are a reality now, I added a remark to the doc string.