Skip to content

Commit 59ee7cf

Browse files
committed
Require julia 0.7-beta
1 parent 97e945f commit 59ee7cf

File tree

5 files changed

+67
-129
lines changed

5 files changed

+67
-129
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ os:
44
- linux
55

66
julia:
7-
- 0.6
87
- nightly
98

109
notifications:

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.6
2-
Compat 0.45
1+
julia 0.7.0-beta.73

appveyor.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
53
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
64
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
75

src/OffsetArrays.jl

Lines changed: 37 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,9 @@ __precompile__()
33
module OffsetArrays
44

55
using Base: Indices, tail
6-
using Compat
7-
using Compat: axes, CartesianIndices
86

97
export OffsetArray, OffsetVector, @unsafe
108

11-
## Major change in 0.7: OffsetArray now uses Offset axes
12-
const AxisType = VERSION < v"0.7.0-DEV.5242" ? identity : Base.Slice
13-
14-
# TODO: just use .+
15-
# See https://github.com/JuliaLang/julia/pull/22932#issuecomment-330711997
16-
if VERSION < v"0.7.0-DEV.1759"
17-
plus(r::AbstractUnitRange, i::Integer) = r + i
18-
else
19-
plus(r::AbstractUnitRange, i::Integer) = broadcast(+, r, i)
20-
end
21-
229
struct OffsetArray{T,N,AA<:AbstractArray} <: AbstractArray{T,N}
2310
parent::AA
2411
offsets::NTuple{N,Int}
@@ -44,33 +31,13 @@ OffsetVector{T}(::UndefInitializer, inds::AbstractUnitRange) where {T} = OffsetA
4431
# deprecated constructors
4532
using Base: @deprecate
4633

47-
# https://github.com/JuliaLang/julia/pull/19989
48-
@static if isdefined(Base, :UndefInitializer)
49-
@deprecate OffsetArray(::Type{T}, inds::Vararg{UnitRange{Int},N}) where {T,N} OffsetArray{T}(undef, inds)
50-
@deprecate OffsetVector(::Type{T}, inds::AbstractUnitRange) where {T} OffsetVector{T}(undef, inds)
51-
else
52-
OffsetArray(::Type{T}, inds::Vararg{UnitRange{Int},N}) where {T,N} = OffsetArray{T}(inds)
53-
OffsetVector(::Type{T}, inds::AbstractUnitRange) where {T} = OffsetVector{T}(inds)
54-
end
55-
56-
# https://github.com/JuliaLang/julia/pull/24652
57-
# Only activate deprecation if `undef` is available from Base;
58-
# should not rely on the user having `undef` available from Compat
59-
# and OffsetArrays.jl should probably not re-export Compat.undef
60-
@static if isdefined(Base, :UndefInitializer)
61-
@deprecate OffsetArray{T,N}(inds::Indices{N}) where {T,N} OffsetArray{T,N}(undef, inds)
62-
@deprecate OffsetArray{T}(inds::Indices{N}) where {T,N} OffsetArray{T}(undef, inds)
63-
@deprecate OffsetArray{T,N}(inds::Vararg{AbstractUnitRange,N}) where {T,N} OffsetArray{T,N}(undef, inds)
64-
@deprecate OffsetArray{T}(inds::Vararg{AbstractUnitRange,N}) where {T,N} OffsetArray{T}(undef, inds)
65-
@deprecate OffsetVector{T}(inds::AbstractUnitRange) where {T} OffsetVector{T}(undef, inds)
66-
else
67-
OffsetArray{T,N}(inds::Indices{N}) where {T,N} = OffsetArray{T,N}(undef, inds)
68-
OffsetArray{T}(inds::Indices{N}) where {T,N} = OffsetArray{T}(undef, inds)
69-
OffsetArray{T,N}(inds::Vararg{AbstractUnitRange,N}) where {T,N} = OffsetArray{T,N}(undef, inds)
70-
OffsetArray{T}(inds::Vararg{AbstractUnitRange,N}) where {T,N} = OffsetArray{T}(undef, inds)
71-
OffsetVector{T}(inds::AbstractUnitRange) where {T} = OffsetVector{T}(undef, inds)
72-
end
73-
34+
@deprecate OffsetArray(::Type{T}, inds::Vararg{UnitRange{Int},N}) where {T,N} OffsetArray{T}(undef, inds)
35+
@deprecate OffsetVector(::Type{T}, inds::AbstractUnitRange) where {T} OffsetVector{T}(undef, inds)
36+
@deprecate OffsetArray{T,N}(inds::Indices{N}) where {T,N} OffsetArray{T,N}(undef, inds)
37+
@deprecate OffsetArray{T}(inds::Indices{N}) where {T,N} OffsetArray{T}(undef, inds)
38+
@deprecate OffsetArray{T,N}(inds::Vararg{AbstractUnitRange,N}) where {T,N} OffsetArray{T,N}(undef, inds)
39+
@deprecate OffsetArray{T}(inds::Vararg{AbstractUnitRange,N}) where {T,N} OffsetArray{T}(undef, inds)
40+
@deprecate OffsetVector{T}(inds::AbstractUnitRange) where {T} OffsetVector{T}(undef, inds)
7441

7542
# The next two are necessary for ambiguity resolution. Really, the
7643
# second method should not be necessary.
@@ -100,12 +67,12 @@ Base.eachindex(::IndexLinear, A::OffsetVector) = axes(A, 1)
10067
# Implementations of axes and indices1. Since bounds-checking is
10168
# performance-critical and relies on axes, these are usually worth
10269
# optimizing thoroughly.
103-
@inline Compat.axes(A::OffsetArray, d) =
104-
1 <= d <= length(A.offsets) ? AxisType(plus(axes(parent(A))[d], A.offsets[d])) : (1:1)
105-
@inline Compat.axes(A::OffsetArray) =
70+
@inline Base.axes(A::OffsetArray, d) =
71+
1 <= d <= length(A.offsets) ? Base.Slice(axes(parent(A))[d] .+ A.offsets[d]) : (1:1)
72+
@inline Base.axes(A::OffsetArray) =
10673
_axes(axes(parent(A)), A.offsets) # would rather use ntuple, but see #15276
10774
@inline _axes(inds, offsets) =
108-
(AxisType(plus(inds[1], offsets[1])), _axes(tail(inds), tail(offsets))...)
75+
(Base.Slice(inds[1] .+ offsets[1]), _axes(tail(inds), tail(offsets))...)
10976
_axes(::Tuple{}, ::Tuple{}) = ()
11077
Base.indices1(A::OffsetArray{T,0}) where {T} = 1:1 # we only need to specialize this one
11178

@@ -119,16 +86,6 @@ function Base.similar(A::AbstractArray, ::Type{T}, inds::Tuple{OffsetAxis,Vararg
11986
OffsetArray(B, map(indexoffset, inds))
12087
end
12188

122-
if VERSION < v"0.7.0-DEV.5242"
123-
# Reshape's methods in Base changed, so using the new definitions leads to ambiguities
124-
Base.reshape(A::AbstractArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
125-
OffsetArray(reshape(A, map(length, inds)), map(indexoffset, inds))
126-
Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
127-
OffsetArray(reshape(parent(A), map(length, inds)), map(indexoffset, inds))
128-
function Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{Union{UnitRange,Int,Base.OneTo}}})
129-
throw(ArgumentError("reshape must supply UnitRange axes, got $(typeof(inds)).\n Note that reshape(A, Val{N}) is not supported for OffsetArrays."))
130-
end
131-
else
13289
Base.reshape(A::AbstractArray, inds::Tuple{OffsetAxis,Vararg{OffsetAxis}}) =
13390
OffsetArray(reshape(A, map(indexlength, inds)), map(indexoffset, inds))
13491

@@ -139,30 +96,20 @@ Base.reshape(A::OffsetArray, inds::Tuple{OffsetAxis,Vararg{OffsetAxis}}) =
13996
# And for non-offset axes, we can just return a reshape of the parent directly
14097
Base.reshape(A::OffsetArray, inds::Tuple{Union{Integer,Base.OneTo},Vararg{Union{Integer,Base.OneTo}}}) = reshape(parent(A), inds)
14198
Base.reshape(A::OffsetArray, inds::Dims) = reshape(parent(A), inds)
142-
end
14399

144-
if VERSION < v"0.7.0-DEV.4873"
145-
# Julia PR #26733 removed similar(f, ...) in favor of just using method extension directly
146-
# https://github.com/JuliaLang/julia/pull/26733
147-
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:AbstractArray} =
148-
OffsetArray(T(undef, map(indexlength, shape)), map(indexoffset, shape))
149-
Base.similar(f::Function, shape::Tuple{UnitRange,Vararg{UnitRange}}) =
150-
OffsetArray(f(map(indexlength, shape)), map(indexoffset, shape))
151-
else
152-
Base.similar(::Type{T}, shape::Tuple{OffsetAxis,Vararg{OffsetAxis}}) where {T<:AbstractArray} =
153-
OffsetArray(T(undef, map(indexlength, shape)), map(indexoffset, shape))
154-
155-
Base.fill(v, inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
156-
fill!(OffsetArray(Array{typeof(v), N}(undef, map(indexlength, inds)), map(indexoffset, inds)), v)
157-
Base.zeros(::Type{T}, inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {T, N} =
158-
fill!(OffsetArray(Array{T, N}(undef, map(indexlength, inds)), map(indexoffset, inds)), zero(T))
159-
Base.ones(::Type{T}, inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {T, N} =
160-
fill!(OffsetArray(Array{T, N}(undef, map(indexlength, inds)), map(indexoffset, inds)), one(T))
161-
Base.trues(inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
162-
fill!(OffsetArray(BitArray{N}(undef, map(indexlength, inds)), map(indexoffset, inds)), true)
163-
Base.falses(inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
164-
fill!(OffsetArray(BitArray{N}(undef, map(indexlength, inds)), map(indexoffset, inds)), false)
165-
end
100+
Base.similar(::Type{T}, shape::Tuple{OffsetAxis,Vararg{OffsetAxis}}) where {T<:AbstractArray} =
101+
OffsetArray(T(undef, map(indexlength, shape)), map(indexoffset, shape))
102+
103+
Base.fill(v, inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
104+
fill!(OffsetArray(Array{typeof(v), N}(undef, map(indexlength, inds)), map(indexoffset, inds)), v)
105+
Base.zeros(::Type{T}, inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {T, N} =
106+
fill!(OffsetArray(Array{T, N}(undef, map(indexlength, inds)), map(indexoffset, inds)), zero(T))
107+
Base.ones(::Type{T}, inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {T, N} =
108+
fill!(OffsetArray(Array{T, N}(undef, map(indexlength, inds)), map(indexoffset, inds)), one(T))
109+
Base.trues(inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
110+
fill!(OffsetArray(BitArray{N}(undef, map(indexlength, inds)), map(indexoffset, inds)), true)
111+
Base.falses(inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
112+
fill!(OffsetArray(BitArray{N}(undef, map(indexlength, inds)), map(indexoffset, inds)), false)
166113

167114
# Don't allow bounds-checks to be removed during Julia 0.5
168115
@inline function Base.getindex(A::OffsetArray{T,N}, I::Vararg{Int,N}) where {T,N}
@@ -293,22 +240,20 @@ end
293240
@inline unsafe_getindex(a::OffsetSubArray, I::Union{Integer,CartesianIndex}...) = unsafe_getindex(a, Base.IteratorsMD.flatten(I)...)
294241
@inline unsafe_setindex!(a::OffsetSubArray, val, I::Union{Integer,CartesianIndex}...) = unsafe_setindex!(a, val, Base.IteratorsMD.flatten(I)...)
295242

296-
if VERSION >= v"0.7.0-DEV.1790"
297-
function Base.showarg(io::IO, a::OffsetArray, toplevel)
298-
print(io, "OffsetArray(")
299-
Base.showarg(io, parent(a), false)
300-
if ndims(a) > 0
301-
print(io, ", ")
302-
printindices(io, axes(a)...)
303-
end
304-
print(io, ')')
305-
toplevel && print(io, " with eltype ", eltype(a))
243+
function Base.showarg(io::IO, a::OffsetArray, toplevel)
244+
print(io, "OffsetArray(")
245+
Base.showarg(io, parent(a), false)
246+
if ndims(a) > 0
247+
print(io, ", ")
248+
printindices(io, axes(a)...)
306249
end
307-
printindices(io::IO, ind1, inds...) =
308-
(print(io, _unslice(ind1), ", "); printindices(io, inds...))
309-
printindices(io::IO, ind1) = print(io, _unslice(ind1))
310-
_unslice(x) = x
311-
_unslice(x::Base.Slice) = x.indices
250+
print(io, ')')
251+
toplevel && print(io, " with eltype ", eltype(a))
312252
end
253+
printindices(io::IO, ind1, inds...) =
254+
(print(io, _unslice(ind1), ", "); printindices(io, inds...))
255+
printindices(io::IO, ind1) = print(io, _unslice(ind1))
256+
_unslice(x) = x
257+
_unslice(x::Base.Slice) = x.indices
313258

314259
end # module

test/runtests.jl

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using Compat.Test
21
using OffsetArrays
3-
using Compat
4-
using Compat: axes, CartesianIndices, copyto!
5-
using Compat.DelimitedFiles
2+
using Test
3+
using DelimitedFiles
64

75
@test isempty(detect_ambiguities(OffsetArrays, Base, Core))
86

@@ -97,19 +95,18 @@ Ac[0,3,1] = 11
9795
@test eachindex(S) == CartesianIndices(Base.Slice.((0:1,3:4)))
9896

9997
# view
100-
const AxisType = VERSION < v"0.7.0-DEV.5242" ? identity : Base.Slice
10198
S = view(A, :, 3)
10299
@test S == OffsetArray([1,2], (A.offsets[1],))
103100
@test S[0] == 1
104101
@test S[1] == 2
105102
@test_throws BoundsError S[2]
106-
@test axes(S) === (AxisType(0:1),)
103+
@test axes(S) === (Base.Slice(0:1),)
107104
S = view(A, 0, :)
108105
@test S == OffsetArray([1,3], (A.offsets[2],))
109106
@test S[3] == 1
110107
@test S[4] == 3
111108
@test_throws BoundsError S[1]
112-
@test axes(S) === (AxisType(3:4),)
109+
@test axes(S) === (Base.Slice(3:4),)
113110
S = view(A, 0:0, 4)
114111
@test S == [3]
115112
@test S[1] == 3
@@ -128,7 +125,7 @@ S = view(A, :, :)
128125
@test S[0,4] == S[3] == 3
129126
@test S[1,4] == S[4] == 4
130127
@test_throws BoundsError S[1,1]
131-
@test axes(S) === AxisType.((0:1, 3:4))
128+
@test axes(S) === Base.Slice.((0:1, 3:4))
132129

133130
# iteration
134131
let a
@@ -169,10 +166,10 @@ B = similar(A, (3,4))
169166
@test axes(B) === (Base.OneTo(3), Base.OneTo(4))
170167
B = similar(A, (-3:3,1:4))
171168
@test isa(B, OffsetArray{Int,2})
172-
@test axes(B) === AxisType.((-3:3, 1:4))
169+
@test axes(B) === Base.Slice.((-3:3, 1:4))
173170
B = similar(parent(A), (-3:3,1:4))
174171
@test isa(B, OffsetArray{Int,2})
175-
@test axes(B) === AxisType.((-3:3, 1:4))
172+
@test axes(B) === Base.Slice.((-3:3, 1:4))
176173
@test isa([x for x in [1,2,3]], Vector{Int})
177174
@test similar(Array{Int}, (0:0, 0:0)) isa OffsetArray{Int, 2}
178175
@test similar(Array{Int}, (1, 1)) isa Matrix{Int}
@@ -185,13 +182,13 @@ end
185182
B = reshape(A0, -10:-9, 9:10)
186183
@test isa(B, OffsetArray{Int,2})
187184
@test parent(B) === A0
188-
@test axes(B) == AxisType.((-10:-9, 9:10))
185+
@test axes(B) == Base.Slice.((-10:-9, 9:10))
189186
B = reshape(A, -10:-9, 9:10)
190187
@test isa(B, OffsetArray{Int,2})
191188
@test pointer(parent(B)) === pointer(A0)
192-
@test axes(B) == AxisType.((-10:-9, 9:10))
189+
@test axes(B) == Base.Slice.((-10:-9, 9:10))
193190
b = reshape(A, -7:-4)
194-
@test axes(b) == (AxisType(-7:-4),)
191+
@test axes(b) == (Base.Slice(-7:-4),)
195192
@test isa(parent(b), Vector{Int})
196193
@test pointer(parent(b)) === pointer(parent(A))
197194
@test parent(b) == A0[:]
@@ -201,28 +198,28 @@ if VERSION >= v"0.7.0-DEV.5242"
201198
b = reshape(a, Val(2))
202199
@test isa(b, OffsetArray{Float64,2})
203200
@test pointer(parent(b)) === pointer(parent(a))
204-
@test axes(b) == AxisType.((-1:1, 1:9))
201+
@test axes(b) == Base.Slice.((-1:1, 1:9))
205202
b = reshape(a, Val(4))
206203
@test isa(b, OffsetArray{Float64,4})
207204
@test pointer(parent(b)) === pointer(parent(a))
208-
@test axes(b) == (axes(a)..., AxisType(1:1))
205+
@test axes(b) == (axes(a)..., Base.Slice(1:1))
209206
end
210207

211208
# Indexing with OffsetArray axes
212209
i1 = OffsetArray([2,1], (-5,))
213210
i1 = OffsetArray([2,1], -5)
214211
b = A0[i1, 1]
215-
@test axes(b) === (AxisType(-4:-3),)
212+
@test axes(b) === (Base.Slice(-4:-3),)
216213
@test b[-4] == 2
217214
@test b[-3] == 1
218215
b = A0[1,i1]
219-
@test axes(b) === (AxisType(-4:-3),)
216+
@test axes(b) === (Base.Slice(-4:-3),)
220217
@test b[-4] == 3
221218
@test b[-3] == 1
222219
v = view(A0, i1, 1)
223-
@test axes(v) === (AxisType(-4:-3),)
220+
@test axes(v) === (Base.Slice(-4:-3),)
224221
v = view(A0, 1:1, i1)
225-
@test axes(v) === (Base.OneTo(1), AxisType(-4:-3))
222+
@test axes(v) === (Base.OneTo(1), Base.Slice(-4:-3))
226223

227224
# logical indexing
228225
@test A[A .> 2] == [3,4]
@@ -293,17 +290,17 @@ A = OffsetArray(rand(4,4), (-3,5))
293290
@test minimum(A) == minimum(parent(A))
294291
@test extrema(A) == extrema(parent(A))
295292
C = similar(A)
296-
Compat.cumsum!(C, A, dims = 1)
297-
@test parent(C) == Compat.cumsum(parent(A), dims = 1)
298-
@test parent(Compat.cumsum(A, dims = 1)) == Compat.cumsum(parent(A), dims = 1)
299-
Compat.cumsum!(C, A, dims = 2)
300-
@test parent(C) == Compat.cumsum(parent(A), dims = 2)
293+
cumsum!(C, A, dims = 1)
294+
@test parent(C) == cumsum(parent(A), dims = 1)
295+
@test parent(cumsum(A, dims = 1)) == cumsum(parent(A), dims = 1)
296+
cumsum!(C, A, dims = 2)
297+
@test parent(C) == cumsum(parent(A), dims = 2)
301298
R = similar(A, (1:1, 6:9))
302299
maximum!(R, A)
303-
@test parent(R) == Compat.maximum(parent(A), dims = 1)
300+
@test parent(R) == maximum(parent(A), dims = 1)
304301
R = similar(A, (-2:1, 1:1))
305302
maximum!(R, A)
306-
@test parent(R) == Compat.maximum(parent(A), dims = 2)
303+
@test parent(R) == maximum(parent(A), dims = 2)
307304
amin, iamin = findmin(A)
308305
pmin, ipmin = findmin(parent(A))
309306
@test amin == pmin
@@ -340,16 +337,16 @@ v = OffsetArray(rand(8), (-2,))
340337
@test sort(v) == OffsetArray(sort(parent(v)), v.offsets)
341338
@test sortrows(A) == OffsetArray(sortrows(parent(A)), A.offsets)
342339
@test sortcols(A) == OffsetArray(sortcols(parent(A)), A.offsets)
343-
@test Compat.sort(A, dims = 1) == OffsetArray(Compat.sort(parent(A), dims = 1), A.offsets)
344-
@test Compat.sort(A, dims = 2) == OffsetArray(Compat.sort(parent(A), dims = 2), A.offsets)
340+
@test sort(A, dims = 1) == OffsetArray(sort(parent(A), dims = 1), A.offsets)
341+
@test sort(A, dims = 2) == OffsetArray(sort(parent(A), dims = 2), A.offsets)
345342

346-
@test mapslices(v->sort(v), A, 1) == OffsetArray(mapslices(v->sort(v), parent(A), 1), A.offsets)
347-
@test mapslices(v->sort(v), A, 2) == OffsetArray(mapslices(v->sort(v), parent(A), 2), A.offsets)
343+
@test mapslices(v->sort(v), A, dims = 1) == OffsetArray(mapslices(v->sort(v), parent(A), dims = 1), A.offsets)
344+
@test mapslices(v->sort(v), A, dims = 2) == OffsetArray(mapslices(v->sort(v), parent(A), dims = 2), A.offsets)
348345

349346
@test rotl90(A) == OffsetArray(rotl90(parent(A)), A.offsets[[2,1]])
350347
@test rotr90(A) == OffsetArray(rotr90(parent(A)), A.offsets[[2,1]])
351-
@test Compat.reverse(A, dims = 1) == OffsetArray(Compat.reverse(parent(A), dims = 1), A.offsets)
352-
@test Compat.reverse(A, dims = 2) == OffsetArray(Compat.reverse(parent(A), dims = 2), A.offsets)
348+
@test reverse(A, dims = 1) == OffsetArray(reverse(parent(A), dims = 1), A.offsets)
349+
@test reverse(A, dims = 2) == OffsetArray(reverse(parent(A), dims = 2), A.offsets)
353350

354351
@test A.+1 == OffsetArray(parent(A).+1, A.offsets)
355352
@test 2*A == OffsetArray(2*parent(A), A.offsets)

0 commit comments

Comments
 (0)