Description
The correct general behavior for zero
and one
is to construct a StaticArrays type which can represent the additive and multiplicative identities. Currently this doesn't always work for the reasons described in JuliaLang/julia#763: for example, zero(Rotations.RotMatrix)
should not return a RotMatrix
.
One fix would be to make operations always call similar_type
and refine the documentation for similar_type
to specify that it should return the type of a "general full matrix". "Full" for the purposes of array ops like broadcasting which don't preserve "structural zeros", and full for algebraic purposes because we need a member of GL(n,R) as generic output. This seems consistent(ish?) with similar
in Base. Note that changing to use similar_type
like this is slightly breaking and led to JuliaLang/julia#700, so this will technically be a breaking change. However we need to do something like this for correctness so we should do it in the next major release. Generally I don't think it will be very breaking...
Perhaps there's some more general option where similar_type
can somehow be aware of the algebraic operation... eg, for multiply to call similar_type(m, *, sz, ty)
... but I'm not sure that would be any better than simply overriding *
.