changeset 22229:22c2bd440544

chol: return permutation vector as row vector instead of column vector. * libinterp/dldfcn/chol.cc: add tests for the vector option. Also error if there's a "vector" option but input was not sparse. Existing test for case sensitivity was also useless, since change is on the 3rd argument. * liboctave/numeric/sparse-chol.cc, liboctave/numeric/sparse-chol.h: use RowVector instead of ColumnVector for permutation vector, for Matlab compatibility.
author Carnë Draug <carandraug@octave.org>
date Tue, 09 Aug 2016 04:14:55 +0100
parents 4afe3705ea75
children e43199618777
files libinterp/dldfcn/chol.cc liboctave/numeric/sparse-chol.cc liboctave/numeric/sparse-chol.h
diffstat 3 files changed, 30 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/chol.cc	Tue Aug 09 00:21:36 2016 +0100
+++ b/libinterp/dldfcn/chol.cc	Tue Aug 09 04:14:55 2016 +0100
@@ -249,6 +249,8 @@
     }
   else if (arg.is_single_type ())
     {
+      if (vecout)
+        error ("chol: A must be sparse for the \"vector\" option");
       if (arg.is_real_type ())
         {
           FloatMatrix m = arg.float_matrix_value ();
@@ -280,6 +282,8 @@
     }
   else
     {
+      if (vecout)
+        error ("chol: A must be sparse for the \"vector\" option");
       if (arg.is_real_type ())
         {
           Matrix m = arg.matrix_value ();
@@ -324,7 +328,25 @@
 
 %!assert (chol ([2, 1; 1, 1], "lower"), chol ([2, 1; 1, 1], "LoweR"))
 %!assert (chol ([2, 1; 1, 1], "upper"), chol ([2, 1; 1, 1], "Upper"))
-%!assert (chol ([2, 1; 1, 1], "vector"), chol ([2, 1; 1, 1], "VECTOR"))
+
+## Check the "vector" option which only affects the 3rd argument and
+## is only valid for sparse input.
+%!test
+%! a = sparse ([2 1; 1 1]);
+%! r = sparse ([sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)]);
+%! [rd, pd, qd] = chol (a);
+%! [rv, pv, qv] = chol (a, "vector");
+%! assert (r, rd, eps)
+%! assert (r, rv, eps)
+%! assert (pd, 0)
+%! assert (pd, pv)
+%! assert (qd, sparse (eye (2)))
+%! assert (qv, [1 2])
+%!
+%! [rv, pv, qv] = chol (a, "Vector"); # check case sensitivity
+%! assert (r, rv, eps)
+%! assert (pd, pv)
+%! assert (qv, [1 2])
 
 %!testif HAVE_CHOLMOD
 %! ## Bug #42587
@@ -338,6 +360,7 @@
 %!error <optional arguments must be strings> chol (1, 2)
 %!error <optional argument must be one of "vector", "lower"> chol (1, "foobar")
 %!error <matrix A must be sparse> [L,p,Q] = chol ([1, 2; 3, 4])
+%!error <A must be sparse> [L, p] = chol ([1, 2; 3, 4], "vector")
 */
 
 DEFUN_DLD (cholinv, args, ,
--- a/liboctave/numeric/sparse-chol.cc	Tue Aug 09 00:21:36 2016 +0100
+++ b/liboctave/numeric/sparse-chol.cc	Tue Aug 09 04:14:55 2016 +0100
@@ -92,7 +92,7 @@
 #endif
   }
 
-  ColumnVector perm (void) const { return perms + 1; }
+  RowVector perm (void) const { return perms + 1; }
 
   SparseMatrix Q (void) const;
 
@@ -108,7 +108,7 @@
 
   octave_idx_type minor_p;
 
-  ColumnVector perms;
+  RowVector perms;
 
   double cond;
 
@@ -474,7 +474,7 @@
 }
 
 template <typename chol_type>
-ColumnVector
+RowVector
 sparse_chol<chol_type>::perm (void) const
 {
   return rep->perm ();
@@ -511,7 +511,7 @@
 
   cholmod_sparse *m = rep->L ();
   octave_idx_type n = m->ncol;
-  ColumnVector perms = rep->perm ();
+  RowVector perms = rep->perm ();
   double rcond2;
   octave_idx_type info;
   MatrixType mattype (MatrixType::Upper);
--- a/liboctave/numeric/sparse-chol.h	Tue Aug 09 00:21:36 2016 +0100
+++ b/liboctave/numeric/sparse-chol.h	Tue Aug 09 04:14:55 2016 +0100
@@ -28,7 +28,7 @@
 #include "octave-config.h"
 
 #include "CSparse.h"
-#include "dColVector.h"
+#include "dRowVector.h"
 #include "dSparse.h"
 
 // If the sparse matrix classes become templated on the element type
@@ -65,7 +65,7 @@
 
   octave_idx_type P (void) const;
 
-  ColumnVector perm (void) const;
+  RowVector perm (void) const;
 
   SparseMatrix Q (void) const;