Say I want to use a sliding window of width =
N, such that in the first iteration I would write it as the range
1:N, and the start and stop values of the range would move
j units after the
j-th iteration. My first try would be:
for j=0:m w = j+(1:N) # etc end
But testing against Julia 0.7 this issues the following warning:
Warning: `a::Number + b::AbstractArray` is deprecated, use `broadcast(+, a, b)` instead.
Following that advice is bad for performance (at least in Julia 0.6)
julia> @time 6 + (1:1e7); 0.000016 seconds (6 allocations: 288 bytes) julia> @time 6 .+ (1:1e7); 0.128881 seconds (5.36 k allocations: 76.562 MiB, 2.51% gc time)
So I guess I should do:
for j=0:m w = (j+1):(j+N) # etc end
with the small extra cost of writing
j two times (but perhaps the benefit of clearer code).
Am I right? Or is there some other smarter way to do it? Or is this performance issue not happening in 0.7?