octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

diag() boundary case


From: Rik
Subject: diag() boundary case
Date: Tue, 29 Mar 2011 12:09:33 -0700

3/29/11

There is a bug open regarding the behavior of diag when the input vector
has a null dimension (https://savannah.gnu.org/bugs/?32901).  From the
documentation it seems that diag(x) should build a diagonal matrix from x
if x is a vector.  When x is a matrix then diag should extract the diagonal
instead.  Under the current code there is a corner case if the input is 1x0
or 0x1.  Octave always returns the empty matrix.  However, Matlab treats
this as a vector (albeit empty) and can return a matrix when the second
argument to diag is not zero.  For example, under Matlab
diag (ones (1, 0), 2)
=> 0 0
   0 0
This makes sense to me, as the user is requesting to put an empty vector on
the second super-diagonal and that would be equivalent to zeroes (2,2).
The attached patch changes the behavior of diag to match that of Matlab,
but do people agree that it makes sense in this case?

The attached patch passes 'make check' except for 1 regression in
wilkinson.m that would need examination.

--Rik

Attachment: patch.Array.cc
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]