# HG changeset patch # User David Bateman # Date 1371895239 -7200 # Node ID f4eef73b6e90a2fb021def3d27cbd6762a9ebdc5 # Parent 9302e92df412b74e91c65b37c9f55e8bde7b0280 When indexing scalars stored as sparse matrices, convert to an array, index and then resparsify (bug #37774) * Sparse.cc (template Sparse Sparse::index (const idx_vector&, *bool) const): If scalar stored in a sparse matrix, treat as an array and resparsify diff --git a/liboctave/array/Sparse.cc b/liboctave/array/Sparse.cc --- 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 (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