changeset 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 9302e92df412
children 617a6e5a974a
files liboctave/array/Sparse.cc
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/Sparse.cc
+++ b/liboctave/array/Sparse.cc
@@ -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