From 40d54c046b4bb12d2a8168af70154ae80c57316e Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Sun, 9 Jul 2017 09:19:30 -0500 Subject: [PATCH] Remove support for 0.5 and drop Compat --- .travis.yml | 1 - REQUIRE | 5 ++--- src/AxisArrays.jl | 2 -- src/core.jl | 11 +++-------- src/indexing.jl | 48 +++++++++-------------------------------------- src/intervals.jl | 5 ++--- src/search.jl | 21 ++++----------------- test/core.jl | 12 ++++++------ test/indexing.jl | 10 ++-------- test/runtests.jl | 5 +---- 10 files changed, 29 insertions(+), 91 deletions(-) diff --git a/.travis.yml b/.travis.yml index 071a475..3c3fcd3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ os: - linux - osx julia: - - 0.5 - 0.6 - nightly notifications: diff --git a/REQUIRE b/REQUIRE index efedb19..870ab04 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,3 @@ -julia 0.5 -IntervalSets +julia 0.6 +IntervalSets 0.1 RangeArrays -Compat 0.19 diff --git a/src/AxisArrays.jl b/src/AxisArrays.jl index b9c94bb..90cfed1 100644 --- a/src/AxisArrays.jl +++ b/src/AxisArrays.jl @@ -4,13 +4,11 @@ module AxisArrays using Base: tail using RangeArrays, IntervalSets -using Compat export AxisArray, Axis, axisnames, axisvalues, axisdim, axes, atindex, atvalue # From IntervalSets: export ClosedInterval, .. -Base.@deprecate_binding Interval ClosedInterval include("core.jl") include("intervals.jl") diff --git a/src/core.jl b/src/core.jl index 3b93930..4b3ed2c 100644 --- a/src/core.jl +++ b/src/core.jl @@ -293,13 +293,8 @@ end # Note that we only extend the following two methods, and then have it # dispatch to package-local `reduced_indices` and `reduced_indices0` # methods. This avoids a whole slew of ambiguities. -if VERSION == v"0.5.0" - Base.reduced_dims(A::AxisArray, region) = reduced_indices(axes(A), region) - Base.reduced_dims0(A::AxisArray, region) = reduced_indices0(axes(A), region) -else - Base.reduced_indices(A::AxisArray, region) = reduced_indices(axes(A), region) - Base.reduced_indices0(A::AxisArray, region) = reduced_indices0(axes(A), region) -end +Base.reduced_indices(A::AxisArray, region) = reduced_indices(axes(A), region) +Base.reduced_indices0(A::AxisArray, region) = reduced_indices0(axes(A), region) reduced_indices{N}(axs::Tuple{Vararg{Axis,N}}, ::Tuple{}) = axs reduced_indices0{N}(axs::Tuple{Vararg{Axis,N}}, ::Tuple{}) = axs @@ -509,7 +504,7 @@ axes(A::AbstractArray) = default_axes(A) axes(A::AbstractArray, dim::Int) = default_axes(A)[dim] ### Axis traits ### -@compat abstract type AxisTrait end +abstract type AxisTrait end immutable Dimensional <: AxisTrait end immutable Categorical <: AxisTrait end immutable Unsupported <: AxisTrait end diff --git a/src/indexing.jl b/src/indexing.jl index 9752e7d..42aff72 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -20,7 +20,7 @@ Base.show(io::IO, v::Value) = print(io, string("Value(", v.val, ", tol=", v.tol, ")")) # Defer IndexStyle to the wrapped array -@compat Base.IndexStyle{T,N,D,Ax}(::Type{AxisArray{T,N,D,Ax}}) = IndexStyle(D) +Base.IndexStyle{T,N,D,Ax}(::Type{AxisArray{T,N,D,Ax}}) = IndexStyle(D) # Simple scalar indexing where we just set or return scalars @propagate_inbounds Base.getindex(A::AxisArray, idxs::Int...) = A.data[idxs...] @@ -55,7 +55,7 @@ reaxis(A::AxisArray, I::Idx...) = _reaxis(make_axes_match(axes(A), I), I) # Now we can reaxis without worrying about mismatched axes/indices @inline _reaxis(axs::Tuple{}, idxs::Tuple{}) = () # Scalars are dropped -const ScalarIndex = @compat Union{Real, AbstractArray{<:Any, 0}} +const ScalarIndex = Union{Real, AbstractArray{<:Any, 0}} @inline _reaxis(axs::Tuple, idxs::Tuple{ScalarIndex, Vararg{Any}}) = _reaxis(tail(axs), tail(idxs)) # Colon passes straight through @inline _reaxis(axs::Tuple, idxs::Tuple{Colon, Vararg{Any}}) = (axs[1], _reaxis(tail(axs), tail(idxs))...) @@ -66,7 +66,7 @@ const ScalarIndex = @compat Union{Real, AbstractArray{<:Any, 0}} # Vectors simply create new axes with the same name; just subsetted by their value @inline _new_axes{name}(ax::Axis{name}, idx::AbstractVector) = (Axis{name}(ax.val[idx]),) # Arrays create multiple axes with _N appended to the axis name containing their indices -@generated function _new_axes{name, N}(ax::Axis{name}, idx::@compat(AbstractArray{<:Any,N})) +@generated function _new_axes{name, N}(ax::Axis{name}, idx::AbstractArray{<:Any,N}) newaxes = Expr(:tuple) for i=1:N push!(newaxes.args, :($(Axis{Symbol(name, "_", i)})(indices(idx, $i)))) @@ -74,7 +74,7 @@ const ScalarIndex = @compat Union{Real, AbstractArray{<:Any, 0}} newaxes end # And indexing with an AxisArray joins the name and overrides the values -@generated function _new_axes{name, N}(ax::Axis{name}, idx::@compat(AxisArray{<:Any, N})) +@generated function _new_axes{name, N}(ax::Axis{name}, idx::AxisArray{<:Any, N}) newaxes = Expr(:tuple) idxnames = axisnames(idx) for i=1:N @@ -88,21 +88,8 @@ end end # To resolve ambiguities, we need several definitions -if VERSION >= v"0.6.0-dev.672" - using Base.AbstractCartesianIndex - @propagate_inbounds Base.view(A::AxisArray, idxs::Idx...) = AxisArray(view(A.data, idxs...), reaxis(A, idxs...)) -else - @propagate_inbounds function Base.view{T,N}(A::AxisArray{T,N}, idxs::Vararg{Idx,N}) - AxisArray(view(A.data, idxs...), reaxis(A, idxs...)) - end - @propagate_inbounds function Base.view(A::AxisArray, idx::Idx) - AxisArray(view(A.data, idx), reaxis(A, idx)) - end - @propagate_inbounds function Base.view{N}(A::AxisArray, idxs::Vararg{Idx,N}) - # this should eventually be deleted, see julia #14770 - AxisArray(view(A.data, idxs...), reaxis(A, idxs...)) - end -end +using Base.AbstractCartesianIndex +@propagate_inbounds Base.view(A::AxisArray, idxs::Idx...) = AxisArray(view(A.data, idxs...), reaxis(A, idxs...)) # Setindex is so much simpler. Just assign it to the data: @propagate_inbounds Base.setindex!(A::AxisArray, v, idxs::Idx...) = (A.data[idxs...] = v) @@ -111,26 +98,9 @@ end @propagate_inbounds Base.getindex(A::AxisArray, idxs...) = A[to_index(A,idxs...)...] @propagate_inbounds Base.setindex!(A::AxisArray, v, idxs...) = (A[to_index(A,idxs...)...] = v) # Deal with lots of ambiguities here -if VERSION >= v"0.6.0-dev.672" - @propagate_inbounds Base.view(A::AxisArray, idxs::ViewIndex...) = view(A, to_index(A,idxs...)...) - @propagate_inbounds Base.view(A::AxisArray, idxs::Union{ViewIndex,AbstractCartesianIndex}...) = view(A, to_index(A,Base.IteratorsMD.flatten(idxs)...)...) - @propagate_inbounds Base.view(A::AxisArray, idxs...) = view(A, to_index(A,idxs...)...) -else - for T in (:ViewIndex, :Any) - @eval begin - @propagate_inbounds function Base.view{T,N}(A::AxisArray{T,N}, idxs::Vararg{$T,N}) - view(A, to_index(A,idxs...)...) - end - @propagate_inbounds function Base.view(A::AxisArray, idx::$T) - view(A, to_index(A,idx)...) - end - @propagate_inbounds function Base.view{N}(A::AxisArray, idsx::Vararg{$T,N}) - # this should eventually be deleted, see julia #14770 - view(A, to_index(A,idxs...)...) - end - end - end -end +@propagate_inbounds Base.view(A::AxisArray, idxs::ViewIndex...) = view(A, to_index(A,idxs...)...) +@propagate_inbounds Base.view(A::AxisArray, idxs::Union{ViewIndex,AbstractCartesianIndex}...) = view(A, to_index(A,Base.IteratorsMD.flatten(idxs)...)...) +@propagate_inbounds Base.view(A::AxisArray, idxs...) = view(A, to_index(A,idxs...)...) # First is indexing by named axis. We simply sort the axes and re-dispatch. # When indexing by named axis the shapes of omitted dimensions are preserved diff --git a/src/intervals.jl b/src/intervals.jl index 68b55e3..2638637 100644 --- a/src/intervals.jl +++ b/src/intervals.jl @@ -20,7 +20,6 @@ const Scalar = Union{Number, Dates.AbstractTime} Base.promote_rule{T<:Scalar}(::Type{ClosedInterval{T}}, ::Type{T}) = ClosedInterval{T} Base.promote_rule{T,S<:Scalar}(::Type{ClosedInterval{T}}, ::Type{S}) = ClosedInterval{promote_type(T,S)} -Base.promote_rule{T,S}(::Type{ClosedInterval{T}}, ::Type{ClosedInterval{S}}) = ClosedInterval{promote_type(T,S)} import Base: isless, <=, >=, ==, +, -, *, /, ^, // # TODO: Is this a total ordering? (antisymmetric, transitive, total)? @@ -62,7 +61,7 @@ immutable RepeatedInterval{T,S,A} <: AbstractVector{T} end RepeatedInterval{S,A<:AbstractVector}(window::ClosedInterval{S}, offsets::A) = RepeatedInterval{promote_type(ClosedInterval{S}, eltype(A)), S, A}(window, offsets) Base.size(r::RepeatedInterval) = size(r.offsets) -@compat Base.IndexStyle(::Type{<:RepeatedInterval}) = IndexLinear() +Base.IndexStyle(::Type{<:RepeatedInterval}) = IndexLinear() Base.getindex(r::RepeatedInterval, i::Int) = r.window + r.offsets[i] +(window::ClosedInterval, offsets::AbstractVector) = RepeatedInterval(window, offsets) +(offsets::AbstractVector, window::ClosedInterval) = RepeatedInterval(window, offsets) @@ -84,5 +83,5 @@ immutable RepeatedIntervalAtIndexes{T,A<:AbstractVector{Int}} <: AbstractVector{ end atindex(window::ClosedInterval, indexes::AbstractVector) = RepeatedIntervalAtIndexes(window, indexes) Base.size(r::RepeatedIntervalAtIndexes) = size(r.indexes) -@compat Base.IndexStyle(::Type{<:RepeatedIntervalAtIndexes}) = IndexLinear() +Base.IndexStyle(::Type{<:RepeatedIntervalAtIndexes}) = IndexLinear() Base.getindex(r::RepeatedIntervalAtIndexes, i::Int) = IntervalAtIndex(r.window, r.indexes[i]) diff --git a/src/search.jl b/src/search.jl index a47ccb2..9fa79be 100644 --- a/src/search.jl +++ b/src/search.jl @@ -45,23 +45,10 @@ end st = oftype(f, f + (first(s)-1)*step(r)) range(st, step(r)*step(s), length(s)) end -if VERSION < v"0.6.0-dev.2390" - include_string(""" - @inline function inbounds_getindex{T}(r::FloatRange{T}, i::Integer) - convert(T, (r.start + (i-1)*r.step)/r.divisor) - end - @inline function inbounds_getindex(r::FloatRange, s::OrdinalRange) - FloatRange(r.start + (first(s)-1)*r.step, step(s)*r.step, length(s), r.divisor) - end - """) -else - include_string(""" - @inline inbounds_getindex(r::StepRangeLen, i::Integer) = Base.unsafe_getindex(r, i) - @inline function inbounds_getindex(r::StepRangeLen, s::OrdinalRange) - vfirst = Base.unsafe_getindex(r, first(s)) - StepRangeLen(vfirst, step(r)*step(s), length(s)) - end - """) +@inline inbounds_getindex(r::StepRangeLen, i::Integer) = Base.unsafe_getindex(r, i) +@inline function inbounds_getindex(r::StepRangeLen, s::OrdinalRange) + vfirst = Base.unsafe_getindex(r, first(s)) + StepRangeLen(vfirst, step(r)*step(s), length(s)) end function unsafe_searchsortedlast{T<:Number}(a::Range{T}, x::Number) diff --git a/test/core.jl b/test/core.jl index bf12b7b..afb243e 100644 --- a/test/core.jl +++ b/test/core.jl @@ -82,34 +82,34 @@ H = similar(A, Float64, 1,1,1) A = AxisArray(1:3) @test A.data == 1:3 @test axisnames(A) == (:row,) -VERSION >= v"0.5.0-dev" && @inferred(axisnames(A)) +@inferred(axisnames(A)) @test axisvalues(A) == (1:3,) A = AxisArray(reshape(1:16, 2,2,2,2)) @test A.data == reshape(1:16, 2,2,2,2) @test axisnames(A) == (:row,:col,:page,:dim_4) -VERSION >= v"0.5.0-dev" && @inferred(axisnames(A)) +@inferred(axisnames(A)) @test axisvalues(A) == (1:2, 1:2, 1:2, 1:2) # Just axis names A = AxisArray(1:3, :a) @test A.data == 1:3 @test axisnames(A) == (:a,) -VERSION >= v"0.5.0-dev" && @inferred(axisnames(A)) +@inferred(axisnames(A)) @test axisvalues(A) == (1:3,) A = AxisArray([1 3; 2 4], :a) @test A.data == [1 3; 2 4] @test axisnames(A) == (:a, :col) -VERSION >= v"0.5.0-dev" && @inferred(axisnames(A)) +@inferred(axisnames(A)) @test axisvalues(A) == (1:2, 1:2) # Just axis values A = @inferred(AxisArray(1:3, .1:.1:.3)) @test A.data == 1:3 @test axisnames(A) == (:row,) -VERSION >= v"0.5.0-dev" && @inferred(axisnames(A)) +@inferred(axisnames(A)) @test axisvalues(A) == (.1:.1:.3,) A = @inferred(AxisArray(reshape(1:16, 2,2,2,2), .5:.5:1)) @test A.data == reshape(1:16, 2,2,2,2) @test axisnames(A) == (:row,:col,:page,:dim_4) -VERSION >= v"0.5.0-dev" && @inferred(axisnames(A)) +@inferred(axisnames(A)) @test axisvalues(A) == (.5:.5:1, 1:2, 1:2, 1:2) A = AxisArray([0]', :x, :y) @test axisnames(squeeze(A, 1)) == (:y,) diff --git a/test/indexing.jl b/test/indexing.jl index 13fa5c6..999d038 100644 --- a/test/indexing.jl +++ b/test/indexing.jl @@ -39,7 +39,7 @@ D[1,1,1,1,1] = 10 # Linear indexing across multiple dimensions drops tracking of those dims @test A[:].axes[1].val == 1:length(A) # TODO: remove the next 4 lines when we no longer feel we need to test for this -VERSION >= v"0.6.0-dev" && info("partial linear indexing deprecation warning is expected") +info("partial linear indexing deprecation warning is expected") B = A[1:2,:] @test B.axes[1].val == A.axes[1].val[1:2] @test B.axes[2].val == 1:Base.trailingsize(A,2) @@ -193,10 +193,4 @@ A = AxisArray(OffsetArrays.OffsetArray([1 2; 3 4], 0:1, 1:2), @test_throws ArgumentError A[4.0] @test_throws ArgumentError A[BigFloat(1.0)] @test_throws ArgumentError A[1.0f0] -if VERSION == v"0.5.2" - # Cannot compose @test_broken with @test_throws (Julia #21098) - # A[:,6.1] incorrectly throws a BoundsError instead of an ArgumentError on Julia 0.5.2 - @test_broken A[:,6.1] -else - @test_throws ArgumentError A[:,6.1] -end +@test_throws ArgumentError A[:,6.1] diff --git a/test/runtests.jl b/test/runtests.jl index 09b4a67..161c89d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,10 +2,7 @@ using AxisArrays using Base.Test @testset "AxisArrays" begin - # during this time there was an ambiguity in base with checkbounds_linear_indices - if VERSION < v"0.6.0-dev.2374" || VERSION >= v"0.6.0-dev.2884" - @test isempty(detect_ambiguities(AxisArrays, Base, Core)) - end + @test isempty(detect_ambiguities(AxisArrays, Base, Core)) @testset "Core" begin include("core.jl")