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

Provide 0.6 implementation of collect for previous releases #350

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `@compat Base.IndexStyle(::Type{<:MyArray}) = IndexLinear()` and `@compat Base.IndexStyle(::Type{<:MyArray}) = IndexCartesian()` to define traits for abstract arrays, replacing the former `Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearFast()` and `Base.linearindexing{T<:MyArray}(::Type{T}) = Base.LinearSlow()`, respectively.

* `Compat.collect(A)` returns an Array even on 0.5, no matter what indices the array `A` has. [#21257]

## Module Aliases

* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
Expand Down Expand Up @@ -363,3 +365,4 @@ includes this fix. Find the minimum version from there.
[#20500]: https://github.com/JuliaLang/julia/issues/20500
[#18629]: https://github.com/JuliaLang/julia/pull/18629
[#21346]: https://github.com/JuliaLang/julia/pull/21346
[#21257]: https://github.com/JuliaLang/julia/pull/21257
14 changes: 14 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,20 @@ else
using Base: StringVector
end

# https://github.com/JuliaLang/julia/pull/21257
if v"0.5.0" <= VERSION < v"0.6.0-pre.beta.28"
Copy link
Contributor

Choose a reason for hiding this comment

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

why the 0.5 lower bound?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

OffsetArrays in its modern form only exists for 0.5 and above, though it's nice that older versions are installable on 0.4 and thus avoid giving us an error just from test/REQUIRE. Moreover, I'm not sure the necessary copy! method was available on 0.4. In general any support that 0.4 would have for arrays with nontraditional indices would be a fluke, and no one should even try to use them; this test is only relevant on 0.5 and above.

Copy link
Contributor

Choose a reason for hiding this comment

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

It wasn't the release that made this method relevant though...

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Do we really want to be encouraging 0.5 pre-releases at this point?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Note that in the README I specified that Compat.collect is for 0.5 and above.

Copy link
Contributor

Choose a reason for hiding this comment

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

encourage no, but Compat's job is to work on as much of its supported version range as possible

Copy link
Contributor

Choose a reason for hiding this comment

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

"even on 0.5" isn't the clearest way of phrasing that

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

collect(A) = collect_indices(indices(A), A)
collect_indices(::Tuple{}, A) = copy!(Array{eltype(A)}(), A)
collect_indices(indsA::Tuple{Vararg{Base.OneTo}}, A) =
copy!(Array{eltype(A)}(map(length, indsA)), A)
function collect_indices(indsA, A)
B = Array{eltype(A)}(map(length, indsA))
copy!(B, CartesianRange(indices(B)), A, CartesianRange(indsA))
end
else
const collect = Base.collect
end

include("to-be-deprecated.jl")

end # module Compat
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OffsetArrays
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,15 @@ let x = fill!(StringVector(5), 0x61)
@test pointer(x) == pointer(Compat.UTF8String(x))
end

# collect
if VERSION >= v"0.5.0"
using OffsetArrays
a = OffsetArray(1:3, -1:1)
b = Compat.collect(a)
@test indices(b) === (Base.OneTo(3),)
@test b == [1,2,3]
end

include("to-be-deprecated.jl")

nothing