comparison liboctave/Sparse.cc @ 14790:b8041f48b0ff stable

Return sparse column vectors when the indexing allows it (bug #36656) * Sparse.cc (Sparse<T>::index): Return a column vector when it's known to be the desired output. Add a test
author David Bateman <dbateman@free.fr>
date Thu, 21 Jun 2012 14:24:33 -0400
parents 62219ea36f05
children 90c131272396 f2e72944847b
comparison
equal deleted inserted replaced
14789:62219ea36f05 14790:b8041f48b0ff
1580 } 1580 }
1581 else if (nc == 1 && idx_j.is_colon_equiv (nc) && idx_i.is_vector ()) 1581 else if (nc == 1 && idx_j.is_colon_equiv (nc) && idx_i.is_vector ())
1582 { 1582 {
1583 // It's actually vector indexing. The 1D index is specialized for that. 1583 // It's actually vector indexing. The 1D index is specialized for that.
1584 retval = index (idx_i); 1584 retval = index (idx_i);
1585
1586 // If nr == 1 then the vector indexing will return a column vector!!
1587 if (nr == 1)
1588 retval.transpose();
1585 } 1589 }
1586 else if (idx_i.is_scalar ()) 1590 else if (idx_i.is_scalar ())
1587 { 1591 {
1588 octave_idx_type ii = idx_i(0); 1592 octave_idx_type ii = idx_i(0);
1589 retval = Sparse<T> (1, m); 1593 retval = Sparse<T> (1, m);
2740 %!test 2744 %!test
2741 %! s = sparse (magic (5)); 2745 %! s = sparse (magic (5));
2742 %! s(:,2:4) = []; 2746 %! s(:,2:4) = [];
2743 %! assert (s, sparse (magic (5)(:, [1,5]))); 2747 %! assert (s, sparse (magic (5)(:, [1,5])));
2744 2748
2749 %!test
2750 %! s = sparse([], [], [], 1, 1);
2751 %! s(1,:) = [];
2752 %! assert (s, sparse ([], [], [], 0, 1));
2753
2745 */ 2754 */
2746 2755
2747 template <class T> 2756 template <class T>
2748 void 2757 void
2749 Sparse<T>::print_info (std::ostream& os, const std::string& prefix) const 2758 Sparse<T>::print_info (std::ostream& os, const std::string& prefix) const