@@ -34,49 +34,49 @@ size(x, d1::Integer, d2::Integer, dx::Vararg{Integer, N}) where {N} =
34
34
(size (x, d1), size (x, d2), ntuple (k-> size (x, dx[k]), Val (N))... )
35
35
36
36
"""
37
- indices (A, d)
37
+ axes (A, d)
38
38
39
39
Return the valid range of indices for array `A` along dimension `d`.
40
40
41
41
# Examples
42
42
```jldoctest
43
43
julia> A = ones(5,6,7);
44
44
45
- julia> indices (A,2)
45
+ julia> axes (A,2)
46
46
Base.OneTo(6)
47
47
```
48
48
"""
49
- function indices (A:: AbstractArray{T,N} , d) where {T,N}
49
+ function axes (A:: AbstractArray{T,N} , d) where {T,N}
50
50
@_inline_meta
51
- d <= N ? indices (A)[d] : OneTo (1 )
51
+ d <= N ? axes (A)[d] : OneTo (1 )
52
52
end
53
53
54
54
"""
55
- indices (A)
55
+ axes (A)
56
56
57
57
Return the tuple of valid indices for array `A`.
58
58
59
59
# Examples
60
60
```jldoctest
61
61
julia> A = ones(5,6,7);
62
62
63
- julia> indices (A)
63
+ julia> axes (A)
64
64
(Base.OneTo(5), Base.OneTo(6), Base.OneTo(7))
65
65
```
66
66
"""
67
- function indices (A)
67
+ function axes (A)
68
68
@_inline_meta
69
69
map (OneTo, size (A))
70
70
end
71
71
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)`
73
73
# for d=1. 1d arrays are heavily used, and the first dimension comes up
74
74
# in other applications.
75
75
indices1 (A:: AbstractArray{<:Any,0} ) = OneTo (1 )
76
- indices1 (A:: AbstractArray ) = (@_inline_meta ; indices (A)[1 ])
76
+ indices1 (A:: AbstractArray ) = (@_inline_meta ; axes (A)[1 ])
77
77
indices1 (iter) = OneTo (length (iter))
78
78
79
- unsafe_indices (A) = indices (A)
79
+ unsafe_indices (A) = axes (A)
80
80
unsafe_indices (r:: AbstractRange ) = (OneTo (unsafe_length (r)),) # Ranges use checked_sub for size
81
81
82
82
"""
@@ -86,7 +86,7 @@ Return a `UnitRange` specifying the valid range of indices for `A[i]`
86
86
where `i` is an `Int`. For arrays with conventional indexing (indices
87
87
start at 1), or any multidimensional array, this is `1:length(A)`;
88
88
however, for one-dimensional arrays with unconventional indices, this
89
- is `indices (A, 1)`.
89
+ is `axes (A, 1)`.
90
90
91
91
Calling this function is the "safe" way to write algorithms that
92
92
exploit linear indexing.
@@ -104,7 +104,7 @@ julia> extrema(b)
104
104
linearindices (A:: AbstractArray ) = (@_inline_meta ; OneTo (_length (A)))
105
105
linearindices (A:: AbstractVector ) = (@_inline_meta ; indices1 (A))
106
106
107
- keys (a:: AbstractArray ) = CartesianRange (indices (a))
107
+ keys (a:: AbstractArray ) = CartesianRange (axes (a))
108
108
keys (a:: AbstractVector ) = linearindices (a)
109
109
110
110
prevind (:: AbstractArray , i:: Integer ) = Int (i)- 1
@@ -150,7 +150,7 @@ julia> length([1 2; 3 4])
150
150
```
151
151
"""
152
152
length (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
154
154
_length (A) = (@_inline_meta ; length (A))
155
155
156
156
"""
@@ -376,7 +376,7 @@ false
376
376
"""
377
377
function checkbounds (:: Type{Bool} , A:: AbstractArray , I... )
378
378
@_inline_meta
379
- checkbounds_indices (Bool, indices (A), I)
379
+ checkbounds_indices (Bool, axes (A), I)
380
380
end
381
381
# Linear indexing is explicitly allowed when there is only one (non-cartesian) index
382
382
function checkbounds (:: Type{Bool} , A:: AbstractArray , i)
386
386
# As a special extension, allow using logical arrays that match the source array exactly
387
387
function checkbounds (:: Type{Bool} , A:: AbstractArray{<:Any,N} , I:: AbstractArray{Bool,N} ) where N
388
388
@_inline_meta
389
- indices (A) == indices (I)
389
+ axes (A) == axes (I)
390
390
end
391
391
392
392
"""
@@ -519,7 +519,7 @@ julia> similar(falses(10), Float64, 2, 4)
519
519
520
520
"""
521
521
similar (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)))
523
523
similar (a:: AbstractArray{T} , dims:: Tuple ) where {T} = similar (a, T, to_shape (dims))
524
524
similar (a:: AbstractArray{T} , dims:: DimOrInd... ) where {T} = similar (a, T, to_shape (dims))
525
525
similar (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.
545
545
546
546
**Examples**:
547
547
548
- similar(Array{Int}, indices (A))
548
+ similar(Array{Int}, axes (A))
549
549
550
550
creates an array that "acts like" an `Array{Int}` (and might indeed be
551
551
backed by one), but which is indexed identically to `A`. If `A` has
552
552
conventional indexing, this will be identical to
553
553
`Array{Int}(uninitialized, size(A))`, but if `A` has unconventional indexing then the
554
554
indices of the result will match `A`.
555
555
556
- similar(BitArray, (indices (A, 2),))
556
+ similar(BitArray, (axes (A, 2),))
557
557
558
558
would create a 1-dimensional logical array whose indices match those
559
559
of the columns of `A`.
560
560
561
- similar(dims->zeros(Int, dims), indices (A))
561
+ similar(dims->zeros(Int, dims), axes (A))
562
562
563
563
would create an array of `Int`, initialized to zero, matching the
564
564
indices of `A`.
@@ -869,7 +869,7 @@ convert(::Type{Array}, A::AbstractArray{T,N}) where {T,N} = convert(Array{T,N},
869
869
870
870
Represents the array `y` as an array having the same indices type as `x`.
871
871
"""
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)))
873
873
874
874
875
875
# # range conversions ##
@@ -986,11 +986,11 @@ function _to_subscript_indices(A::AbstractArray{T,N}, I::Int...) where {T,N}
986
986
_to_subscript_indices (A, J, Jrem)
987
987
end
988
988
_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)
990
990
function __to_subscript_indices (A:: AbstractArray ,
991
991
:: Tuple{AbstractUnitRange,Vararg{AbstractUnitRange}} , J:: Tuple , Jrem:: Tuple{} )
992
992
@_inline_meta
993
- (J... , map (first, tail (_remaining_size (J, indices (A))))... )
993
+ (J... , map (first, tail (_remaining_size (J, axes (A))))... )
994
994
end
995
995
_to_subscript_indices (A, J:: Tuple , Jrem:: Tuple ) = J # already bounds-checked, safe to drop
996
996
_to_subscript_indices (A:: AbstractArray{T,N} , I:: Vararg{Int,N} ) where {T,N} = I
@@ -1200,7 +1200,7 @@ cat_size(A, d) = 1
1200
1200
cat_size (A:: AbstractArray , d) = size (A, d)
1201
1201
1202
1202
cat_indices (A, d) = OneTo (1 )
1203
- cat_indices (A:: AbstractArray , d) = indices (A, d)
1203
+ cat_indices (A:: AbstractArray , d) = axes (A, d)
1204
1204
1205
1205
cat_similar (A, T, shape) = Array {T} (uninitialized, shape)
1206
1206
cat_similar (A:: AbstractArray , T, shape) = similar (A, T, shape)
@@ -1543,7 +1543,7 @@ end
1543
1543
1544
1544
function isequal (A:: AbstractArray , B:: AbstractArray )
1545
1545
if A === B return true end
1546
- if indices (A) != indices (B)
1546
+ if axes (A) != axes (B)
1547
1547
return false
1548
1548
end
1549
1549
if isa (A,AbstractRange) != isa (B,AbstractRange)
@@ -1566,7 +1566,7 @@ function lexcmp(A::AbstractArray, B::AbstractArray)
1566
1566
end
1567
1567
1568
1568
function (== )(A:: AbstractArray , B:: AbstractArray )
1569
- if indices (A) != indices (B)
1569
+ if axes (A) != axes (B)
1570
1570
return false
1571
1571
end
1572
1572
if isa (A,AbstractRange) != isa (B,AbstractRange)
@@ -1588,7 +1588,7 @@ end
1588
1588
# fallbacks
1589
1589
function sub2ind (A:: AbstractArray , I... )
1590
1590
@_inline_meta
1591
- sub2ind (indices (A), I... )
1591
+ sub2ind (axes (A), I... )
1592
1592
end
1593
1593
1594
1594
"""
@@ -1609,7 +1609,7 @@ julia> ind2sub(A,70)
1609
1609
"""
1610
1610
function ind2sub (A:: AbstractArray , ind)
1611
1611
@_inline_meta
1612
- ind2sub (indices (A), ind)
1612
+ ind2sub (axes (A), ind)
1613
1613
end
1614
1614
1615
1615
# 0-dimensional arrays and indexing with []
@@ -1835,16 +1835,16 @@ function mapslices(f, A::AbstractArray, dims::AbstractVector)
1835
1835
return map (f,A)
1836
1836
end
1837
1837
1838
- dimsA = [indices (A)... ]
1838
+ dimsA = [axes (A)... ]
1839
1839
ndimsA = ndims (A)
1840
1840
alldims = [1 : ndimsA;]
1841
1841
1842
1842
otherdims = setdiff (alldims, dims)
1843
1843
1844
- idx = Any[first (ind) for ind in indices (A)]
1844
+ idx = Any[first (ind) for ind in axes (A)]
1845
1845
itershape = tuple (dimsA[otherdims]. .. )
1846
1846
for d in dims
1847
- idx[d] = Slice (indices (A, d))
1847
+ idx[d] = Slice (axes (A, d))
1848
1848
end
1849
1849
1850
1850
# 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)
1867
1867
if eltype (Rsize) == Int
1868
1868
Rsize[dims] = [size (r1)... , ntuple (d-> 1 , nextra)... ]
1869
1869
else
1870
- Rsize[dims] = [indices (r1)... , ntuple (d-> OneTo (1 ), nextra)... ]
1870
+ Rsize[dims] = [axes (r1)... , ntuple (d-> OneTo (1 ), nextra)... ]
1871
1871
end
1872
1872
R = similar (r1, tuple (Rsize... ,))
1873
1873
1874
- ridx = Any[map (first, indices (R))... ]
1874
+ ridx = Any[map (first, axes (R))... ]
1875
1875
for d in dims
1876
- ridx[d] = indices (R,d)
1876
+ ridx[d] = axes (R,d)
1877
1877
end
1878
1878
1879
1879
R[ridx... ] = r1
0 commit comments