Skip to content

Commit

Permalink
Deprecate indices in favor of cartesianindices
Browse files Browse the repository at this point in the history
  • Loading branch information
emmt committed Nov 28, 2019
1 parent 89dfaed commit 078c7b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
30 changes: 16 additions & 14 deletions src/ArrayTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export
bcastdim,
bcastdims,
bcastlazy,
cartesianindices,
checkdimensions,
colons,
Dimensions,
Expand Down Expand Up @@ -39,6 +40,7 @@ using Base: OneTo, axes1, @_inline_meta
import Base: dotview, getindex, setindex!

@deprecate colons rubberindex
@deprecate indices cartesianindices

"""
```julia
Expand Down Expand Up @@ -374,11 +376,11 @@ has_standard_indexing(::Number) = true
The calls:
```julia
indices(A)
indices((n1, n2, ...))
indices((i1:j1, i2:j2, ...))
indices(CartesianIndex(i1, i2, ...), CartesianIndex(j1, j2, ...))
indices(R)
cartesianindices(A)
cartesianindices((n1, n2, ...))
cartesianindices((i1:j1, i2:j2, ...))
cartesianindices(CartesianIndex(i1, i2, ...), CartesianIndex(j1, j2, ...))
cartesianindices(R)
```
all yield an instance of `CartesianIndices` suitable for multi-dimensional
Expand All @@ -388,13 +390,13 @@ last indices are `(i1,i2,...)` and `(j1,j2,...)` or a Cartesian region defined
by `R`, an instance of `CartesianIndices`.
"""
indices(A::AbstractArray) = indices(axes(A))
indices(R::CartesianIndices) = R
@inline indices(start::CartesianIndex{N}, stop::CartesianIndex{N}) where {N} =
cartesianindices(A::AbstractArray) = cartesianindices(axes(A))
cartesianindices(R::CartesianIndices) = R
@inline cartesianindices(start::CartesianIndex{N}, stop::CartesianIndex{N}) where {N} =
CartesianIndices(map((i,j) -> (i == 1 ? Base.OneTo(j) : i:j), start.I, stop.I))
indices(dims::Tuple{Vararg{Integer}}) =
cartesianindices(dims::Tuple{Vararg{Integer}}) =
CartesianIndices(map(dim -> Base.OneTo(dim), dims))
indices(rngs::NTuple{N,AbstractUnitRange{<:Integer}}) where {N} =
cartesianindices(rngs::NTuple{N,AbstractUnitRange{<:Integer}}) where {N} =
CartesianIndices(rngs)

# The following, would yield an `AbstractUnitRange` if a single argument is
Expand All @@ -404,10 +406,10 @@ indices(rngs::NTuple{N,AbstractUnitRange{<:Integer}}) where {N} =
# of dimensions, a tuple of unit ranges or a pair of `CartesianIndices` yields
# the indices of the Cartesian region defined by these arguments.
#
#indices(dim::Int) = Base.OneTo(dim)
#indices(dim::Integer) = Base.OneTo(Int(dim))
#indices(rng::AbstractUnitRange{Int}) = rng
#indices(rng::AbstractUnitRange{<:Integer}) = convert(UnitRange{Int}, rng)
#cartesianindices(dim::Int) = Base.OneTo(dim)
#cartesianindices(dim::Integer) = Base.OneTo(Int(dim))
#cartesianindices(rng::AbstractUnitRange{Int}) = rng
#cartesianindices(rng::AbstractUnitRange{<:Integer}) = convert(UnitRange{Int}, rng)


#------------------------------------------------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ atol = 1e-6
@test anyof(x) == (anyof(minimum, x, x) || anyof(maximum, x))
end
#
# Tests for `indices`.
# Tests for `cartesianindices`.
#
@test indices(A) === CartesianIndices(axes(A))
@test indices(A) === indices(size(A))
@test indices(A) === indices(axes(A))
@test indices(A) === indices(indices(A))
@test_deprecated indices(A) === CartesianIndices(axes(A))
@test cartesianindices(A) === CartesianIndices(axes(A))
@test cartesianindices(A) === cartesianindices(size(A))
@test cartesianindices(A) === cartesianindices(axes(A))
@test cartesianindices(A) === cartesianindices(cartesianindices(A))
#
# Tests for `safeindices`.
#
Expand All @@ -129,7 +130,7 @@ end
I1 = CartesianIndex(2)
I2 = CartesianIndex(3,4)
I3 = CartesianIndex(3,4,5)
@test colons(5) == rubberindex(5)
@test_deprecated colons(5) == rubberindex(5)
for d 0:12
tup = ntuple(x -> Colon(), d)
@test rubberindex(d) === tup
Expand Down

0 comments on commit 078c7b4

Please sign in to comment.