Skip to content

Commit b43c0fb

Browse files
authored
Merge pull request #19 from alsam/teh/0.6
Fixes for Julia 0.6
2 parents fbc5d58 + 6d19a9e commit b43c0fb

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/OffsetArrays.jl

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ Base.eachindex(::LinearFast, A::OffsetVector) = indices(A, 1)
5353
# Implementations of indices and indices1. Since bounds-checking is
5454
# performance-critical and relies on indices, these are usually worth
5555
# optimizing thoroughly.
56-
@inline Base.indices(A::OffsetArray, d) = 1 <= d <= length(A.offsets) ? indices(parent(A))[d] + A.offsets[d] : (1:1)
57-
@inline Base.indices(A::OffsetArray) = _indices(indices(parent(A)), A.offsets) # would rather use ntuple, but see #15276
58-
@inline _indices(inds, offsets) = (inds[1]+offsets[1], _indices(tail(inds), tail(offsets))...)
56+
@inline Base.indices(A::OffsetArray, d) =
57+
1 <= d <= length(A.offsets) ? indices(parent(A))[d] + A.offsets[d] : (1:1)
58+
@inline Base.indices(A::OffsetArray) =
59+
_indices(indices(parent(A)), A.offsets) # would rather use ntuple, but see #15276
60+
@inline _indices(inds, offsets) =
61+
(inds[1]+offsets[1], _indices(tail(inds), tail(offsets))...)
5962
_indices(::Tuple{}, ::Tuple{}) = ()
6063
Base.indices1{T}(A::OffsetArray{T,0}) = 1:1 # we only need to specialize this one
6164

@@ -67,11 +70,14 @@ function Base.similar{T}(A::AbstractArray, ::Type{T}, inds::Tuple{UnitRange,Vara
6770
OffsetArray(B, map(indexoffset, inds))
6871
end
6972

70-
Base.similar(f::Union{Function,Type}, shape::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(f(map(length, shape)), map(indexoffset, shape))
73+
Base.similar(f::Union{Function,Type}, shape::Tuple{UnitRange,Vararg{UnitRange}}) =
74+
OffsetArray(f(map(length, shape)), map(indexoffset, shape))
7175

72-
Base.reshape(A::AbstractArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(reshape(A, map(length, inds)), map(indexoffset, inds))
76+
Base.reshape(A::AbstractArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
77+
OffsetArray(reshape(A, map(length, inds)), map(indexoffset, inds))
7378

74-
Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(reshape(parent(A), map(length, inds)), map(indexoffset, inds))
79+
Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
80+
OffsetArray(reshape(parent(A), map(length, inds)), map(indexoffset, inds))
7581

7682
function Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{Union{UnitRange,Int,Base.OneTo}}})
7783
throw(ArgumentError("reshape must supply UnitRange indices, got $(typeof(inds)).\n Note that reshape(A, Val{N}) is not supported for OffsetArrays."))
@@ -83,12 +89,12 @@ end
8389
@inbounds ret = parent(A)[offset(A.offsets, I)...]
8490
ret
8591
end
86-
@inline function Base._getindex(::LinearFast, A::OffsetVector, i::Int)
92+
@inline function Base.getindex(A::OffsetVector, i::Int)
8793
checkbounds(A, i)
8894
@inbounds ret = parent(A)[offset(A.offsets, (i,))[1]]
8995
ret
9096
end
91-
@inline function Base._getindex(::LinearFast, A::OffsetArray, i::Int)
97+
@inline function Base.getindex(A::OffsetArray, i::Int)
9298
checkbounds(A, i)
9399
@inbounds ret = parent(A)[i]
94100
ret
@@ -98,31 +104,34 @@ end
98104
@inbounds parent(A)[offset(A.offsets, I)...] = val
99105
val
100106
end
101-
@inline function Base._setindex!(::LinearFast, A::OffsetVector, val, i::Int)
107+
@inline function Base.setindex!(A::OffsetVector, val, i::Int)
102108
checkbounds(A, i)
103109
@inbounds parent(A)[offset(A.offsets, (i,))[1]] = val
104110
val
105111
end
106-
@inline function Base._setindex!(::LinearFast, A::OffsetArray, val, i::Int)
112+
@inline function Base.setindex!(A::OffsetArray, val, i::Int)
107113
checkbounds(A, i)
108114
@inbounds parent(A)[i] = val
109115
val
110116
end
111117

112118
### Convenience functions ###
113119

114-
Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) = fill!(OffsetArray{typeof(x)}(inds), x)
120+
Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
121+
fill!(OffsetArray{typeof(x)}(inds), x)
115122
@inline Base.fill(x, ind1::UnitRange, inds::UnitRange...) = fill(x, (ind1, inds...))
116123

117124
### Low-level utilities ###
118125

119126
# Computing a shifted index (subtracting the offset)
120127
offset{N}(offsets::NTuple{N,Int}, inds::NTuple{N,Int}) = _offset((), offsets, inds)
121128
_offset(out, ::Tuple{}, ::Tuple{}) = out
122-
@inline _offset(out, offsets, inds) = _offset((out..., inds[1]-offsets[1]), Base.tail(offsets), Base.tail(inds))
129+
@inline _offset(out, offsets, inds) =
130+
_offset((out..., inds[1]-offsets[1]), Base.tail(offsets), Base.tail(inds))
123131

124132
# Support trailing 1s
125-
@inline offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{Vararg{Int}}) = (offset(offsets, Base.front(inds))..., inds[end])
133+
@inline offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{Vararg{Int}}) =
134+
(offset(offsets, Base.front(inds))..., inds[end])
126135
offset(offsets::Tuple{}, inds::Tuple{}) = ()
127136
offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{}) = error("inds cannot be shorter than offsets")
128137

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ seek(io, 0)
311311
@test readdlm(io, eltype(A)) == parent(A)
312312

313313
amin, amax = extrema(parent(A))
314-
@test clamp(A, (amax+amin)/2, amax) == clamp(parent(A), (amax+amin)/2, amax)
314+
@test clamp.(A, (amax+amin)/2, amax) == OffsetArray(clamp.(parent(A), (amax+amin)/2, amax), indices(A))
315315

316316
@test unique(A, 1) == parent(A)
317317
@test unique(A, 2) == parent(A)

0 commit comments

Comments
 (0)