LoopVectorization.jl icon indicating copy to clipboard operation
LoopVectorization.jl copied to clipboard

For loops with the syntax for i in iter

Open gbaraldi opened this issue 4 years ago • 1 comments
trafficstars

For loops with the syntax for i in iter dont work even with a simple iterator like a Vector. MWE

using LoopVectorization

test = rand(10000)
function mymean(func,iter)
    len = length(iter)
    total = zero(eltype(iter))
    @avx for i in iter
        total += func(i)
    end
    total/len
end

mymean(identity,test)

This gives this error:

ERROR: LoadError: MethodError: no method matching canonicalize_range(::Vector{Float64})

gbaraldi avatar Mar 31 '21 03:03 gbaraldi

I'll probably hold off on this until the triangular loops update, which is probably at least several months away. But if anyone else would like to take a stab at it, I'd be happy to explain how to do it and answer any questions.

The approach would basically be to notice that the type of iter isn't a range, and replace it with eachindex(iter), and then substitute uses of i with iter[i].

chriselrod avatar Apr 05 '21 09:04 chriselrod