JuliaSIMD / JuliaSIMD/LoopVectorization.jl

Nested loop UndefVarError

Aperta
#321 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Julia
Stelle
789
Fork
73
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.