diff liboctave/array/dSparse.cc @ 17679:c81debf315e0

Avoid use of numel in sparse matrix min/max functions * dSparse.cc (SparseMatrix SparseMatrix::max (Array<octave_idx-type>&, int)) : Remove use of numel (SparseMatrix SparseMatrix::min (Array<octave_idx-type>&, int)) : ditto * CSparse.cc (SparseComplexMatrix SparseComplexMatrix::max ( Array<octave_idx-type>&, int)) : Remove use of numel (SparseComplexMatrix SparseComplexMatrix::min (Array<octave_idx-type>&, int)) : ditto
author David Bateman <dbateman@free.fr>
date Thu, 17 Oct 2013 23:07:34 +0200
parents 6aafe87a3144
children 93e272018df2
line wrap: on
line diff
--- a/liboctave/array/dSparse.cc	Thu Oct 17 13:36:52 2013 -0700
+++ b/liboctave/array/dSparse.cc	Thu Oct 17 23:07:34 2013 +0200
@@ -276,16 +276,15 @@
 {
   SparseMatrix result;
   dim_vector dv = dims ();
-
-  if (dv.numel () == 0 || dim >= dv.length ())
+  octave_idx_type nr = dv(0);
+  octave_idx_type nc = dv(1);
+
+  if (nr == 0 || nc == 0 || dim >= dv.length ())
     return result;
 
   if (dim < 0)
     dim = dv.first_non_singleton ();
 
-  octave_idx_type nr = dv(0);
-  octave_idx_type nc = dv(1);
-
   if (dim == 0)
     {
       idx_arg.clear (1, nc);
@@ -425,16 +424,15 @@
 {
   SparseMatrix result;
   dim_vector dv = dims ();
-
-  if (dv.numel () == 0 || dim >= dv.length ())
+  octave_idx_type nr = dv(0);
+  octave_idx_type nc = dv(1);
+
+  if (nr == 0 || nc == 0 || dim >= dv.length ())
     return result;
 
   if (dim < 0)
     dim = dv.first_non_singleton ();
 
-  octave_idx_type nr = dv(0);
-  octave_idx_type nc = dv(1);
-
   if (dim == 0)
     {
       idx_arg.clear (1, nc);
@@ -562,6 +560,13 @@
   return result;
 }
 
+/*
+
+%!assert (max (max (speye (65536))), sparse (1)) 
+%!assert (min (min (speye (65536))), sparse (0)) 
+
+*/
+
 RowVector
 SparseMatrix::row (octave_idx_type i) const
 {