@@ -34,49 +34,49 @@ size(x, d1::Integer, d2::Integer, dx::Vararg{Integer, N}) where {N} =
3434 (size (x, d1), size (x, d2), ntuple (k-> size (x, dx[k]), Val (N))... )
3535
3636"""
37- indices (A, d)
37+ axes (A, d)
3838
3939Return the valid range of indices for array `A` along dimension `d`.
4040
4141# Examples
4242```jldoctest
4343julia> A = ones(5,6,7);
4444
45- julia> indices (A,2)
45+ julia> axes (A,2)
4646Base.OneTo(6)
4747```
4848"""
49- function indices (A:: AbstractArray{T,N} , d) where {T,N}
49+ function axes (A:: AbstractArray{T,N} , d) where {T,N}
5050 @_inline_meta
51- d <= N ? indices (A)[d] : OneTo (1 )
51+ d <= N ? axes (A)[d] : OneTo (1 )
5252end
5353
5454"""
55- indices (A)
55+ axes (A)
5656
5757Return the tuple of valid indices for array `A`.
5858
5959# Examples
6060```jldoctest
6161julia> A = ones(5,6,7);
6262
63- julia> indices (A)
63+ julia> axes (A)
6464(Base.OneTo(5), Base.OneTo(6), Base.OneTo(7))
6565```
6666"""
67- function indices (A)
67+ function axes (A)
6868 @_inline_meta
6969 map (OneTo, size (A))
7070end
7171
72- # Performance optimization: get rid of a branch on `d` in `indices (A, d)`
72+ # Performance optimization: get rid of a branch on `d` in `axes (A, d)`
7373# for d=1. 1d arrays are heavily used, and the first dimension comes up
7474# in other applications.
7575indices1 (A:: AbstractArray{<:Any,0} ) = OneTo (1 )
76- indices1 (A:: AbstractArray ) = (@_inline_meta ; indices (A)[1 ])
76+ indices1 (A:: AbstractArray ) = (@_inline_meta ; axes (A)[1 ])
7777indices1 (iter) = OneTo (length (iter))
7878
79- unsafe_indices (A) = indices (A)
79+ unsafe_indices (A) = axes (A)
8080unsafe_indices (r:: AbstractRange ) = (OneTo (unsafe_length (r)),) # Ranges use checked_sub for size
8181
8282"""
@@ -86,7 +86,7 @@ Return a `UnitRange` specifying the valid range of indices for `A[i]`
8686where `i` is an `Int`. For arrays with conventional indexing (indices
8787start at 1), or any multidimensional array, this is `1:length(A)`;
8888however, for one-dimensional arrays with unconventional indices, this
89- is `indices (A, 1)`.
89+ is `axes (A, 1)`.
9090
9191Calling this function is the "safe" way to write algorithms that
9292exploit linear indexing.
@@ -104,7 +104,7 @@ julia> extrema(b)
104104linearindices (A:: AbstractArray ) = (@_inline_meta ; OneTo (_length (A)))
105105linearindices (A:: AbstractVector ) = (@_inline_meta ; indices1 (A))
106106
107- keys (a:: AbstractArray ) = CartesianRange (indices (a))
107+ keys (a:: AbstractArray ) = CartesianRange (axes (a))
108108keys (a:: AbstractVector ) = linearindices (a)
109109
110110prevind (:: AbstractArray , i:: Integer ) = Int (i)- 1
@@ -150,7 +150,7 @@ julia> length([1 2; 3 4])
150150```
151151"""
152152length (t:: AbstractArray ) = (@_inline_meta ; prod (size (t)))
153- _length (A:: AbstractArray ) = (@_inline_meta ; prod (map (unsafe_length, indices (A)))) # circumvent missing size
153+ _length (A:: AbstractArray ) = (@_inline_meta ; prod (map (unsafe_length, axes (A)))) # circumvent missing size
154154_length (A) = (@_inline_meta ; length (A))
155155
156156"""
@@ -376,7 +376,7 @@ false
376376"""
377377function checkbounds (:: Type{Bool} , A:: AbstractArray , I... )
378378 @_inline_meta
379- checkbounds_indices (Bool, indices (A), I)
379+ checkbounds_indices (Bool, axes (A), I)
380380end
381381# Linear indexing is explicitly allowed when there is only one (non-cartesian) index
382382function checkbounds (:: Type{Bool} , A:: AbstractArray , i)
386386# As a special extension, allow using logical arrays that match the source array exactly
387387function checkbounds (:: Type{Bool} , A:: AbstractArray{<:Any,N} , I:: AbstractArray{Bool,N} ) where N
388388 @_inline_meta
389- indices (A) == indices (I)
389+ axes (A) == axes (I)
390390end
391391
392392"""
@@ -519,7 +519,7 @@ julia> similar(falses(10), Float64, 2, 4)
519519
520520"""
521521similar (a:: AbstractArray{T} ) where {T} = similar (a, T)
522- similar (a:: AbstractArray , :: Type{T} ) where {T} = similar (a, T, to_shape (indices (a)))
522+ similar (a:: AbstractArray , :: Type{T} ) where {T} = similar (a, T, to_shape (axes (a)))
523523similar (a:: AbstractArray{T} , dims:: Tuple ) where {T} = similar (a, T, to_shape (dims))
524524similar (a:: AbstractArray{T} , dims:: DimOrInd... ) where {T} = similar (a, T, to_shape (dims))
525525similar (a:: AbstractArray , :: Type{T} , dims:: DimOrInd... ) where {T} = similar (a, T, to_shape (dims))
@@ -545,20 +545,20 @@ argument. `storagetype` might be a type or a function.
545545
546546**Examples**:
547547
548- similar(Array{Int}, indices (A))
548+ similar(Array{Int}, axes (A))
549549
550550creates an array that "acts like" an `Array{Int}` (and might indeed be
551551backed by one), but which is indexed identically to `A`. If `A` has
552552conventional indexing, this will be identical to
553553`Array{Int}(uninitialized, size(A))`, but if `A` has unconventional indexing then the
554554indices of the result will match `A`.
555555
556- similar(BitArray, (indices (A, 2),))
556+ similar(BitArray, (axes (A, 2),))
557557
558558would create a 1-dimensional logical array whose indices match those
559559of the columns of `A`.
560560
561- similar(dims->zeros(Int, dims), indices (A))
561+ similar(dims->zeros(Int, dims), axes (A))
562562
563563would create an array of `Int`, initialized to zero, matching the
564564indices of `A`.
@@ -869,7 +869,7 @@ convert(::Type{Array}, A::AbstractArray{T,N}) where {T,N} = convert(Array{T,N},
869869
870870Represents the array `y` as an array having the same indices type as `x`.
871871"""
872- of_indices (x, y) = similar (dims-> y, oftype (indices (x), indices (y)))
872+ of_indices (x, y) = similar (dims-> y, oftype (axes (x), axes (y)))
873873
874874
875875# # range conversions ##
@@ -986,11 +986,11 @@ function _to_subscript_indices(A::AbstractArray{T,N}, I::Int...) where {T,N}
986986 _to_subscript_indices (A, J, Jrem)
987987end
988988_to_subscript_indices (A:: AbstractArray , J:: Tuple , Jrem:: Tuple{} ) =
989- __to_subscript_indices (A, indices (A), J, Jrem)
989+ __to_subscript_indices (A, axes (A), J, Jrem)
990990function __to_subscript_indices (A:: AbstractArray ,
991991 :: Tuple{AbstractUnitRange,Vararg{AbstractUnitRange}} , J:: Tuple , Jrem:: Tuple{} )
992992 @_inline_meta
993- (J... , map (first, tail (_remaining_size (J, indices (A))))... )
993+ (J... , map (first, tail (_remaining_size (J, axes (A))))... )
994994end
995995_to_subscript_indices (A, J:: Tuple , Jrem:: Tuple ) = J # already bounds-checked, safe to drop
996996_to_subscript_indices (A:: AbstractArray{T,N} , I:: Vararg{Int,N} ) where {T,N} = I
@@ -1200,7 +1200,7 @@ cat_size(A, d) = 1
12001200cat_size (A:: AbstractArray , d) = size (A, d)
12011201
12021202cat_indices (A, d) = OneTo (1 )
1203- cat_indices (A:: AbstractArray , d) = indices (A, d)
1203+ cat_indices (A:: AbstractArray , d) = axes (A, d)
12041204
12051205cat_similar (A, T, shape) = Array {T} (uninitialized, shape)
12061206cat_similar (A:: AbstractArray , T, shape) = similar (A, T, shape)
@@ -1543,7 +1543,7 @@ end
15431543
15441544function isequal (A:: AbstractArray , B:: AbstractArray )
15451545 if A === B return true end
1546- if indices (A) != indices (B)
1546+ if axes (A) != axes (B)
15471547 return false
15481548 end
15491549 if isa (A,AbstractRange) != isa (B,AbstractRange)
@@ -1566,7 +1566,7 @@ function lexcmp(A::AbstractArray, B::AbstractArray)
15661566end
15671567
15681568function (== )(A:: AbstractArray , B:: AbstractArray )
1569- if indices (A) != indices (B)
1569+ if axes (A) != axes (B)
15701570 return false
15711571 end
15721572 if isa (A,AbstractRange) != isa (B,AbstractRange)
@@ -1588,7 +1588,7 @@ end
15881588# fallbacks
15891589function sub2ind (A:: AbstractArray , I... )
15901590 @_inline_meta
1591- sub2ind (indices (A), I... )
1591+ sub2ind (axes (A), I... )
15921592end
15931593
15941594"""
@@ -1609,7 +1609,7 @@ julia> ind2sub(A,70)
16091609"""
16101610function ind2sub (A:: AbstractArray , ind)
16111611 @_inline_meta
1612- ind2sub (indices (A), ind)
1612+ ind2sub (axes (A), ind)
16131613end
16141614
16151615# 0-dimensional arrays and indexing with []
@@ -1835,16 +1835,16 @@ function mapslices(f, A::AbstractArray, dims::AbstractVector)
18351835 return map (f,A)
18361836 end
18371837
1838- dimsA = [indices (A)... ]
1838+ dimsA = [axes (A)... ]
18391839 ndimsA = ndims (A)
18401840 alldims = [1 : ndimsA;]
18411841
18421842 otherdims = setdiff (alldims, dims)
18431843
1844- idx = Any[first (ind) for ind in indices (A)]
1844+ idx = Any[first (ind) for ind in axes (A)]
18451845 itershape = tuple (dimsA[otherdims]. .. )
18461846 for d in dims
1847- idx[d] = Slice (indices (A, d))
1847+ idx[d] = Slice (axes (A, d))
18481848 end
18491849
18501850 # Apply the function to the first slice in order to determine the next steps
@@ -1867,13 +1867,13 @@ function mapslices(f, A::AbstractArray, dims::AbstractVector)
18671867 if eltype (Rsize) == Int
18681868 Rsize[dims] = [size (r1)... , ntuple (d-> 1 , nextra)... ]
18691869 else
1870- Rsize[dims] = [indices (r1)... , ntuple (d-> OneTo (1 ), nextra)... ]
1870+ Rsize[dims] = [axes (r1)... , ntuple (d-> OneTo (1 ), nextra)... ]
18711871 end
18721872 R = similar (r1, tuple (Rsize... ,))
18731873
1874- ridx = Any[map (first, indices (R))... ]
1874+ ridx = Any[map (first, axes (R))... ]
18751875 for d in dims
1876- ridx[d] = indices (R,d)
1876+ ridx[d] = axes (R,d)
18771877 end
18781878
18791879 R[ridx... ] = r1
0 commit comments