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

Errors with certain simple for loop

Open junyuan-chen opened this issue 2 years ago • 2 comments

Depending on how the index ranges are specified, there are a few cases in which I get unexpected errors.

For example, I am getting errors on something like this:

using LoopVectorization
a = zeros(3,2)
N = 2
@turbo thread=true for i in 1:1, j in 1:N
    a[i,j] += 1.0
end
ERROR: MethodError: no method matching vmul_nw(::Int64)

The following also errors:

v = zeros(3)
N1 = 1
N2 = 3
@turbo thread=true for i in 1:N2, j in 1:N1
    v[i,j] += 1.0
end
ERROR: BoundsError: attempt to access 1-element Vector{Any} at index [2]

junyuan-chen avatar Apr 05 '23 19:04 junyuan-chen

The second case is tricker. The ideal behavior is that LV would figure out that N1 has to be <=1, and throw an error otherwise. Currently, throwing some error always probably isn't so bad.

I fixed the first case, and added it to the tests: https://github.com/JuliaSIMD/LoopVectorization.jl/commit/ded74ba4229c5bdb286057204aa50a8c8895f472

chriselrod avatar Apr 05 '23 20:04 chriselrod

@chriselrod Thank you so much for the fast response.

junyuan-chen avatar Apr 05 '23 20:04 junyuan-chen