Wed 07 Oct 2015 04:03:31 PM UTC, comment #1:
I think there is a difference in goals between what you are proposing and what Octave is trying to do. The diagonal class in Octave is intended to be merely a memory-efficient way of handling certain specific matrices. Matlab does not implement this so there is no API to match. Instead, the "match" is to the behavior of regular full matrices. Users shouldn't need to know that there is anything different happening.
That is one reason why issparse (diag (...)) returns false. Because a diagonal matrix has different "rules" than a sparse matrix and it will automatically convert to a full matrix whenever it needs to. Thus,
In the diagonal matrix, the zeros really are zeros just like a full matrix and so cos (0) == 1.
I don't see anything wrong in trying to accomodate the mathematician's view of diagonal matrices as a closed set where possible, although the first principle will still be to behave like a full matrix when necessary.
I think the best course of action is to continue to identify places where Octave can be upgraded without impacting the Matlab-compatible behavior.
For permute/ipermute, Octave returns a full matrix because it doesn't know in advance whether you are permuting just rows/columns or perhaps introducing a third or fourth dimension.
For example,
It seems that one could write a special case in do_permute() in libinterp/corefcn/data.cc to check whether the input was a diagonal matrix, and that the permute vector had only two elements, and that the elements were either [1 2] or [2 1]. If all that was true then one could just return the original diagonal matrix.
The do_permute code is shown below:
|