Mercurial > octave
comparison 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 |
comparison
equal
deleted
inserted
replaced
16802:9302e92df412 | 16803:f4eef73b6e90 |
---|---|
1573 else if (idx_i.extent (nr) > nr) | 1573 else if (idx_i.extent (nr) > nr) |
1574 gripe_index_out_of_range (2, 1, idx_i.extent (nr), nr); | 1574 gripe_index_out_of_range (2, 1, idx_i.extent (nr), nr); |
1575 else | 1575 else |
1576 gripe_index_out_of_range (2, 2, idx_j.extent (nc), nc); | 1576 gripe_index_out_of_range (2, 2, idx_j.extent (nc), nc); |
1577 } | 1577 } |
1578 else if (nr == 1 && nc == 1) | |
1579 { | |
1580 // Scalars stored as sparse matrices occupy more memory than | |
1581 // a scalar, so let's just convert the matrix to full, index, | |
1582 // and sparsify the result. | |
1583 | |
1584 retval = Sparse<T> (array_value ().index (idx_i, idx_j)); | |
1585 } | |
1578 else if (idx_i.is_colon ()) | 1586 else if (idx_i.is_colon ()) |
1579 { | 1587 { |
1580 // Great, we're just manipulating columns. This is going to be quite | 1588 // Great, we're just manipulating columns. This is going to be quite |
1581 // efficient, because the columns can stay compressed as they are. | 1589 // efficient, because the columns can stay compressed as they are. |
1582 if (idx_j.is_colon ()) | 1590 if (idx_j.is_colon ()) |