diff liboctave/Sparse.cc @ 10494:e52f41fd82c7

optimize (:) indexing of sparse column vectors
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 07 Apr 2010 13:00:25 +0200
parents 2f8bacc2a57d
children cb7ffe7288f0
line wrap: on
line diff
--- a/liboctave/Sparse.cc	Wed Apr 07 12:07:06 2010 +0200
+++ b/liboctave/Sparse.cc	Wed Apr 07 13:00:25 2010 +0200
@@ -1472,20 +1472,25 @@
       ("cannot index sparse matrix with an N-D Array");
   else if (idx.is_colon ())
     {
-      // Fast magic colon processing.
-      retval = Sparse<T> (nel, 1, nz);
-
-      for (octave_idx_type i = 0; i < nc; i++)
+      if (nc == 1)
+        retval = *this;
+      else
         {
-          for (octave_idx_type j = cidx(i); j < cidx(i+1); j++)
+          // Fast magic colon processing.
+          retval = Sparse<T> (nel, 1, nz);
+
+          for (octave_idx_type i = 0; i < nc; i++)
             {
-              retval.xdata(j) = data(j); 
-              retval.xridx(j) = ridx(j) + i * nr;
+              for (octave_idx_type j = cidx(i); j < cidx(i+1); j++)
+                {
+                  retval.xdata(j) = data(j); 
+                  retval.xridx(j) = ridx(j) + i * nr;
+                }
             }
+
+          retval.xcidx(0) = 0;
+          retval.xcidx(1) = nz;
         }
-
-      retval.xcidx(0) = 0;
-      retval.xcidx(1) = nz;
     }
   else if (idx.extent (nel) > nel)
     {