# HG changeset patch # User Marco Caliari # Date 1330957987 18000 # Node ID ec660526ae50c3d3e3b17630b953df4979fdae6f # Parent 9f7c22795c948c0256f32df7171f06b5a7656cf2 Fix sparse range indexing bug (bug #35570) * Sparse.cc (Sparse::index): Correctly compute and assign the row and column index vectors. Also add a test to check for this bug. diff --git a/liboctave/Sparse.cc b/liboctave/Sparse.cc --- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -1404,7 +1404,11 @@ if (idx.is_range () && idx.increment () == -1) { retval = Sparse (nr, 1, nz); - std::reverse_copy (ridx (), ridx () + nz, retval.ridx ()); + + for (octave_idx_type j = 0; j < nz; j++) + retval.ridx (j) = nr - ridx (nz - j - 1) - 1; + + copy_or_memcpy (2, cidx (), retval.cidx ()); std::reverse_copy (data (), data () + nz, retval.data ()); } else @@ -2726,6 +2730,10 @@ %!test test_sparse_slice([2 2], 22, 3); %!test test_sparse_slice([2 2], 22, 4); +bug #35570: + +%!assert (speye (3,1)(3:-1:1), sparse ([0; 0; 1])) + */ template