New array from a sum of N values in array A?

rolling sum or moving sum?

See Rolling Sum

I think Tullio has an interesting solution

A = rand(100_000_000);

using Tullio

N = 3
res = zeros(eltype(A), length(A))

using Tullio
@time @tullio res[j] = A[j] + A[j+1] + A[j+2]
@time @tullio res[j] = A[j] + A[j+1] + A[j+2] # 0.2s
1 Like