changeset 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 26bd7d18a50c
children 4264c78951ec
files liboctave/array/CSparse.cc liboctave/array/dSparse.cc
diffstat 2 files changed, 30 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/CSparse.cc	Thu Oct 17 13:36:52 2013 -0700
+++ b/liboctave/array/CSparse.cc	Thu Oct 17 23:07:34 2013 +0200
@@ -258,16 +258,15 @@
 {
   SparseComplexMatrix 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);
@@ -413,16 +412,15 @@
 {
   SparseComplexMatrix 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);
@@ -556,6 +554,13 @@
   return result;
 }
 
+/*
+
+%!assert (max (max (speye (65536) * 1i)), sparse (1i)) 
+%!assert (min (min (speye (65536) * 1i)), sparse (0)) 
+
+*/
+
 ComplexRowVector
 SparseComplexMatrix::row (octave_idx_type i) const
 {
--- 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
 {