I am revising a piece of code where I am removing unnecessary copies by creating views. At places where I have @tturbo decorators, I get errors because LoopVectorization does not like the @view. Is it possible to make the preferred solution work by first expanding the @view and then @tturbo? I added working solutions that either come with an additional line, or writing view
as a function that would make it inconsistent with the rest of my code.
using LoopVectorization
a = rand(128, 128, 128)
b = similar(a)
# original with unnecessary copy
b[10:20, 10:20, 10:20] .= a[10:20, 10:20, 10:20]
# preferred solution
# @tturbo b[10:20, 10:20, 10:20] .= @view a[10:20, 10:20, 10:20]
# two line fix
av = @view a[10:20, 10:20, 10:20]
@tturbo b[10:20, 10:20, 10:20] .= av
# one line fix
@tturbo b[10:20, 10:20, 10:20] .= view(a, 10:20, 10:20, 10:20)