You can add ``@inbounds`` macro here (and some other places below). This meets the criteria of using this macro: in a tight inner loop and the indexes are proved to be in bounds.