# Odd behavior with mul!() and @view

**URL:** <https://discourse.julialang.org/t/odd-behavior-with-mul-and-view/108606>\
**Category:** General Usage\
**Created:** [January 10, 2024, 4:55am UTC](https://discourse.julialang.org/t/odd-behavior-with-mul-and-view/108606 "2024-01-10T04:55:50Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [January 10, 2024, 5:02am UTC](https://discourse.julialang.org/t/odd-behavior-with-mul-and-view/108606/2 "2024-01-10T05:02:53Z")

</div>

Method 1 lowers to `getindex` i.e. makes another slice. Method 2 lowers to `setindex!`

```julia
julia> Meta.@lower mul!(out2[:,1], A, b)
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ %1 = Base.getindex(out2, :, 1)
│ %2 = A
│ %3 = mul!(%1, %2, b)
└── return %3
))))

julia> Meta.@lower out2[:,1] = A*b
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ %1 = A * b
│ Base.setindex!(out2, %1, :, 1)
└── return %1
))))

```

what is the motivation for using `mul!` specifically rather than `*` ? also I think if you use another `view` this will work as intended

```julia
# equivalently, mul!(view(out2, :, 1), A, b)
julia> @views mul!(out2[:,1], A, b)
10-element view(::Matrix{Float64}, :, 3) with eltype Float64:
 10.0
 10.0
 10.0
 10.0
 10.0
 10.0
 10.0
 10.0
 10.0
 10.0

```

---

_[View the full topic](https://discourse.julialang.org/t/odd-behavior-with-mul-and-view/108606)._
