You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# checks if the offset may be added to the range without overflowing
139
+
functionoverflow_check(r::AbstractUnitRange{T}, offset::T) where T<:Integer
139
140
# This gives some performance boost https://github.com/JuliaLang/julia/issues/33273
140
-
throw_upper_overflow_error() =throw(OverflowError("Boundary overflow detected: offset should be <= $(typemax(T) -last(r)) for offsets of type $T, received $offset"))
141
-
throw_lower_overflow_error() =throw(OverflowError("Boundary overflow detected: offset should be >= $(typemin(T) -first(r)) for offsets of type $T, received $offset"))
141
+
throw_upper_overflow_error(val) =throw(OverflowError("offset should be <= $(typemax(T) -val) corresponding to the axis $r, received an offset$offset"))
142
+
throw_lower_overflow_error(val) =throw(OverflowError("offset should be >= $(typemin(T) -val) corresponding to the axis $r, received an offset$offset"))
142
143
143
-
if offset >0&&last(r) >typemax(T) - offset
144
+
# With ranges in the picture, first(r) might not necessarily be < last(r)
145
+
# we therefore use the min and max of first(r) and last(r) to check for overflow
# checks if the two offsets may be added together without overflowing
156
+
functionoverflow_check(offset1::T, offset2::T) where {T<:Integer}
157
+
throw_upper_overflow_error() =throw(OverflowError("offset should be <= $(typemax(eltype(offset1)) - offset1) given a pre-existing offset of $offset1, received an offset $offset2"))
158
+
throw_lower_overflow_error() =throw(OverflowError("offset should be >= $(typemin(eltype(offset1)) - offset1) given a pre-existing offset of $offset1, received an offset $offset2"))
159
+
160
+
if offset1 >0&& offset2 >typemax(T) - offset1
144
161
throw_upper_overflow_error()
145
-
elseifoffset<0&&first(r)<typemin(T) -offset
162
+
elseifoffset1<0&&offset2<typemin(T) -offset1
146
163
throw_lower_overflow_error()
147
164
end
165
+
returnnothing
148
166
end
149
167
150
168
# Tuples of integers are treated as offsets
@@ -170,10 +188,16 @@ end
170
188
## OffsetArray constructors
171
189
for FT in (:OffsetArray, :OffsetVector, :OffsetMatrix)
172
190
# Nested OffsetArrays may strip off the wrapper and collate the offsets
0 commit comments