# Surprising type result with @

**URL:** <https://discourse.julialang.org/t/surprising-type-result-with/112012>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 23, 2024, 9:20am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012 "2024-03-23T09:20:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CM1](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@CM1](https://discourse.julialang.org/u/CM1)\
**Post date:** [March 23, 2024, 9:20am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012/1 "2024-03-23T09:20:55Z")

</div>

Hi everyone,

I am quite confused about the resulting types in below snippet:

```julia
N = 5
T = Float32

# edit, forgot to mention these variables
μ = rand(T, N_states, 1)
σ = rand(T, N_states, 1)

E₀ = fill(T(0.5), N, 1) # 5×1 Matrix{Float32}
U₀_1 = @. ((1 - μ) * σ) * E₀ # 5×1 Matrix{Float32}
U₀_2 = @. (1 - μ) * σ * fill(T(0.5), N, 1) # 5×1 Matrix{Matrix{Float32}}

```

Can someone please explain why `U₀_2` has a different type than `U₀_1`, despite `typeof(fill(T(0.5), N_states, 1))` being equal to `typeof(E₀)`?

---

<div class="post-metadata">

**Author:** ![artemsolod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/artemsolod/32/20704_2.png) [@artemsolod](https://discourse.julialang.org/u/artemsolod)\
**Post date:** [March 23, 2024, 9:32am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012/2 "2024-03-23T09:32:42Z")

</div>

I can’t reproduce on julia `1.10.2` but I guess this is because `@.` applies to `fill` as well. Can you try `U₀_2 = fill(T(0.5), N, 1) .* (@. (1 - μ) * σ)`?

---

<div class="post-metadata">

**Author:** ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Post date:** [March 23, 2024, 10:16am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012/3 "2024-03-23T10:16:19Z")

</div>

What is `μ` and `σ`? And which version of julia are you running?

---

<div class="post-metadata">

**Author:** ![CM1](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@CM1](https://discourse.julialang.org/u/CM1)\
**Post date:** [March 23, 2024, 10:23am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012/4 "2024-03-23T10:23:45Z")

</div>

@sgaure Oops, my bad, I added the variables to the MWE  
@artemsolod It seems you are correct, your variant works on Julia 1.9.3, too

Thanks for the answers!

---

<div class="post-metadata">

**Author:** ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Post date:** [March 23, 2024, 10:30am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012/5 "2024-03-23T10:30:54Z")

</div>

Yes, it’s the difference between

```julia
julia> ((1 .- μ) .* σ) .* fill(T(0.5), N, 1)
5×1 Matrix{Float32}:

```

and

```julia
julia> ((1 .- μ) .* σ) .* fill.(T(0.5), N, 1)
5×1 Matrix{Matrix{Float32}}:

```

where the broadcasts are fused, and the `fill` broadcast computes `fill(T(0.5),N,1)` every time. I agree it’s a bit unexpected.

---

<div class="post-metadata">

**Author:** ![artemsolod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/artemsolod/32/20704_2.png) [@artemsolod](https://discourse.julialang.org/u/artemsolod)\
**Post date:** [March 23, 2024, 11:18am UTC](https://discourse.julialang.org/t/surprising-type-result-with/112012/6 "2024-03-23T11:18:36Z")

</div>

It appears broadcast can be escaped with `$`:

```julia
julia> @. fill(1., (1,2))
([1.0], [1.0, 1.0])

julia> @. $fill(1., (1,2))
1×2 Matrix{Float64}:
 1.0 1.0

```

Great post: [Broadcasting in Julia: the Good, the Bad, and the Ugly | Blog by Bogumił Kamiński](https://bkamins.github.io/julialang/2022/06/24/broadcasting.html)
