Skip to content

Commit

Permalink
Provide 0.6 implementation of collect for previous releases
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Apr 18, 2017
1 parent 47f5741 commit 5b7b3ae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
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 @@ -361,3 +363,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 @@ -1464,6 +1464,20 @@ if VERSION < v"0.6.0-pre.beta.102"
Base.bswap(z::Complex) = Complex(bswap(real(z)), bswap(imag(z)))
end

# https://github.com/JuliaLang/julia/pull/21257
if v"0.5.0" <= VERSION < v"0.6.0-pre.beta.28"
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)}(length.(indsA)), A)
function collect_indices(indsA, A)
B = Array{eltype(A)}(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
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,13 @@ let zbuf = IOBuffer([0xbf, 0xc0, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00,
@test bswap(z2) === 3.5 - 4.5im
end

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

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

nothing

0 comments on commit 5b7b3ae

Please sign in to comment.