# Evaluating @view macro before @tturbo

**URL:** <https://discourse.julialang.org/t/evaluating-view-macro-before-tturbo/75320>\
**Category:** Performance\
**Tags:** macros, loopvectorization, views\
**Created:** [January 27, 2022, 8:20pm UTC](https://discourse.julialang.org/t/evaluating-view-macro-before-tturbo/75320 "2022-01-27T20:20:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chiil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chiil/32/27474_2.png) [@Chiil](https://discourse.julialang.org/u/Chiil)\
**Post date:** [January 27, 2022, 8:20pm UTC](https://discourse.julialang.org/t/evaluating-view-macro-before-tturbo/75320/1 "2022-01-27T20:20:25Z")

</div>

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.

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [January 27, 2022, 11:54pm UTC](https://discourse.julialang.org/t/evaluating-view-macro-before-tturbo/75320/2 "2022-01-27T23:54:04Z")

</div>

It looks to me like `Loopvectorization` works better when writting out the loops.

Try :

```julia
@tturbo for i in 1:10, j in 1:10, k in 1:10
    b[i,j,k] = a[i,j,k]
end

```

of course, inside a function. Furthermore, always look at `@code_warntype` and `benchmarkTool.@btime` when you are doing these kinds of transformations.
