# HG changeset patch # User Jaroslav Hajek # Date 1235894877 -3600 # Node ID d077c590eb889f6820821d722bb7639380b196fc # Parent ae51d068bbd5f1c2e61564ec959f13a0ba4ae2f0 indicate diag & perm matrices on output diff -r ae51d068bbd5 -r d077c590eb88 src/ChangeLog --- a/src/ChangeLog Sat Feb 28 22:39:33 2009 -0500 +++ b/src/ChangeLog Sun Mar 01 09:07:57 2009 +0100 @@ -1,3 +1,14 @@ +2009-03-01 Jaroslav Hajek + + * ov-perm.cc (octave_perm_matrix::print_raw): Call + octave_print_internal. + (octave_perm_matrix::print_raw): Call print_raw. + * pr-output.cc (octave_print_internal (...,const DiagMatrix&,...)): + Indicate diagonal matrix. + (octave_print_internal (...,const ComplexDiagMatrix&,...)): Ditto. + (octave_print_internal (...,const PermMatrix&,...)): New function. + * pr-output.h: Declare it. + 2009-02-27 Jaroslav Hajek * OPERATORS/op-dms-template.cc (gripe_if_zero): New template static diff -r ae51d068bbd5 -r d077c590eb88 src/ov-perm.cc --- a/src/ov-perm.cc Sat Feb 28 22:39:33 2009 -0500 +++ b/src/ov-perm.cc Sun Mar 01 09:07:57 2009 +0100 @@ -33,6 +33,7 @@ #include "error.h" #include "gripes.h" #include "ops.h" +#include "pr-output.h" #include "ls-oct-ascii.h" @@ -352,7 +353,8 @@ octave_perm_matrix::print_raw (std::ostream& os, bool pr_as_read_syntax) const { - return to_dense ().print_raw (os, pr_as_read_syntax); + return octave_print_internal (os, matrix, pr_as_read_syntax, + current_print_indent_level ()); } mxArray * @@ -372,7 +374,8 @@ void octave_perm_matrix::print (std::ostream& os, bool pr_as_read_syntax) const { - to_dense ().print (os, pr_as_read_syntax); + print_raw (os, pr_as_read_syntax); + newline (os); } int diff -r ae51d068bbd5 -r d077c590eb88 src/pr-output.cc --- a/src/pr-output.cc Sat Feb 28 22:39:33 2009 -0500 +++ b/src/pr-output.cc Sun Mar 01 09:07:57 2009 +0100 @@ -1793,6 +1793,7 @@ } else { + os << "Diagonal Matrix\n\n"; pr_scale_header (os, scale); // kluge. Get the true width of a number. @@ -2195,6 +2196,7 @@ } else { + os << "Diagonal Matrix\n\n"; pr_scale_header (os, scale); // kluge. Get the true width of a number. @@ -2238,6 +2240,139 @@ } void +octave_print_internal (std::ostream& os, const PermMatrix& m, + bool pr_as_read_syntax, int extra_indent) +{ + octave_idx_type nr = m.rows (); + octave_idx_type nc = m.columns (); + + if (nr == 0 || nc == 0) + print_empty_matrix (os, nr, nc, pr_as_read_syntax); + else if (plus_format && ! pr_as_read_syntax) + { + for (octave_idx_type i = 0; i < nr; i++) + { + for (octave_idx_type j = 0; j < nc; j++) + { + OCTAVE_QUIT; + + pr_plus_format (os, m(i,j)); + } + + if (i < nr - 1) + os << "\n"; + } + } + else + { + int fw = 2; + double scale = 1.0; + int column_width = fw + 2; + octave_idx_type total_width = nc * column_width; + octave_idx_type max_width = command_editor::terminal_cols (); + + if (pr_as_read_syntax) + max_width -= 4; + else + max_width -= extra_indent; + + if (max_width < 0) + max_width = 0; + + if (free_format) + { + if (pr_as_read_syntax) + os << "[\n"; + + os << Matrix (m); + + if (pr_as_read_syntax) + os << "]"; + + return; + } + + octave_idx_type inc = nc; + if (total_width > max_width && Vsplit_long_rows) + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } + + if (pr_as_read_syntax) + { + Array pvec = m.pvec (); + bool colp = m.is_col_perm (); + + os << "eye ("; + if (colp) os << ":, "; + + octave_idx_type col = 0; + while (col < nc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + for (octave_idx_type j = col; j < lim; j++) + { + OCTAVE_QUIT; + + if (j == 0) + os << "[ "; + else + { + if (j > col && j < lim) + os << ", "; + else + os << " "; + } + + os << pvec (j); + } + + col += inc; + + if (col >= nc) + os << " ]"; + else + os << " ...\n"; + } + if (! colp) os << ", :"; + os << ")"; + } + else + { + os << "Permutation Matrix\n\n"; + + for (octave_idx_type col = 0; col < nc; col += inc) + { + octave_idx_type lim = col + inc < nc ? col + inc : nc; + + pr_col_num_header (os, total_width, max_width, lim, col, + extra_indent); + + for (octave_idx_type i = 0; i < nr; i++) + { + os << std::setw (extra_indent) << ""; + + for (octave_idx_type j = col; j < lim; j++) + { + OCTAVE_QUIT; + + os << " "; + + os << std::setw (fw) << m(i,j); + } + + if (i < nr - 1) + os << "\n"; + } + } + } + } +} + +void octave_print_internal (std::ostream& os, const ComplexNDArray& nda, bool pr_as_read_syntax, int extra_indent) { diff -r ae51d068bbd5 -r d077c590eb88 src/pr-output.h --- a/src/pr-output.h Sat Feb 28 22:39:33 2009 -0500 +++ b/src/pr-output.h Sun Mar 01 09:07:57 2009 +0100 @@ -31,10 +31,14 @@ template class ArrayN; class ComplexMatrix; class FloatComplexMatrix; +class ComplexDiagMatrix; +class FloatComplexDiagMatrix; class ComplexNDArray; class FloatComplexNDArray; class Matrix; class FloatMatrix; +class DiagMatrix; +class FloatDiagMatrix; class NDArray; class FloatNDArray; class Range; @@ -42,6 +46,7 @@ class boolNDArray; class charMatrix; class charNDArray; +class PermMatrix; class Cell; #include "intNDArray.h" @@ -129,6 +134,11 @@ int extra_indent = 0); extern OCTINTERP_API void +octave_print_internal (std::ostream& os, const PermMatrix& m, + bool pr_as_read_syntax = false, + int extra_indent = 0); + +extern OCTINTERP_API void octave_print_internal (std::ostream& os, const Range& r, bool pr_as_read_syntax = false, int extra_indent = 0);