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

Iteratorsize for partition iterator #16552

Merged
merged 2 commits into from
Jul 12, 2017
Merged

Conversation

mschauer
Copy link
Contributor

@mschauer mschauer commented May 24, 2016

Before, collect of a partition could fail because it assumed the existence of a length method via the iteratorsize fall back.

@test v[2] == [3,4]
@test v[3] == [5]
let v1 = collect(Base.partition([1,2,3,4,5], 2)), v2 = collect(Base.partition(Base.flatten([1,2,3,4,5]), 2))
@test v1[1] == v1[1] == [1,2]
Copy link
Contributor

Choose a reason for hiding this comment

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

presumably this should be v1[1] == v2[1] ?

@mschauer
Copy link
Contributor Author

The test failure after adressing @tkelman's spot is unrelated, previously passing test here https://ci.appveyor.com/project/JuliaLang/julia/build/1.0.2015

@mschauer
Copy link
Contributor Author

mschauer commented Jun 6, 2016

Personal assessment: this change is straight forward.

@tkelman
Copy link
Contributor

tkelman commented Jun 6, 2016

Thanks for the bump, I agree this looks fine.

I think all the iterator size business still needs more thorough interface documentation, right?

@mschauer
Copy link
Contributor Author

mschauer commented Jun 6, 2016

Yes, I wrote https://gist.github.com/mschauer/c8d8b7eb5b455cb12ddc9bda15695203 but I would like to wait for feedback before writing more docs. See issue #15977

@mschauer
Copy link
Contributor Author

mschauer commented Jul 6, 2017

Bump.

Copy link
Member

@rfourquet rfourquet left a comment

Choose a reason for hiding this comment

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

LGTM! (modulo the few comments)

base/iterator.jl Outdated
@@ -490,6 +490,9 @@ type PartitionIterator{T}
end

eltype{T}(::Type{PartitionIterator{T}}) = Vector{eltype(T)}
partition_iteratorsize(::HasShape) = HasLength()
partition_iteratorsize{T}(isz::T) = isz
Copy link
Member

Choose a reason for hiding this comment

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

The type parameter can be omitted.

base/iterator.jl Outdated
@@ -490,6 +490,9 @@ type PartitionIterator{T}
end

eltype{T}(::Type{PartitionIterator{T}}) = Vector{eltype(T)}
partition_iteratorsize(::HasShape) = HasLength()
partition_iteratorsize{T}(isz::T) = isz
iteratorsize{T}(P::Type{PartitionIterator{T}}) = partition_iteratorsize(iteratorsize(T))
Copy link
Member

Choose a reason for hiding this comment

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

the argument P can be omitted, and when rebasing update to the where syntax

@test v[1] == [1,2]
@test v[2] == [3,4]
@test v[3] == [5]
let v1 = collect(Base.partition([1,2,3,4,5], 2)), v2 = collect(Base.partition(Base.flatten([1,2,3,4,5]), 2))
Copy link
Member

Choose a reason for hiding this comment

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

wrap at 92 (IIRC) chars

Copy link
Member

@Sacha0 Sacha0 left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks @mschauer! :)

(The CI failures appear unrelated.)

@StefanKarpinski
Copy link
Sponsor Member

If this is good to go, please merge, @rfourquet since you have some outstanding review comments.

@mschauer
Copy link
Contributor Author

@rfourquet Let me make one amendment first, after #22691 partition(flatten([1,2,3,4,5]),2) will actually have a length and not trigger anymore the SizeUnknown-code path of collect. One can replace withpartition(flatten([[1,2],[3,4],5]),2).

partition_iteratorsize(isz) = isz
function iteratorsize(::Type{PartitionIterator{T}}) where {T}
partition_iteratorsize(iteratorsize(T))
end
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity: you switched to the long-form function syntax because of the where syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@rfourquet rfourquet merged commit 0d83de9 into JuliaLang:master Jul 12, 2017
@rfourquet
Copy link
Member

Thanks @mschauer !

jeffwong pushed a commit to jeffwong/julia that referenced this pull request Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants