octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix conversion from PermMatrix to SparseMatrix.


From: Jason Riedy
Subject: [PATCH] Fix conversion from PermMatrix to SparseMatrix.
Date: Tue, 10 Mar 2009 14:25:05 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux)

# HG changeset patch
# User Jason Riedy <address@hidden>
# Date 1236708805 14400
# Node ID c12f52b84321d53731a0d536d01f3439b09f11ab
# Parent  42e24f4ebc8c70db07d0fcfd08d70b7a40e5519c
[PATCH] 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 <address@hidden>
---
 liboctave/ChangeLog   |    6 ++++++
 liboctave/dSparse.cc  |    7 +++++--
 test/ChangeLog        |    4 ++++
 test/test_diag_perm.m |    9 +++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,9 @@
+2009-03-10  Jason Riedy  <address@hidden>
+
+       * dSparse.cc (SparseMatrix): Fix the constructor from PermMatrix
+       to add values to the matrix as well as getting the structure
+       correct.
+
 2009-03-08  Jaroslav Hajek  <address@hidden>
 
        * idx-vector.h (idx_vector::bloop): loop --> bloop.
diff --git a/liboctave/dSparse.cc b/liboctave/dSparse.cc
--- 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 (pv (i)) = i;
+    }
+  else
+    {
+      for (octave_idx_type i = 0; i < n; i++)
         ridx (i) = pv (i);
     }
-  else
-    {
-      for (octave_idx_type i = 0; i < n; i++)
-        ridx (pv (i)) = i;
-    }
+
+  for (octave_idx_type i = 0; i < n; i++)
+    data (i) = 1.0;
 }
 
 bool
diff --git a/test/ChangeLog b/test/ChangeLog
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2009-03-10  Jason Riedy  <address@hidden>
+
+       * test_diag_perm.m: Add a test for conversion to sparse form.
+
 2009-02-25  John W. Eaton  <address@hidden>
 
        * build_sparse_tests.sh: Note that saving sparse matrices to MAT
diff --git a/test/test_diag_perm.m b/test/test_diag_perm.m
--- a/test/test_diag_perm.m
+++ b/test/test_diag_perm.m
@@ -69,6 +69,15 @@
 %! 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);
+%!  assert (all (find (sP) (:, 3) == 1));
+
 ########################################
 ## Diagonal matrices
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]