Skip to content

Commit

Permalink
Rename CartesianRange->CartesianIndices
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Dec 16, 2017
1 parent f06b91c commit cd67176
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 217 deletions.
8 changes: 4 additions & 4 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ julia> extrema(b)
linearindices(A::AbstractArray) = (@_inline_meta; OneTo(_length(A)))
linearindices(A::AbstractVector) = (@_inline_meta; indices1(A))

keys(a::AbstractArray) = CartesianRange(axes(a))
keys(a::AbstractArray) = CartesianIndices(axes(a))
keys(a::AbstractVector) = linearindices(a)

prevind(::AbstractArray, i::Integer) = Int(i)-1
Expand Down Expand Up @@ -773,7 +773,7 @@ zero(x::AbstractArray{T}) where {T} = fill!(similar(x), zero(T))
# Allows fast iteration by default for both IndexLinear and IndexCartesian arrays

# While the definitions for IndexLinear are all simple enough to inline on their
# own, IndexCartesian's CartesianRange is more complicated and requires explicit
# own, IndexCartesian's CartesianIndices is more complicated and requires explicit
# inlining.
start(A::AbstractArray) = (@_inline_meta; itr = eachindex(A); (itr, start(itr)))
next(A::AbstractArray, i) = (@_propagate_inbounds_meta; (idx, s) = next(i[1], i[2]); (A[idx], (i[1], s)))
Expand Down Expand Up @@ -824,7 +824,7 @@ A[iter] = 0
If you supply more than one `AbstractArray` argument, `eachindex` will create an
iterable object that is fast for all arguments (a `UnitRange`
if all inputs have fast linear indexing, a [`CartesianRange`](@ref)
if all inputs have fast linear indexing, a [`CartesianIndices`](@ref)
otherwise).
If the arrays have different sizes and/or dimensionalities, `eachindex` will return an
iterable that spans the largest range along each dimension.
Expand Down Expand Up @@ -1815,7 +1815,7 @@ function mapslices(f, A::AbstractArray, dims::AbstractVector)
R[ridx...] = r1

nidx = length(otherdims)
indices = Iterators.drop(CartesianRange(itershape), 1)
indices = Iterators.drop(CartesianIndices(itershape), 1)
inner_mapslices!(safe_for_reuse, indices, nidx, idx, otherdims, ridx, Aslice, A, f, R)
end

Expand Down
2 changes: 1 addition & 1 deletion base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ cat_fill!(R, X::AbstractArray, inds) = fill!(view(R, inds...), X)
R[axes(A)...] = A
else
inner_indices = [1:n for n in inner]
for c in CartesianRange(axes(A))
for c in CartesianIndices(axes(A))
for i in 1:ndims(A)
n = inner[i]
inner_indices[i] = (1:n) .+ ((c[i] - 1) * n)
Expand Down
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ _collect_indices(indsA::Tuple{Vararg{OneTo}}, A) =
copy!(Array{eltype(A)}(uninitialized, length.(indsA)), A)
function _collect_indices(indsA, A)
B = Array{eltype(A)}(uninitialized, length.(indsA))
copy!(B, CartesianRange(axes(B)), A, CartesianRange(indsA))
copy!(B, CartesianIndices(axes(B)), A, CartesianIndices(indsA))
end

# define this as a macro so that the call to Inference
Expand Down
2 changes: 1 addition & 1 deletion base/arrayshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function show_nd(io::IO, a::AbstractArray, print_matrix::Function, label_slices:
end
tailinds = tail(tail(axes(a)))
nd = ndims(a)-2
for I in CartesianRange(tailinds)
for I in CartesianIndices(tailinds)
idxs = I.I
if limit
for i = 1:nd
Expand Down
2 changes: 1 addition & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ gen_bitarray(isz::IteratorSize, itr) = gen_bitarray_from_itr(itr, start(itr))
# generic iterable with known shape
function gen_bitarray(::HasShape, itr)
B = BitArray(uninitialized, size(itr))
for (I,x) in zip(CartesianRange(axes(itr)), itr)
for (I,x) in zip(CartesianIndices(axes(itr)), itr)
B[I] = x
end
return B
Expand Down
4 changes: 2 additions & 2 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ as in `broadcast!(f, A, A, B)` to perform `A[:] = broadcast(f, A, B)`.
shape = broadcast_indices(C)
@boundscheck check_broadcast_indices(shape, A, Bs...)
keeps, Idefaults = map_newindexer(shape, A, Bs)
iter = CartesianRange(shape)
iter = CartesianIndices(shape)
_broadcast!(f, C, keeps, Idefaults, A, Bs, Val(N), iter)
return C
end
Expand Down Expand Up @@ -616,7 +616,7 @@ end
# accommodate later values.
function broadcast_nonleaf(f, s::NonleafHandlingTypes, ::Type{ElType}, shape::Indices, As...) where ElType
nargs = length(As)
iter = CartesianRange(shape)
iter = CartesianIndices(shape)
if isempty(iter)
return Base.similar(Array{ElType}, shape)
end
Expand Down
47 changes: 25 additions & 22 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1381,10 +1381,10 @@ import .LinAlg: lufact, lufact!, qrfact, qrfact!, cholfact, cholfact!
@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(uninitialized, convert(Tuple{Vararg{Int}},tuple(d1,dims...))))
@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(uninitialized, dims))

function CartesianRange(start::CartesianIndex{N}, stop::CartesianIndex{N}) where N
function CartesianIndices(start::CartesianIndex{N}, stop::CartesianIndex{N}) where N
inds = map((f,l)->f:l, start.I, stop.I)
depwarn("the internal representation of CartesianRange has changed, use CartesianRange($inds) (or other more approriate AbstractUnitRange type) instead.", :CartesianRange)
CartesianRange(inds)
depwarn("the internal representation of CartesianIndices has changed, use CartesianIndices($inds) (or other more approriate AbstractUnitRange type) instead.", :CartesianIndices)
CartesianIndices(inds)
end

# PR #20005
Expand Down Expand Up @@ -3263,25 +3263,28 @@ end
@deprecate_moved unsafe_get "Nullables"

# sub2ind and ind2sub deprecation (PR #24715)
@deprecate ind2sub(A::AbstractArray, ind) CartesianRange(A)[ind]
@deprecate ind2sub(::Tuple{}, ind::Integer) CartesianRange()[ind]
@deprecate ind2sub(dims::Tuple{Vararg{Integer,N}} where N, ind::Integer) CartesianRange(dims)[ind]
@deprecate ind2sub(inds::Tuple{Base.OneTo}, ind::Integer) CartesianRange(inds)[ind]
@deprecate ind2sub(inds::Tuple{AbstractUnitRange}, ind::Integer) CartesianRange(inds)[ind]
@deprecate ind2sub(inds::Tuple{Vararg{AbstractUnitRange,N}} where N, ind::Integer) CartesianRange(inds)[ind]
@deprecate ind2sub(inds::Union{DimsInteger{N},Indices{N}} where N, ind::AbstractVector{<:Integer}) CartesianRange(inds)[ind]

@deprecate sub2ind(A::AbstractArray, I...) CartesianToLinear(A)[I...]
@deprecate sub2ind(dims::Tuple{}) CartesianToLinear(dims)[]
@deprecate sub2ind(dims::DimsInteger) CartesianToLinear(dims)[]
@deprecate sub2ind(dims::Indices) CartesianToLinear(dims)[]
@deprecate sub2ind(dims::Tuple{}, I::Integer...) CartesianToLinear(dims)[I...]
@deprecate sub2ind(dims::DimsInteger, I::Integer...) CartesianToLinear(dims)[I...]
@deprecate sub2ind(inds::Indices, I::Integer...) CartesianToLinear(inds)[I...]
@deprecate sub2ind(inds::Tuple{OneTo}, I::Integer...) CartesianToLinear(inds)[I...]
@deprecate sub2ind(inds::Tuple{OneTo}, i::Integer) CartesianToLinear(inds)[i]
@deprecate sub2ind(inds::Tuple{OneTo}, I1::AbstractVector{T}, I::AbstractVector{T}...) where {T<:Integer} CartesianToLinear(inds)[CartesianIndex.(I1, I...)]
@deprecate sub2ind(inds::Union{DimsInteger,Indices}, I1::AbstractVector{T}, I::AbstractVector{T}...) where {T<:Integer} CartesianToLinear(inds)[CartesianIndex.(I1, I...)]
@deprecate ind2sub(A::AbstractArray, ind) CartesianIndices(A)[ind]
@deprecate ind2sub(::Tuple{}, ind::Integer) CartesianIndices()[ind]
@deprecate ind2sub(dims::Tuple{Vararg{Integer,N}} where N, ind::Integer) CartesianIndices(dims)[ind]
@deprecate ind2sub(inds::Tuple{Base.OneTo}, ind::Integer) CartesianIndices(inds)[ind]
@deprecate ind2sub(inds::Tuple{AbstractUnitRange}, ind::Integer) CartesianIndices(inds)[ind]
@deprecate ind2sub(inds::Tuple{Vararg{AbstractUnitRange,N}} where N, ind::Integer) CartesianIndices(inds)[ind]
@deprecate ind2sub(inds::Union{DimsInteger{N},Indices{N}} where N, ind::AbstractVector{<:Integer}) CartesianIndices(inds)[ind]

@deprecate sub2ind(A::AbstractArray, I...) LinearIndices(A)[I...]
@deprecate sub2ind(dims::Tuple{}) LinearIndices(dims)[]
@deprecate sub2ind(dims::DimsInteger) LinearIndices(dims)[]
@deprecate sub2ind(dims::Indices) LinearIndices(dims)[]
@deprecate sub2ind(dims::Tuple{}, I::Integer...) LinearIndices(dims)[I...]
@deprecate sub2ind(dims::DimsInteger, I::Integer...) LinearIndices(dims)[I...]
@deprecate sub2ind(inds::Indices, I::Integer...) LinearIndices(inds)[I...]
@deprecate sub2ind(inds::Tuple{OneTo}, I::Integer...) LinearIndices(inds)[I...]
@deprecate sub2ind(inds::Tuple{OneTo}, i::Integer) LinearIndices(inds)[i]
@deprecate sub2ind(inds::Tuple{OneTo}, I1::AbstractVector{T}, I::AbstractVector{T}...) where {T<:Integer} LinearIndices(inds)[CartesianIndex.(I1, I...)]
@deprecate sub2ind(inds::Union{DimsInteger,Indices}, I1::AbstractVector{T}, I::AbstractVector{T}...) where {T<:Integer} LinearIndices(inds)[CartesianIndex.(I1, I...)]

# PR #25113
@deprecate_binding CartesianRange CartesianIndices

# END 0.7 deprecations

Expand Down
4 changes: 2 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export
BitVector,
BufferStream,
CartesianIndex,
CartesianRange,
CartesianToLinear,
CartesianIndices,
LinearIndices,
Channel,
Cmd,
Colon,
Expand Down
4 changes: 2 additions & 2 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,14 @@ function write(s::IO, a::SubArray{T,N,<:Array}) where {T,N}
elsz = sizeof(T)
colsz = size(a,1) * elsz
@gc_preserve a if stride(a,1) != 1
for idxs in CartesianRange(size(a))
for idxs in CartesianIndices(size(a))
unsafe_write(s, pointer(a, idxs.I), elsz)
end
return elsz * length(a)
elseif N <= 1
return unsafe_write(s, pointer(a, 1), colsz)
else
for idxs in CartesianRange((1, size(a)[2:end]...))
for idxs in CartesianIndices((1, size(a)[2:end]...))
unsafe_write(s, pointer(a, idxs.I), colsz)
end
return colsz * trailingsize(a,2)
Expand Down
2 changes: 1 addition & 1 deletion base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ CartesianIndex(2, 2) e
See also: [`IndexStyle`](@ref), [`axes`](@ref).
"""
pairs(::IndexLinear, A::AbstractArray) = IndexValue(A, linearindices(A))
pairs(::IndexCartesian, A::AbstractArray) = IndexValue(A, CartesianRange(axes(A)))
pairs(::IndexCartesian, A::AbstractArray) = IndexValue(A, CartesianIndices(axes(A)))

# faster than zip(keys(a), values(a)) for arrays
pairs(A::AbstractArray) = pairs(IndexCartesian(), A)
Expand Down
Loading

0 comments on commit cd67176

Please sign in to comment.