Skip to content

Commit ce6ecce

Browse files
authored
Merge pull request #26 from alsam/teh/various
Various improvements
2 parents 174fc7a + 93076d5 commit ce6ecce

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/OffsetArrays.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ __precompile__()
22

33
module OffsetArrays
44

5-
Base.@deprecate_binding (..) Colon()
6-
75
using Base: Indices, tail
86
using Compat
97

@@ -23,6 +21,8 @@ OffsetArray{T,N}(A::AbstractArray{T,N}, offsets::Vararg{Int,N}) =
2321
(::Type{OffsetArray{T,N}}){T,N}(inds::Indices{N}) =
2422
OffsetArray{T,N,Array{T,N}}(Array{T,N}(map(length, inds)), map(indexoffset, inds))
2523
(::Type{OffsetArray{T}}){T,N}(inds::Indices{N}) = OffsetArray{T,N}(inds)
24+
(::Type{OffsetArray{T,N}}){T,N}(inds::Vararg{AbstractUnitRange,N}) = OffsetArray{T,N}(inds)
25+
(::Type{OffsetArray{T}}){T,N}(inds::Vararg{AbstractUnitRange,N}) = OffsetArray{T,N}(inds)
2626
OffsetArray{T}(A::AbstractArray{T,0}) = OffsetArray{T,0,typeof(A)}(A, ())
2727
OffsetArray{T,N}(::Type{T}, inds::Vararg{UnitRange{Int},N}) = OffsetArray{T,N}(inds)
2828

@@ -125,7 +125,7 @@ Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
125125
### Low-level utilities ###
126126

127127
# Computing a shifted index (subtracting the offset)
128-
offset{N}(offsets::NTuple{N,Int}, inds::NTuple{N,Int}) = _offset((), offsets, inds)
128+
@inline offset{N}(offsets::NTuple{N,Int}, inds::NTuple{N,Int}) = _offset((), offsets, inds)
129129
_offset(out, ::Tuple{}, ::Tuple{}) = out
130130
@inline _offset(out, offsets, inds) =
131131
_offset((out..., inds[1]-offsets[1]), Base.tail(offsets), Base.tail(inds))
@@ -213,11 +213,4 @@ end
213213
@inline unsafe_getindex(a::OffsetSubArray, I::Union{Integer,CartesianIndex}...) = unsafe_getindex(a, Base.IteratorsMD.flatten(I)...)
214214
@inline unsafe_setindex!(a::OffsetSubArray, val, I::Union{Integer,CartesianIndex}...) = unsafe_setindex!(a, val, Base.IteratorsMD.flatten(I)...)
215215

216-
# Deprecations
217-
import Base: zeros, ones
218-
@deprecate zeros(T::Type, ind1::UnitRange, ind2::UnitRange, inds::UnitRange...) fill!(OffsetArray{T}((ind1, ind2, inds...)), zero(T))
219-
@deprecate ones(T::Type, ind1::UnitRange, inds2::UnitRange, inds::UnitRange...) fill!(OffsetArray{T}((ind1, ind2, inds...)), one(T))
220-
@deprecate zeros(ind1::UnitRange, ind2::UnitRange, inds::UnitRange...) fill!(OffsetArray{Float64}((ind1, ind2, inds...)), 0)
221-
@deprecate ones(ind1::UnitRange, ind2::UnitRange, inds::UnitRange...) fill!(OffsetArray{Float64}((ind1, ind2, inds...)), 1)
222-
223216
end # module

test/runtests.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ using Base.Test
22
using OffsetArrays
33
using Compat
44

5-
ambs = detect_ambiguities(Base, Core) # in case these have ambiguities of their own
6-
@test isempty(setdiff(detect_ambiguities(OffsetArrays, Base, Core), ambs))
5+
@test isempty(detect_ambiguities(OffsetArrays, Base, Core))
76

87
# Basics
98
for n = 0:5
10-
a = OffsetArray(ones(Int,ntuple(d->1,n)), ntuple(x->x-1,n))
11-
@test length(linearindices(a)) == 1
12-
@test indices(a) == ntuple(x->x:x,n)
13-
@test a[1] == 1
9+
for a in (OffsetArray(ones(Int,ntuple(d->1,n)), ntuple(x->x-1,n)),
10+
fill!(OffsetArray(Float64, ntuple(x->(0:0)+x, n)...), 1),
11+
fill!(OffsetArray{Float64}(ntuple(x->(0:0)+x, n)), 1),
12+
fill!(OffsetArray{Float64}(ntuple(x->(0:0)+x, n)...), 1),
13+
fill!(OffsetArray{Float64,n}(ntuple(x->(0:0)+x, n)), 1),
14+
fill!(OffsetArray{Float64,n}(ntuple(x->(0:0)+x, n)...), 1))
15+
@test length(linearindices(a)) == 1
16+
@test indices(a) == ntuple(x->x:x,n)
17+
@test a[1] == 1
18+
end
1419
end
1520
a0 = reshape([3])
1621
a = OffsetArray(a0)

0 commit comments

Comments
 (0)