changeset 14566:aa491bd9e19b stable

avoid unnecessary index overflow error when printing sparse array (bug #35148) * ov-base-sparse.cc (octave_base_sparse<T>::print_info): Don't use numel when computing percentage of non-zero elements.
author John W. Eaton <jwe@octave.org>
date Mon, 16 Apr 2012 15:58:38 -0400
parents 05b7fa3b64c8
children 5bb5fcffa29d
files src/ov-base-sparse.cc
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ov-base-sparse.cc	Sat Apr 14 18:45:08 2012 -0700
+++ b/src/ov-base-sparse.cc	Mon Apr 16 15:58:38 2012 -0400
@@ -318,7 +318,13 @@
      << ", cols = " << nc
      << ", nnz = " << nz;
 
-  double dnel = matrix.numel ();
+  // Avoid calling numel here since it can easily overflow
+  // octave_idx_type even when there is no real problem storing the
+  // sparse array.
+
+  double dnr = nr;
+  double dnc = nc;
+  double dnel = dnr * dnc;
 
   if (dnel > 0)
     {