Mercurial > octave
changeset 22193:e35866e6a2e0
normest1: always return a column vector for IT output (patch #8837)
* normest1.m: special code path returns a row vector for number of iterations
while it returns a column vector for all others. This is Matlab compatible
but obviously a bug in Matlab. Fix to always return a vector of same shape.
Add tests.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Sat, 30 Jul 2016 14:30:48 +0100 |
parents | 20b225a3ebf8 |
children | b1ebad209360 |
files | scripts/linear-algebra/normest1.m |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/linear-algebra/normest1.m Sat Jul 23 17:45:32 2016 +0200 +++ b/scripts/linear-algebra/normest1.m Sat Jul 30 14:30:48 2016 +0100 @@ -111,7 +111,10 @@ v = zeros (n, 1); v(idx) = 1; w = A(:, idx); - k = [0, 1]; + ## Matlab incompatible on purpose. Matlab returns k as a row vector + ## for this special case, but a column vector in all other cases. + ## This is obviously a bug in Matlab that we don't reproduce. + k = [0; 1]; return else realm = isreal (A); @@ -354,3 +357,10 @@ %! unwind_protect_cleanup %! rand ("state", old_state); %! end_unwind_protect + +## Check IT is always a column vector. +%!test +%! [~, ~, ~, it] = normest1 (rand (3), 3); +%! assert (iscolumn (it)) +%! [~, ~, ~, it] = normest1 (rand (50), 20); +%! assert (iscolumn (it))