Skip to content

Commit

Permalink
Merge pull request #6 from ajkeller34/v07
Browse files Browse the repository at this point in the history
Fix v0.7 deprecations and bump Compat and Julia version requirements.
  • Loading branch information
mbauman committed Jan 18, 2018
2 parents ae15f5c + 86cc184 commit 6f4ae29
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,7 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- nightly
notifications:
email: false
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
@@ -1,2 +1,2 @@
julia 0.5
Compat 0.19
julia 0.6
Compat 0.32
4 changes: 2 additions & 2 deletions appveyor.yml
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
19 changes: 11 additions & 8 deletions src/matrix.jl
@@ -1,5 +1,5 @@
"""
RangeMatrix{T<:Range}(rs::AbstractVector{T})
RangeMatrix(rs::AbstractVector{T}) where T <: AbstractRange
A RangeMatrix is a simple matrix representation of a vector of ranges, with
each range representing one column. Construct a RangeMatrix with a vector of
Expand All @@ -8,12 +8,12 @@ ranges; the ranges must all have the same length.
Note that it is only efficient when all the ranges are of the same type and in
a concretely typed Vector.
"""
immutable RangeMatrix{T,A} <: AbstractArray{T,2}
struct RangeMatrix{T,A} <: AbstractArray{T,2}
rs::A # A <: AbstractVector{_<:Range{T}}
dims::Tuple{Int,Int}
end
RangeMatrix(rs::Range...) = RangeMatrix(collect(rs)) # TODO: use tuple storage?
function RangeMatrix{T<:Range}(rs::AbstractVector{T})
RangeMatrix(rs::AbstractRange...) = RangeMatrix(collect(rs)) # TODO: use tuple storage?
function RangeMatrix(rs::AbstractVector{T}) where T <: AbstractRange
n = length(rs)
n == 0 && return RangeMatrix{T}(rs, (0, 0))
m = length(rs[1])
Expand All @@ -34,13 +34,16 @@ end

# For non-scalar indexing, only specialize with inner Ranges and Colons to
# return Ranges or RangeMatrixes. For everything else, we can use the fallbacks.
@inline function Base.getindex(R::RangeMatrix, I::Union{Range, Colon}, J)
@inline function Base.getindex(R::RangeMatrix, I::Union{AbstractRange, Colon}, J)
@boundscheck checkbounds(R, I, J)
unsafe_getindex(R, I, J)
end
@inline unsafe_getindex(R::RangeMatrix, I::Union{Range, Colon}, j::Real) = @inbounds return R.rs[j][I]
@inline unsafe_getindex(R::RangeMatrix, I::Union{Range, Colon}, ::Colon) = @inbounds return RangeMatrix([R.rs[j][I] for j=1:length(R.rs)])
@inline unsafe_getindex(R::RangeMatrix, I::Union{Range, Colon}, J) = @inbounds return RangeMatrix([R.rs[j][I] for j in J])
@inline unsafe_getindex(R::RangeMatrix, I::Union{AbstractRange, Colon}, j::Real) =
@inbounds return R.rs[j][I]
@inline unsafe_getindex(R::RangeMatrix, I::Union{AbstractRange, Colon}, ::Colon) =
@inbounds return RangeMatrix([R.rs[j][I] for j=1:length(R.rs)])
@inline unsafe_getindex(R::RangeMatrix, I::Union{AbstractRange, Colon}, J) =
@inbounds return RangeMatrix([R.rs[j][I] for j in J])

# We can also optimize bounds checks to only look at each range's endpoints
function Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, R::RangeMatrix)
Expand Down
11 changes: 6 additions & 5 deletions src/repeatedrange.jl
@@ -1,15 +1,16 @@
"""
RepeatedRangeMatrix{T}(r::Range{T}, at::AbstractVector{T})
RepeatedRangeMatrix(r::AbstractRange{T}, at::AbstractVector{T}) where T
A RepeatedRange is like a RangeMatrix, except that it only stores one range and
a vector of offsets, at which the range repeats. For now, both the range and
vector of offsets must have the same element type.
"""
immutable RepeatedRangeMatrix{T,R,A} <: AbstractMatrix{T}
struct RepeatedRangeMatrix{T,R,A} <: AbstractMatrix{T}
r::R # <: Range{T}
at::A #<: AbstractVector{T}
end
RepeatedRangeMatrix{T}(r::Range{T}, at::AbstractVector{T}) = RepeatedRangeMatrix{T, typeof(r), typeof(at)}(r, at)
RepeatedRangeMatrix(r::AbstractRange{T}, at::AbstractVector{T}) where T =
RepeatedRangeMatrix{T, typeof(r), typeof(at)}(r, at)

Base.size(R::RepeatedRangeMatrix) = (length(R.r), length(R.at))
@compat Base.IndexStyle(::Type{<:RepeatedRangeMatrix}) = IndexCartesian()
Expand Down Expand Up @@ -45,11 +46,11 @@ end

# For non-scalar indexing, only specialize with inner Ranges and Colons to
# return Ranges or RangeMatrixes. For everything else, we can use the fallbacks.
@inline function Base.getindex(R::RepeatedRangeMatrix, I::Union{Range, Colon}, j::Real)
@inline function Base.getindex(R::RepeatedRangeMatrix, I::Union{AbstractRange, Colon}, j::Real)
@boundscheck checkbounds(R, I, j)
@inbounds return R.r[I] + R.at[j]
end
@inline function Base.getindex(R::RepeatedRangeMatrix, I::Union{Range, Colon}, J)
@inline function Base.getindex(R::RepeatedRangeMatrix, I::Union{AbstractRange, Colon}, J)
@boundscheck checkbounds(R, I, J)
@inbounds return RepeatedRangeMatrix(R.r[I], R.at[J])
end
Expand Down

0 comments on commit 6f4ae29

Please sign in to comment.