Some clarification on `@inbounds`

I know that @inbounds can be applied before a statement like

x[i] = y

and it will elide the bounds check for the setindex! call on x. I’m a little confused about where else @inbounds can be applied, though. If I write

@inbounds for i = 1:n
    x[i] = i^2
    y[i] = exp(x[i])
    z[i] = 1/y[i]

does this elide all of the bounds checks in the loop?

Yes, all bounds checks in the loop block will be elided.

Also, I think you mean setindex! :slight_smile:

1 Like

does this also apply to nested loops?