June 2019
Intermediate to advanced
218 pages
5h 19m
English
However, as with any extra operation, bound checking has costs too. There are extra operations for all array reads and writes. While this cost is reasonably small and it is usually a good trade-off for safety, in some situations where it can be guaranteed that the array bounds are never crossed, it may be worthwhile to remove these checks. This is possible in Julia using the @inbounds macro as follows:
function prefix_bounds(a, b) for i in 2:size(a, 1) a[i] = b[i-1] + b[i] end end function prefix_inbounds(a, b) @inbounds for i in 2:size(a, 1) a[i] = b[i-1] + b[i] end end
The @inbounds macro can be applied in front of a function or loop definition. Once this is done, all bound checking is disabled ...
Read now
Unlock full access