JuliaSIMD / JuliaSIMD/LoopVectorization.jl

Nested loop UndefVarError

Abierto
#321 3 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Julia
Estrellas
789
Forks
73
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.