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

Remove support for 0.5 and drop Compat #98

Merged
merged 2 commits into from
Jul 26, 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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- nightly
notifications:
Expand Down
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
julia 0.5
julia 0.6
IntervalSets 0.1
RangeArrays
Compat 0.19
2 changes: 0 additions & 2 deletions src/AxisArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 3 additions & 8 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
48 changes: 9 additions & 39 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...]
Expand Down Expand Up @@ -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))...)
Expand All @@ -66,15 +66,15 @@ 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))))
end
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
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,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)
Expand All @@ -83,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])
21 changes: 4 additions & 17 deletions src/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand Down
10 changes: 2 additions & 8 deletions test/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
5 changes: 1 addition & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down