Customizing Broadcasting Recursively for Collections of Arrays

Extending upon your previous solution, you’ll need to now implement broadcasting for your style. You do this by implementing copyto!(dest::A, bc::Broadcast.Broadcasted{MyStyle}). There are two challenges here:

  1. Implementing that method isn’t easy. You need to support any arbitrary combinations of fused expressions and do the indexing computations yourself — you can make this a bit easier (at the sacrifice of a bit of performance) by using Broadcast.flatten, which transforms the nested expression tree into a single function and a flat list of arguments. It’s still hard and annoying.

  2. Perhaps more importantly, you’re at the edge of (or possibly beyond) supported broadcasting use-cases. Broadcast is defined as doing an element-wise computation, but what is an “element” of A? See Broadcasting in 0.7 and https://github.com/JuliaLang/julia/issues/27988#issuecomment-403319535 for more details.

1 Like