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
141
throw_upper_overflow_error(val) =throw(OverflowError("offset should be <= $(typemax(T) - val) corresponding to the axis $r, received an offset $offset"))
141
142
throw_lower_overflow_error(val) =throw(OverflowError("offset should be >= $(typemin(T) - val) corresponding to the axis $r, received an offset $offset"))
@@ -149,6 +150,19 @@ function overflow_check(r, offset::T) where T
# 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
161
+
throw_upper_overflow_error()
162
+
elseif offset1 <0&& offset2 <typemin(T) - offset1
163
+
throw_lower_overflow_error()
164
+
end
165
+
returnnothing
152
166
end
153
167
154
168
# Tuples of integers are treated as offsets
@@ -177,7 +191,8 @@ for FT in (:OffsetArray, :OffsetVector, :OffsetMatrix)
0 commit comments