Proposal: Add Diagonal type to mat
Created by: btracey
I think we should add a Diagonal type to mat. If we also add TriBanded, then I think that will be a complete set of types for real-valued matrices in mat.
Diagonal matrices are a pretty core concept, and I think it'll be something users look for. Actually having it there will make it easy. We've also had a bunch of requests for extracting the diagonal of a matrix (and related), and having a Diagonal type is a clear means to do this.
What is special about Diagonal is that it implements both Triangular and Symmetric, which cannot be done by either TriBanded or SymBanded. This makes it difficult when the task is to extract and then use for a specific purpose, as we can't guess in advance which the user wants. A Diagonal type would implement both, and so there is no need to know.
There is one problem, which is that a Diagonal is both upper and lower triangular, and that is impossible to represent in a boolean. We could redefine the type to be Upper/Lower/Both, but this would have a lot of ramifications on the current codebase, and it would be generally uglier and harder to deal with. I think there is a clean solution though. NewDiagDense (and associated constructions) return the Diagonal as an upper triangular matrix, just like the default position for Triangular (such as in Cholesky) is to use an upper triangular matrix. The Transpose method on Diagonal would then swap Upper to Lower (and vis-versa), but otherwise be a no-op. This would make it easy to use a Diagonal as a Triangular matrix that requires a specific orientation, but does not change any of our existing code.