I’m having trouble trying to use LoopVectorization.@turbo
—it gives an ERROR: UndefVarError: i1 not defined
.
I suspect that the issue stem from the “strange” format of the weights
and indices
inputs. (The reason for the strange format is that I don’t know the length of vectors in A
.)
Can I rewrite test1
so that @turbo
works here?
using LoopVectorization
function test1(A)
n1, n2 = size(A)
n3 = 100
# Generate nonsense inputs
weights = Matrix{Vector{NTuple{2, Float64}}}(
undef,
n1,
n2,
)
indices = Matrix{Vector{Int}}(
undef,
n1,
n2,
)
nA = length(A[1])
for ix in eachindex(weights)
weights[ix] = Vector{NTuple{2, Float64}}(undef, n3)
for i3 in eachindex(weights[ix])
weights[ix][i3] = (rand(2)...,)
weights[ix][i3] = weights[ix][i3] ./ sum(weights[ix][i3])
end
indices[ix] = sort(rand(1:nA - 1, n3))
end
# Computation
B = zeros(n1, n2, n3)
@turbo for i3 in 1:n3
for i2 in 1:n2
for i1 in 1:n1
for i4 in 0:1
B[i1, i2, i3] += weights[i1, i2][i3][1 + i4] * A[i1, i2][indices[i1, i2][i3] + i4]
end
end
end
end
return B
end
n1 = 3
n2 = 7
A = Matrix{Vector{Float64}}(
undef,
n1,
n2,
)
for ix in eachindex(A)
A[ix] = sort(rand(60));
end
test1(A)