# Broadcasting with convert

**URL:** <https://discourse.julialang.org/t/broadcasting-with-convert/56619>\
**Category:** General Usage\
**Tags:** broadcast\
**Created:** [March 6, 2021, 1:54pm UTC](https://discourse.julialang.org/t/broadcasting-with-convert/56619 "2021-03-06T13:54:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgroenks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bgroenks/32/21784_2.png) [@bgroenks](https://discourse.julialang.org/u/bgroenks)\
**Post date:** [March 6, 2021, 1:54pm UTC](https://discourse.julialang.org/t/broadcasting-with-convert/56619/1 "2021-03-06T13:54:57Z")

</div>

Would someone be able to explain to me briefly the mechanics of what should happen when you call

```julia
convert.(T,a)

```

on an array `a`?

I would think that `Base.similar(bc::Broadcasted{DestStyle}, ::Type{ElType})` would get called to allocate the output container, but this doesn’t seem to be the case.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 6, 2021, 3:28pm UTC](https://discourse.julialang.org/t/broadcasting-with-convert/56619/2 "2021-03-06T15:28:24Z")

</div>

Assuming you have an `a` that uses the default implementation, it’ll only use `copyto!(similar(...), ...)` if the broadcast kernel is type stable. Otherwise, it’ll use incremental widening. It sounds like you’ve started customizing broadcast, though, in which case all bets are off.

---

<div class="post-metadata">

**Author:** ![bgroenks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bgroenks/32/21784_2.png) [@bgroenks](https://discourse.julialang.org/u/bgroenks)\
**Post date:** [March 6, 2021, 4:40pm UTC](https://discourse.julialang.org/t/broadcasting-with-convert/56619/3 "2021-03-06T16:40:49Z")

</div>

Well I’m playing around with `DEDataArray` which overrides some broadcast functions. But what I want is to be able to add my own custom code for `similar(a, Type{S})` that converts the data types of the other fields as well, not just the array elements.

I’m just confused that it doesn’t seem to call any of the overloads of `similar`. I don’t see how that’s possible.

The array method overrides for `DEDataArray` can be found [here](https://github.com/SciML/DiffEqBase.jl/blob/70498fbd9808b38678af0d941e536f87ee375a46/src/data_array.jl), if someone doesn’t mind taking a quick look.
