-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
In light of recent discussion, blog post about the (un)reliability of the Julia ecosystem, maybe it's best to simply disable @inbounds but only in that case. Already debugged code for 1-based (what Julia only had once) will thus still work, and be as fast, but OffsetArrays.jl (for now) will be second class (we can follow-up to fix that).
That's basically the request, what follows is discussion if it's actually possible. Taking the example from the docs:
function sum(A::AbstractArray)
r = zero(eltype(A))
for i in eachindex(A)
@inbounds r += A[i]
end
return r
end
I think @inbounds there only "sees" r += A[i] so it's missing the context, that eachindex is used, i.e. in that case no bound checks would be safe. I'm ok with that, it would put pressure on the compiler figuring it out. Had 1:length(A) been used instead the code would have been wrong, but only for non-1-based. Would the code have been better with the macro at @inbounds for and then it could be disabled in fewer cases?
Does the macro see the type of A? I'm not sure it does, but even if not, I think it could generate code that does see the type, and can handle it conditionally, so shouldn't be a problem.