While implementing #105 the issue of map vs broadcast for FSA operations came up. The FSA map already does some broadcast with scalars, and we should probably be extending it into a full broadcast implementation for consistency with Array. I didn't want to start on broadcast and further delay fixing a lot of bugs, so here's a new issue for it. To copy the summary from https://github.com/SimonDanisch/FixedSizeArrays.jl/pull/105#issuecomment-220810574:
Deducing the output type is the major problem with implementing broadcast if we want to allow mixing FixedArray with AbstractArray in a nice way.
For broadcast(), mixing the two must result in a normal Array, since the output size will only be known at runtime so we can't know the output FSA type. (The output size of a broadcast may also be really large in which case using an FSA would be pretty terrible anyway.)
Say you want to broadcast .+. There's only really one set of rules which makes sense:
For map() it's natural to assume that mixing the two should result in a FixedArray, because you've already got a fixed array of the same size, and you can have the following set of rules:
So it's a sticky situation. On the one hand, we should follow the usual broadcast semantics from AbstractArray. On the other hand, these play havoc with the ability to make FixedArray and AbstractArray interoperate efficiently, with a minimum of intrusive syntax.
While implementing #105 the issue of
map
vsbroadcast
for FSA operations came up. The FSA map already does some broadcast with scalars, and we should probably be extending it into a full broadcast implementation for consistency withArray
. I didn't want to start on broadcast and further delay fixing a lot of bugs, so here's a new issue for it. To copy the summary from https://github.com/SimonDanisch/FixedSizeArrays.jl/pull/105#issuecomment-220810574:Deducing the output type is the major problem with implementing broadcast if we want to allow mixing
FixedArray
withAbstractArray
in a nice way.For
broadcast()
, mixing the two must result in a normal Array, since the output size will only be known at runtime so we can't know the output FSA type. (The output size of a broadcast may also be really large in which case using an FSA would be pretty terrible anyway.)Say you want to broadcast
.+
. There's only really one set of rules which makes sense:For
map()
it's natural to assume that mixing the two should result in aFixedArray
, because you've already got a fixed array of the same size, and you can have the following set of rules:So it's a sticky situation. On the one hand, we should follow the usual broadcast semantics from
AbstractArray
. On the other hand, these play havoc with the ability to makeFixedArray
andAbstractArray
interoperate efficiently, with a minimum of intrusive syntax.