# HG changeset patch # User Carnë Draug # Date 1470712495 -3600 # Node ID 22c2bd4405441a0c5be66b65f23b2b9578240add # Parent 4afe3705ea753511669b015220a42c3354353080 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. diff -r 4afe3705ea75 -r 22c2bd440544 libinterp/dldfcn/chol.cc --- 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 chol (1, 2) %!error chol (1, "foobar") %!error [L,p,Q] = chol ([1, 2; 3, 4]) +%!error [L, p] = chol ([1, 2; 3, 4], "vector") */ DEFUN_DLD (cholinv, args, , diff -r 4afe3705ea75 -r 22c2bd440544 liboctave/numeric/sparse-chol.cc --- 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 -ColumnVector +RowVector sparse_chol::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); diff -r 4afe3705ea75 -r 22c2bd440544 liboctave/numeric/sparse-chol.h --- 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;