Mercurial > hg > octave-terminal
changeset 8951:5bce1357edd6
Fix conversion from PermMatrix to SparseMatrix.
From 76c98628f1943d583d5813321ec0a3c684d7ac84 Mon Sep 17 00:00:00 2001
Date: Tue, 10 Mar 2009 14:12:59 -0400
The result was transposed and missing its values. Also add a test case.
Signed-off-by: Jason Riedy <jason@acm.org>
---
liboctave/ChangeLog | 6 ++++++
liboctave/dSparse.cc | 7 +++++--
test/ChangeLog | 4 ++++
test/test_diag_perm.m | 9 +++++++++
4 files changed, 24 insertions(+), 2 deletions(-)
author | Jason Riedy <jason@acm.org> |
---|---|
date | Tue, 10 Mar 2009 15:44:11 -0400 |
parents | d865363208d6 |
children | 43aec7c168eb |
files | liboctave/ChangeLog liboctave/dSparse.cc test/ChangeLog test/test_diag_perm.m |
diffstat | 4 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2009-03-10 Jason Riedy <jason@acm.org> + + * dSparse.cc (SparseMatrix::SparseMatrix (const PermMatrix&)): + Fix conversion to add values to the matrix as well as getting + structure correct. + 2009-03-10 John W. Eaton <jwe@octave.org> * Array.h, ArrayN.h, Bounds.h, CmplxAEPBAL.h, CmplxCHOL.h,
--- a/liboctave/dSparse.cc +++ b/liboctave/dSparse.cc @@ -169,13 +169,16 @@ if (a.is_row_perm ()) { for (octave_idx_type i = 0; i < n; i++) - ridx (i) = pv (i); + ridx (pv (i)) = i; } else { for (octave_idx_type i = 0; i < n; i++) - ridx (pv (i)) = i; + ridx (i) = pv (i); } + + for (octave_idx_type i = 0; i < n; i++) + data (i) = 1.0; } bool
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2009-03-10 Jason Riedy <jason@acm.org> + + * test_diag_perm.m: Add a test for conversion to sparse form. + 2009-02-25 John W. Eaton <jwe@octave.org> * build_sparse_tests.sh: Note that saving sparse matrices to MAT
--- a/test/test_diag_perm.m +++ b/test/test_diag_perm.m @@ -69,6 +69,14 @@ %! A(3, 1) = Inf; %! assert (Pr * A * Pc, A(pr, pc)); +## conversion to sparse form +%!test +%! n = 7; +%! P = eye (n) (:, randperm (n)); +%! sP = sparse (P); +%! assert (full (sP), full (P)); +%! assert (size (find (sP), 1), n); + ######################################## ## Diagonal matrices