diff liboctave/array/Sparse.cc @ 16803:f4eef73b6e90

When indexing scalars stored as sparse matrices, convert to an array, index and then resparsify (bug #37774) * Sparse.cc (template <class T> Sparse<T> Sparse<T>::index (const idx_vector&, *bool) const): If scalar stored in a sparse matrix, treat as an array and resparsify
author David Bateman <dbateman@free.fr>
date Sat, 22 Jun 2013 12:00:39 +0200
parents b135f013679e
children e39f00a32dc7
line wrap: on
line diff
--- a/liboctave/array/Sparse.cc	Sat Jun 22 15:35:19 2013 +0800
+++ b/liboctave/array/Sparse.cc	Sat Jun 22 12:00:39 2013 +0200
@@ -1575,6 +1575,14 @@
       else
         gripe_index_out_of_range (2, 2, idx_j.extent (nc), nc);
     }
+  else if (nr == 1 && nc == 1)
+    {
+      // Scalars stored as sparse matrices occupy more memory than 
+      // a scalar, so let's just convert the matrix to full, index, 
+      // and sparsify the result.
+
+      retval = Sparse<T> (array_value ().index (idx_i, idx_j));
+    }
   else if (idx_i.is_colon ())
     {
       // Great, we're just manipulating columns. This is going to be quite