Why is `transpose` recursive?

My understanding is that since very early on, this has been defined to allow for a very simple definition of matrices in block form.

E.g. it is relatively common in linear algebra to express given matrices A, B, C, D of compatible sizes,

M = [A B;
     C D]

Now we can define things like M' * M and get the expected results, where

M' == [A' C';
       B' D']

On the other hand, I’m not sure this functionality has been fully followed through on in Base. For example, an extremely obvious use case is block-diagonal matrices using Diagonal, but transpose(::Diagonal) is not recursive!

I was actually hoping we could clear this up sometime in the next release cycle - do we want to more fully support block-diagonal matrices using nested arrays? Or is it, upon hindsight, better to rely on specific wrapper types (might be BlockArray, BlockMatrix, BlockVector) which present a “flattened” view of the matrix for which recursion is implied (and remove recursion from the standard definition)?

3 Likes