Skip to content

Commit 78f7d51

Browse files
committed
Fix 0.6 breakages and depwarns
1 parent 65263db commit 78f7d51

File tree

9 files changed

+61
-30
lines changed

9 files changed

+61
-30
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ julia 0.5
22
IntervalSets
33
Iterators
44
RangeArrays
5+
Compat 0.19

src/AxisArrays.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module AxisArrays
44

55
using Base: tail
66
using RangeArrays, Iterators, IntervalSets
7+
using Compat
78

89
export AxisArray, Axis, axisnames, axisvalues, axisdim, axes, atindex
910

src/combine.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sizes{T<:AxisArray}(As::T...) = tuple(zip(map(size, As)...)...)
1313
matchingdims{N,T<:AxisArray}(As::NTuple{N,T}) = all(equalvalued, sizes(As...))
1414
matchingdimsexcept{N,T<:AxisArray}(As::NTuple{N,T}, n::Int) = all(equalvalued, sizes(As[[1:n-1; n+1:end]]...))
1515

16-
function Base.cat{T<:AxisArray}(n::Integer, As::T...)
16+
function Base.cat{T}(n::Integer, As::AxisArray{T}...)
1717
if n <= ndims(As[1])
1818
matchingdimsexcept(As, n) || error("All non-concatenated axes must be identically-valued")
1919
newaxis = Axis{axisnames(As[1])[n]}(vcat(map(A -> A.axes[n].val, As)...))

src/core.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ else
88
using Base: @pure
99
end
1010

11-
typealias Symbols Tuple{Symbol,Vararg{Symbol}}
11+
const Symbols = Tuple{Symbol,Vararg{Symbol}}
1212

1313
@doc """
1414
Type-stable axis-specific indexing and identification with a
@@ -158,17 +158,17 @@ A[ClosedInterval(0.,.3), [:a, :c]] # select an interval and two columns
158158
immutable AxisArray{T,N,D,Ax} <: AbstractArray{T,N}
159159
data::D # D <:AbstractArray, enforced in constructor to avoid dispatch bugs (https://github.com/JuliaLang/julia/issues/6383)
160160
axes::Ax # Ax<:NTuple{N, Axis}, but with specialized Axis{...} types
161-
AxisArray(data::AbstractArray, axs) = new{T,N,D,Ax}(data, axs)
161+
(::Type{AxisArray{T,N,D,Ax}}){T,N,D,Ax}(data::AbstractArray{T,N}, axs::Tuple{Vararg{Axis,N}}) = new{T,N,D,Ax}(data, axs)
162162
end
163163
#
164164
_defaultdimname(i) = i == 1 ? (:row) : i == 2 ? (:col) : i == 3 ? (:page) : Symbol(:dim_, i)
165165

166166
default_axes(A::AbstractArray) = _default_axes(A, indices(A), ())
167-
_default_axes{T,N}(A::AbstractArray{T,N}, inds, axs::NTuple{N}) = axs
168-
@inline _default_axes{T,N,M}(A::AbstractArray{T,N}, inds, axs::NTuple{M}) =
167+
_default_axes{T,N}(A::AbstractArray{T,N}, inds, axs::NTuple{N,Axis}) = axs
168+
@inline _default_axes{T,N,M}(A::AbstractArray{T,N}, inds, axs::NTuple{M,Axis}) =
169169
_default_axes(A, inds, (axs..., _nextaxistype(A, axs)(inds[M+1])))
170170
# Why doesn't @pure work here?
171-
@generated function _nextaxistype{T,M}(A::AbstractArray{T}, axs::NTuple{M})
171+
@generated function _nextaxistype{T,M}(A::AbstractArray{T}, axs::NTuple{M,Axis})
172172
name = _defaultdimname(M+1)
173173
:(Axis{$(Expr(:quote, name))})
174174
end
@@ -245,7 +245,6 @@ Base.size{Ax<:Axis}(A::AxisArray, ::Type{Ax}) = size(A.data, axisdim(A, Ax))
245245
Base.indices(A::AxisArray) = indices(A.data)
246246
Base.indices(A::AxisArray, Ax::Axis) = indices(A.data, axisdim(A, Ax))
247247
Base.indices{Ax<:Axis}(A::AxisArray, ::Type{Ax}) = indices(A.data, axisdim(A, Ax))
248-
Base.linearindexing(A::AxisArray) = Base.linearindexing(A.data)
249248
Base.convert{T,N}(::Type{Array{T,N}}, A::AxisArray{T,N}) = convert(Array{T,N}, A.data)
250249
# Similar is tricky. If we're just changing the element type, it can stay as an
251250
# AxisArray. But if we're changing dimensions, there's no way it can know how
@@ -308,7 +307,7 @@ function permutation(to::Symbols, from::Symbols)
308307
li = linearindices(from)
309308
d = Dict(from[i]=>i for i in li)
310309
covered = similar(dims->falses(length(li)), li)
311-
ind = Array(Int, max(n, nf))
310+
ind = Array{Int}(max(n, nf))
312311
for (i,toi) in enumerate(to)
313312
j = get(d, toi, 0)
314313
ind[i] = j
@@ -421,7 +420,7 @@ axes(A::AbstractArray) = default_axes(A)
421420
axes(A::AbstractArray, dim::Int) = default_axes(A)[dim]
422421

423422
### Axis traits ###
424-
abstract AxisTrait
423+
@compat abstract type AxisTrait end
425424
immutable Dimensional <: AxisTrait end
426425
immutable Categorical <: AxisTrait end
427426
immutable Unsupported <: AxisTrait end

src/indexing.jl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
typealias Idx Union{Real,Colon,AbstractArray{Int}}
1+
const Idx = Union{Real,Colon,AbstractArray{Int}}
22

3-
using Base: ViewIndex, linearindexing, unsafe_getindex, unsafe_setindex!
3+
using Base: ViewIndex, unsafe_getindex, unsafe_setindex!
44

5-
# Defer linearindexing to the wrapped array
6-
Base.linearindexing{T,N,D}(::AxisArray{T,N,D}) = linearindexing(D)
5+
# Defer IndexStyle to the wrapped array
6+
@compat Base.IndexStyle{T,N,D,Ax}(::Type{AxisArray{T,N,D,Ax}}) = IndexStyle(D)
77

88
# Simple scalar indexing where we just set or return scalars
99
@inline Base.getindex(A::AxisArray, idxs::Int...) = A.data[idxs...]
@@ -26,16 +26,24 @@ Base.setindex!(A::AxisArray, v, idx::Base.IteratorsMD.CartesianIndex) = (A.data[
2626
end
2727
names = axisnames(A)
2828
newaxes = Expr[]
29-
for d=1:lastnonscalar-droplastaxis
29+
drange = 1:lastnonscalar-droplastaxis
30+
for d=drange
3031
if I[d] <: AxisArray
3132
# Indexing with an AxisArray joins the axis names
3233
idxnames = axisnames(I[d])
3334
for i=1:ndims(I[d])
3435
push!(newaxes, :($(Axis{Symbol(names[d], "_", idxnames[i])})(I[$d].axes[$i].val)))
3536
end
3637
elseif I[d] <: Real
37-
elseif I[d] <: Union{AbstractVector,Colon}
38+
elseif I[d] <: AbstractVector
3839
push!(newaxes, :($(Axis{names[d]})(A.axes[$d].val[Base.to_index(I[$d])])))
40+
elseif I[d] <: Colon
41+
if d < length(I) || d <= ndims(A)
42+
push!(newaxes, :($(Axis{names[d]})(A.axes[$d].val)))
43+
else
44+
dimname = _defaultdimname(d)
45+
push!(newaxes, :($(Axis{dimname})(Base.OneTo(Base.trailingsize(A, $d)))))
46+
end
3947
elseif I[d] <: AbstractArray
4048
for i=1:ndims(I[d])
4149
# When we index with non-vector arrays, we *add* dimensions.
@@ -117,6 +125,12 @@ end
117125
return :($meta; to_index(A, $(idxs...)))
118126
end
119127

128+
function Base.reshape{N}(A::AxisArray, ::Type{Val{N}})
129+
# axN, _ = Base.IteratorsMD.split(axes(A), Val{N})
130+
# AxisArray(reshape(A.data, Val{N}), reaxis(A, Base.fill_to_length(axN, :, Val{N})...))
131+
AxisArray(reshape(A.data, Val{N}), reaxis(A, ntuple(d->Colon(), Val{N})...))
132+
end
133+
120134
### Indexing along values of the axes ###
121135

122136
# Default axes indexing throws an error

src/intervals.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# downside is that Intervals are not as useful as they could be; they really
1818
# could be considered as <: Number themselves. We do this in general for any
1919
# supported Scalar:
20-
typealias Scalar Union{Number, Dates.AbstractTime}
20+
const Scalar = Union{Number, Dates.AbstractTime}
2121
Base.promote_rule{T<:Scalar}(::Type{ClosedInterval{T}}, ::Type{T}) = ClosedInterval{T}
2222
Base.promote_rule{T,S<:Scalar}(::Type{ClosedInterval{T}}, ::Type{S}) = ClosedInterval{promote_type(T,S)}
2323
Base.promote_rule{T,S}(::Type{ClosedInterval{T}}, ::Type{ClosedInterval{S}}) = ClosedInterval{promote_type(T,S)}
@@ -62,7 +62,7 @@ immutable RepeatedInterval{T,S,A} <: AbstractVector{T}
6262
end
6363
RepeatedInterval{S,A<:AbstractVector}(window::ClosedInterval{S}, offsets::A) = RepeatedInterval{promote_type(ClosedInterval{S}, eltype(A)), S, A}(window, offsets)
6464
Base.size(r::RepeatedInterval) = size(r.offsets)
65-
Base.linearindexing{R<:RepeatedInterval}(::Type{R}) = Base.LinearFast()
65+
@compat Base.IndexStyle(::Type{<:RepeatedInterval}) = IndexLinear()
6666
Base.getindex(r::RepeatedInterval, i::Int) = r.window + r.offsets[i]
6767
+(window::ClosedInterval, offsets::AbstractVector) = RepeatedInterval(window, offsets)
6868
+(offsets::AbstractVector, window::ClosedInterval) = RepeatedInterval(window, offsets)
@@ -84,5 +84,5 @@ immutable RepeatedIntervalAtIndexes{T,A<:AbstractVector{Int}} <: AbstractVector{
8484
end
8585
atindex(window::ClosedInterval, indexes::AbstractVector) = RepeatedIntervalAtIndexes(window, indexes)
8686
Base.size(r::RepeatedIntervalAtIndexes) = size(r.indexes)
87-
Base.linearindexing{R<:RepeatedIntervalAtIndexes}(::Type{R}) = Base.LinearFast()
87+
@compat Base.IndexStyle(::Type{<:RepeatedIntervalAtIndexes}) = IndexLinear()
8888
Base.getindex(r::RepeatedIntervalAtIndexes, i::Int) = IntervalAtIndex(r.window, r.indexes[i])

src/search.jl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,30 @@ function Base.searchsorted(a::Range, I::ClosedInterval)
3636
searchsortedfirst(a, I.left):searchsortedlast(a, I.right)
3737
end
3838

39-
if VERSION > v"0.5.0-dev+4557"
40-
# When running with "--check-bounds=yes" (like on Travis), the bounds-check isn't elided
41-
@inline function Base.unsafe_getindex{T}(v::Range{T}, i::Integer)
42-
convert(T, first(v) + (i-1)*step(v))
43-
end
39+
# When running with "--check-bounds=yes" (like on Travis), the bounds-check isn't elided
40+
@inline function Base.unsafe_getindex{T}(v::Range{T}, i::Integer)
41+
convert(T, first(v) + (i-1)*step(v))
42+
end
43+
@inline function Base.unsafe_getindex{T<:Integer}(r::StepRange, s::Range{T})
44+
st = oftype(r.start, r.start + (first(s)-1)*step(r))
45+
range(st, step(r)*step(s), length(s))
46+
end
47+
if VERSION < v"0.6.0-dev.2390"
48+
include_string("""
4449
@inline function Base.unsafe_getindex{T}(r::FloatRange{T}, i::Integer)
4550
convert(T, (r.start + (i-1)*r.step)/r.divisor)
4651
end
47-
@inline function Base.unsafe_getindex{T<:Integer}(r::StepRange, s::Range{T})
48-
st = oftype(r.start, r.start + (first(s)-1)*step(r))
49-
range(st, step(r)*step(s), length(s))
50-
end
5152
@inline function Base.unsafe_getindex(r::FloatRange, s::OrdinalRange)
5253
FloatRange(r.start + (first(s)-1)*r.step, step(s)*r.step, length(s), r.divisor)
5354
end
55+
""")
56+
else
57+
include_string("""
58+
@inline function Base.unsafe_getindex(r::StepRangeLen, s::OrdinalRange)
59+
vfirst = unsafe_getindex(r, first(s))
60+
StepRangeLen(vfirst, r.step*step(s), length(s))
61+
end
62+
""")
5463
end
5564

5665
function unsafe_searchsortedlast{T<:Number}(a::Range{T}, x::Number)

test/indexing.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ D[1,1,1,1,1] = 10
3737

3838
# Linear indexing across multiple dimensions drops tracking of those dims
3939
@test A[:].axes[1].val == 1:length(A)
40-
@test A[1:2,:].axes[1].val == A.axes[1].val[1:2]
41-
@test A[1:2,:].axes[2].val == 1:Base.trailingsize(A,2)
40+
B = A[1:2,:]
41+
@test B.axes[1].val == A.axes[1].val[1:2]
42+
@test B.axes[2].val == 1:Base.trailingsize(A,2)
43+
B2 = reshape(A, Val{2})
44+
B = B2[1:2,:]
45+
@test B.axes[1].val == A.axes[1].val[1:2]
46+
@test B.axes[2].val == 1:Base.trailingsize(A,2)
4247

4348
B = AxisArray(reshape(1:15, 5,3), .1:.1:0.5, [:a, :b, :c])
4449

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using AxisArrays
22
using Base.Test
33

4-
@test isempty(detect_ambiguities(AxisArrays, Base, Core))
4+
if VERSION < v"0.6.0-dev"
5+
@test isempty(detect_ambiguities(AxisArrays, Base, Core))
6+
end
57

68
include("core.jl")
79
include("intervals.jl")

0 commit comments

Comments
 (0)