-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentation
Description
It appears that the example use of @inbounds
given in the documentation for @inbounds
is not a safe use of @inbounds
:
The paragraph above the example implies that it is meant as an example to be followed, not one to be avoided. However, the warning immediately below the example strongly recommends only using @inbounds
when it is certain from the information locally available that all accesses are in bounds.
This is not the case in the example, whose method signature explicitly allows all AbstractArray
s, including those which do not use one-based indexing.
I verified that the example silently produces incorrect results due to out-of-bounds memory access on Julia 1.5.3:
julia> function sum(A::AbstractArray)
r = zero(eltype(A))
for i = 1:length(A)
@inbounds r += A[i]
end
return r
end
sum (generic function with 1 method)
julia> using OffsetArrays
julia> sum(OffsetArray(collect(1:11), -5:5))
8858289599
JeffBezanson and tavasolireza
Metadata
Metadata
Assignees
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentation