@@ -35,23 +35,32 @@ function Broadcast.instantiate(bc::Broadcasted{StructStaticArrayStyle{M}}) where
3535 bc′ = Broadcast. instantiate (replace_structarray (bc))
3636 return convert (Broadcasted{StructStaticArrayStyle{M}}, bc′)
3737end
38- # This looks costy , but compiler should be able to optimize them away
38+ # This looks costly , but the compiler should be able to optimize them away
3939Broadcast. _axes (bc:: Broadcasted{<:StructStaticArrayStyle} , :: Nothing ) = axes (replace_structarray (bc))
4040
4141to_staticstyle (@nospecialize (x:: Type )) = x
4242to_staticstyle (:: Type{StructStaticArrayStyle{N}} ) where {N} = StaticArrayStyle{N}
43+
44+ """
45+ replace_structarray(bc::Broadcasted)
46+
47+ An internal function transforms the `Broadcasted` with `StructArray` into
48+ an equivalent one without it. This is not a must if the root `BroadcastStyle`
49+ supports `AbstractArray`. But some `BroadcastStyle` limits the input array types,
50+ e.g. `StaticArrayStyle`, thus we have to omit all `StructArray`.
51+ """
4352function replace_structarray (bc:: Broadcasted{Style} ) where {Style}
4453 args = replace_structarray_args (bc. args)
4554 return Broadcasted {to_staticstyle(Style)} (bc. f, args, nothing )
4655end
4756function replace_structarray (A:: StructArray )
48- f = createinstance (eltype (A))
57+ f = Instantiator (eltype (A))
4958 args = Tuple (components (A))
5059 return Broadcasted {StaticArrayStyle{ndims(A)}} (f, args, nothing )
5160end
5261replace_structarray (@nospecialize (A)) = A
5362
54- replace_structarray_args (args:: Tuple ) = (replace_structarray (args[1 ]), replace_structarray_args (Base . tail (args))... )
63+ replace_structarray_args (args:: Tuple ) = (replace_structarray (args[1 ]), replace_structarray_args (tail (args))... )
5564replace_structarray_args (:: Tuple{} ) = ()
5665
5766# StaticArrayStyle has no similar defined.
0 commit comments