# Collecting Base.Broadcast.Broadcasted

**URL:** <https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933>\
**Category:** Performance\
**Tags:** broadcast, broadcasting\
**Created:** [April 26, 2023, 7:48am UTC](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933 "2023-04-26T07:48:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [April 26, 2023, 7:48am UTC](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933/1 "2023-04-26T07:48:08Z")

</div>

when overloading `broadcasted()` one may sometimes want to call `collect`. However, this seems to not remember the size:

```julia
julia> a = reshape(1:100,(10,10))
10×10 reshape(::UnitRange{Int64}, 10, 10) with eltype Int64:
  1 11 21 31 41 51 61 71 81 91
  2 12 22 32 42 52 62 72 82 92
  3 13 23 33 43 53 63 73 83 93
  4 14 24 34 44 54 64 74 84 94
  5 15 25 35 45 55 65 75 85 95
  6 16 26 36 46 56 66 76 86 96
  7 17 27 37 47 57 67 77 87 97
  8 18 28 38 48 58 68 78 88 98
  9 19 29 39 49 59 69 79 89 99
 10 20 30 40 50 60 70 80 90 100

julia> b = Base.Broadcast.Broadcasted(+, (a, 100))
Base.Broadcast.Broadcasted(+, ([1 11 … 81 91; 2 12 … 82 92; … ; 9 19 … 89 99; 10 20 … 90 100], 100))

julia> size(b)
(10, 10)

julia> size(collect(b))
(100,)

```

Does one need to always use `reshape(collect, size(b))` or is there a better way?

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [April 26, 2023, 9:56am UTC](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933/2 "2023-04-26T09:56:20Z")

</div>

Note that the shape is preserved in this example in Julia 1.9.

---

<div class="post-metadata">

**Author:** ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Post date:** [April 26, 2023, 9:59am UTC](https://discourse.julialang.org/t/collecting-base-broadcast-broadcasted/97933/3 "2023-04-26T09:59:51Z")

</div>

Ah. I see.
