@@ -53,9 +53,12 @@ Base.eachindex(::LinearFast, A::OffsetVector) = indices(A, 1)
53
53
# Implementations of indices and indices1. Since bounds-checking is
54
54
# performance-critical and relies on indices, these are usually worth
55
55
# optimizing thoroughly.
56
- @inline Base. indices (A:: OffsetArray , d) = 1 <= d <= length (A. offsets) ? indices (parent (A))[d] + A. offsets[d] : (1 : 1 )
57
- @inline Base. indices (A:: OffsetArray ) = _indices (indices (parent (A)), A. offsets) # would rather use ntuple, but see #15276
58
- @inline _indices (inds, offsets) = (inds[1 ]+ offsets[1 ], _indices (tail (inds), tail (offsets))... )
56
+ @inline Base. indices (A:: OffsetArray , d) =
57
+ 1 <= d <= length (A. offsets) ? indices (parent (A))[d] + A. offsets[d] : (1 : 1 )
58
+ @inline Base. indices (A:: OffsetArray ) =
59
+ _indices (indices (parent (A)), A. offsets) # would rather use ntuple, but see #15276
60
+ @inline _indices (inds, offsets) =
61
+ (inds[1 ]+ offsets[1 ], _indices (tail (inds), tail (offsets))... )
59
62
_indices (:: Tuple{} , :: Tuple{} ) = ()
60
63
Base. indices1 {T} (A:: OffsetArray{T,0} ) = 1 : 1 # we only need to specialize this one
61
64
@@ -67,11 +70,14 @@ function Base.similar{T}(A::AbstractArray, ::Type{T}, inds::Tuple{UnitRange,Vara
67
70
OffsetArray (B, map (indexoffset, inds))
68
71
end
69
72
70
- Base. similar (f:: Union{Function,Type} , shape:: Tuple{UnitRange,Vararg{UnitRange}} ) = OffsetArray (f (map (length, shape)), map (indexoffset, shape))
73
+ Base. similar (f:: Union{Function,Type} , shape:: Tuple{UnitRange,Vararg{UnitRange}} ) =
74
+ OffsetArray (f (map (length, shape)), map (indexoffset, shape))
71
75
72
- Base. reshape (A:: AbstractArray , inds:: Tuple{UnitRange,Vararg{UnitRange}} ) = OffsetArray (reshape (A, map (length, inds)), map (indexoffset, inds))
76
+ Base. reshape (A:: AbstractArray , inds:: Tuple{UnitRange,Vararg{UnitRange}} ) =
77
+ OffsetArray (reshape (A, map (length, inds)), map (indexoffset, inds))
73
78
74
- Base. reshape (A:: OffsetArray , inds:: Tuple{UnitRange,Vararg{UnitRange}} ) = OffsetArray (reshape (parent (A), map (length, inds)), map (indexoffset, inds))
79
+ Base. reshape (A:: OffsetArray , inds:: Tuple{UnitRange,Vararg{UnitRange}} ) =
80
+ OffsetArray (reshape (parent (A), map (length, inds)), map (indexoffset, inds))
75
81
76
82
function Base. reshape (A:: OffsetArray , inds:: Tuple{UnitRange,Vararg{Union{UnitRange,Int,Base.OneTo}}} )
77
83
throw (ArgumentError (" reshape must supply UnitRange indices, got $(typeof (inds)) .\n Note that reshape(A, Val{N}) is not supported for OffsetArrays." ))
@@ -111,18 +117,21 @@ end
111
117
112
118
# ## Convenience functions ###
113
119
114
- Base. fill (x, inds:: Tuple{UnitRange,Vararg{UnitRange}} ) = fill! (OffsetArray {typeof(x)} (inds), x)
120
+ Base. fill (x, inds:: Tuple{UnitRange,Vararg{UnitRange}} ) =
121
+ fill! (OffsetArray {typeof(x)} (inds), x)
115
122
@inline Base. fill (x, ind1:: UnitRange , inds:: UnitRange... ) = fill (x, (ind1, inds... ))
116
123
117
124
# ## Low-level utilities ###
118
125
119
126
# Computing a shifted index (subtracting the offset)
120
127
offset {N} (offsets:: NTuple{N,Int} , inds:: NTuple{N,Int} ) = _offset ((), offsets, inds)
121
128
_offset (out, :: Tuple{} , :: Tuple{} ) = out
122
- @inline _offset (out, offsets, inds) = _offset ((out... , inds[1 ]- offsets[1 ]), Base. tail (offsets), Base. tail (inds))
129
+ @inline _offset (out, offsets, inds) =
130
+ _offset ((out... , inds[1 ]- offsets[1 ]), Base. tail (offsets), Base. tail (inds))
123
131
124
132
# Support trailing 1s
125
- @inline offset (offsets:: Tuple{Vararg{Int}} , inds:: Tuple{Vararg{Int}} ) = (offset (offsets, Base. front (inds))... , inds[end ])
133
+ @inline offset (offsets:: Tuple{Vararg{Int}} , inds:: Tuple{Vararg{Int}} ) =
134
+ (offset (offsets, Base. front (inds))... , inds[end ])
126
135
offset (offsets:: Tuple{} , inds:: Tuple{} ) = ()
127
136
offset (offsets:: Tuple{Vararg{Int}} , inds:: Tuple{} ) = error (" inds cannot be shorter than offsets" )
128
137
0 commit comments