Mercurial > hg > octave-nkf
diff src/ov-base-sparse.cc @ 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 | a1dbe9d80eee |
children | 283989f2da9b |
line wrap: on
line diff
--- 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