Broadcasting with convert

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


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.

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.

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, if someone doesn’t mind taking a quick look.