Why is `transpose` recursive?

At least reshape(vec,(1,:)) is possible now, which helps.

Since the issue is entirely that people want something that comes close to the conciseness of ', would it make sense to have a convenience function that exclusively swaps the first two dimensions? flip(vec)?

Like I said, I feel one problem with ' was that it was a reversible toggle. You can’t tell the shape of the output without knowing the shape of the input. If you get too many of these, and you’re reading code you’re not intimately familiar with, it is hard to grasp what is going on. flip would be the same.

But now in Julia we have vectors, row vectors, column matrices and row matrices, and there is probably a situation where you might want to “cast” something to any of those shapes…

1 Like

I agree with @StefanKarpinski here. There are many custom types that you can create, which behave like a ring or field, but which you do not necessarily want to make a subtype of Number. So it makes sense to build matrices with this element type, without having to define transpose as an identity operation this type in itself. I don’t think there is any mathematical motivation for making transpose act recursively. Block matrices are the only exception, but that’s only after the programmer made a ambiguous mathematical interpretation for a data structure which could also represent other mathematical structures. As such, a specific type for block matrices would indeed serve this purpose better.

11 Likes

For those interested in this subject, it might be worth noting “Taking matrix transposes seriously” at https://github.com/JuliaLang/julia/issues/20978.

1 Like