Mercurial > hg > octave-lyh
changeset 7644:91d7440211e7
display percentage of elements that are nonzero when printing sparse matrices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 26 Mar 2008 12:56:51 -0400 |
parents | 0220da981c2a |
children | 734854f21c94 |
files | src/ChangeLog src/ov-base-sparse.cc |
diffstat | 2 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-03-26 John W. Eaton <jwe@octave.org> + + * ov-base-sparse.cc (octave_base_sparse<T>::print_raw): + Also display percentage of elements that are nonzero. + 2008-03-25 Soren Hauberg <hauberg@gmail.com> * DLD-FUNCTIONS/__convn__.cc: New file.
--- a/src/ov-base-sparse.cc +++ b/src/ov-base-sparse.cc @@ -25,6 +25,7 @@ #include <config.h> #endif +#include <iomanip> #include <iostream> #include "oct-obj.h" @@ -265,7 +266,14 @@ os << "Compressed Column Sparse (rows = " << nr << ", cols = " << nc - << ", nnz = " << nz << ")\n"; + << ", nnz = " << nz; + + double dnel = matrix.numel (); + + if (dnel > 0) + os << " [" << std::setprecision (2) << (nz / dnel * 100) << "%])\n"; + + os << ")\n"; // add one to the printed indices to go from // zero-based to one-based arrays