JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Nested loop UndefVarError
- Dominant language
- Julia
- Stars
- 789
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Hey, thanks for the great library!
I'm not sure if this is a bug, but the following code doesn't work for me for no obvious reason:
```julia
function logmean(samples, weights)
logμ = zero(first(samples))
n = length(samples)
k = length(logμ)
@turbo for i in 1:n
for j in 1:k
logμ[j] = logμ[j] + weights[i] * log(samples[i][j])
end
end
return logμ
end
```
```julia
logmean([ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ], [ 0.5, 0.5 ])
UndefVarError: i not defined
Stacktrace:
[1] logmean(samples::Vector{Vector{Float64}}, weights::Vector{Float64})
@ Main ./In[15]:5
[2] top-level scope
@ In[16]:1
[3] eval
@ ./boot.jl:360 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1116
```
The following version works like a charm:
```julia
function logmean(samples, weights)
logμ = zero(first(samples))
n = length(samples)
k = length(logμ)
for i in 1:n
@turbo for j in 1:k
logμ[j] = logμ[j] + weights[i] * log(samples[i][j])
end
end
return logμ
end
```
I thought `LoopVectorization.jl` should be able to handle nested loops? Or are there some special requirements for that?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.