Skip to content

Commit 6d19a9e

Browse files
committed
Wrap some long lines
1 parent 684b05a commit 6d19a9e

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/OffsetArrays.jl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ Base.eachindex(::LinearFast, A::OffsetVector) = indices(A, 1)
5353
# Implementations of indices and indices1. Since bounds-checking is
5454
# performance-critical and relies on indices, these are usually worth
5555
# 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))...)
5962
_indices(::Tuple{}, ::Tuple{}) = ()
6063
Base.indices1{T}(A::OffsetArray{T,0}) = 1:1 # we only need to specialize this one
6164

@@ -67,11 +70,14 @@ function Base.similar{T}(A::AbstractArray, ::Type{T}, inds::Tuple{UnitRange,Vara
6770
OffsetArray(B, map(indexoffset, inds))
6871
end
6972

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))
7175

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))
7378

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))
7581

7682
function Base.reshape(A::OffsetArray, inds::Tuple{UnitRange,Vararg{Union{UnitRange,Int,Base.OneTo}}})
7783
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
111117

112118
### Convenience functions ###
113119

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)
115122
@inline Base.fill(x, ind1::UnitRange, inds::UnitRange...) = fill(x, (ind1, inds...))
116123

117124
### Low-level utilities ###
118125

119126
# Computing a shifted index (subtracting the offset)
120127
offset{N}(offsets::NTuple{N,Int}, inds::NTuple{N,Int}) = _offset((), offsets, inds)
121128
_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))
123131

124132
# 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])
126135
offset(offsets::Tuple{}, inds::Tuple{}) = ()
127136
offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{}) = error("inds cannot be shorter than offsets")
128137

0 commit comments

Comments
 (0)