Skip to content

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

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
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
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.

5 participants