I am trying to provide @inbounds
functionality for a custom type.
After reading the docs, I have experimented with various combinations of checkbounds
with @inline
and @propagate_inbounds
. But still I can’t seem to get it to work, and I have a feeling I’m doing something quite stupid.
Why in the example below, doesn’t @inbounds A[2]
work as expected?
(It returns nothing
)
# Julia v0.6.0
struct MyType end
#Base.checkbounds(A::MyType, i::Integer) = println("checking bounds ...")
Base.checkbounds(A::MyType, i::Integer) = i < 0 && throw(BoundsError(A, i))
@inline function Base.getindex(A::MyType, i::Integer)
@boundscheck checkbounds(A, i)
return 17
end
A = MyType()
A[2]
@inbounds A[2]