Mercurial > hg > octave-nkf
changeset 10617:9c9e07f5eb1c
make schur mark triangular matrices on output
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 10 May 2010 07:50:56 +0200 |
parents | d61caf612f1e |
children | 773566827bcf |
files | src/ChangeLog src/DLD-FUNCTIONS/schur.cc |
diffstat | 2 files changed, 28 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2010-05-10 Jaroslav Hajek <highegg@gmail.com> + + * DLD-FUNCTIONS/schur.cc (Fschur): Mark triangular matrices on output. + 2010-05-10 Jaroslav Hajek <highegg@gmail.com> * ov-range.cc (octave_range::index_vector): Optimize order of
--- a/src/DLD-FUNCTIONS/schur.cc +++ b/src/DLD-FUNCTIONS/schur.cc @@ -38,6 +38,26 @@ #include "oct-obj.h" #include "utils.h" +template <class Matrix> +static octave_value +mark_upper_triangular (const Matrix& a) +{ + octave_value retval = a; + + octave_idx_type n = a.rows (); + assert (a.columns () == n); + + const typename Matrix::element_type zero = typename Matrix::element_type (); + + for (octave_idx_type i = 0; i < n; i++) + if (a(i,i) == zero) + return retval; + + retval.matrix_type (MatrixType::Upper); + + return retval; +} + DEFUN_DLD (schur, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{s} =} schur (@var{a})\n\ @@ -294,12 +314,12 @@ if (nargout == 0 || nargout == 1) { FloatComplexSCHUR result (ctmp, ord, false); - retval(0) = result.schur_matrix (); + retval(0) = mark_upper_triangular (result.schur_matrix ()); } else { FloatComplexSCHUR result (ctmp, ord, true); - retval(1) = result.schur_matrix (); + retval(1) = mark_upper_triangular (result.schur_matrix ()); retval(0) = result.unitary_matrix (); } } @@ -336,12 +356,12 @@ if (nargout == 0 || nargout == 1) { ComplexSCHUR result (ctmp, ord, false); - retval(0) = result.schur_matrix (); + retval(0) = mark_upper_triangular (result.schur_matrix ()); } else { ComplexSCHUR result (ctmp, ord, true); - retval(1) = result.schur_matrix (); + retval(1) = mark_upper_triangular (result.schur_matrix ()); retval(0) = result.unitary_matrix (); } }