comparison libinterp/dldfcn/chol.cc @ 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 3ac380d46d54
children 71d86e88589f
comparison
equal deleted inserted replaced
22228:4afe3705ea75 22229:22c2bd440544
247 else 247 else
248 err_wrong_type_arg ("chol", arg); 248 err_wrong_type_arg ("chol", arg);
249 } 249 }
250 else if (arg.is_single_type ()) 250 else if (arg.is_single_type ())
251 { 251 {
252 if (vecout)
253 error ("chol: A must be sparse for the \"vector\" option");
252 if (arg.is_real_type ()) 254 if (arg.is_real_type ())
253 { 255 {
254 FloatMatrix m = arg.float_matrix_value (); 256 FloatMatrix m = arg.float_matrix_value ();
255 257
256 octave_idx_type info; 258 octave_idx_type info;
278 else 280 else
279 err_wrong_type_arg ("chol", arg); 281 err_wrong_type_arg ("chol", arg);
280 } 282 }
281 else 283 else
282 { 284 {
285 if (vecout)
286 error ("chol: A must be sparse for the \"vector\" option");
283 if (arg.is_real_type ()) 287 if (arg.is_real_type ())
284 { 288 {
285 Matrix m = arg.matrix_value (); 289 Matrix m = arg.matrix_value ();
286 290
287 octave_idx_type info; 291 octave_idx_type info;
322 %!assert (chol ([2, 1; 1, 1], "lower"), [sqrt(2), 0; 1/sqrt(2), 1/sqrt(2)], 326 %!assert (chol ([2, 1; 1, 1], "lower"), [sqrt(2), 0; 1/sqrt(2), 1/sqrt(2)],
323 %! sqrt (eps)) 327 %! sqrt (eps))
324 328
325 %!assert (chol ([2, 1; 1, 1], "lower"), chol ([2, 1; 1, 1], "LoweR")) 329 %!assert (chol ([2, 1; 1, 1], "lower"), chol ([2, 1; 1, 1], "LoweR"))
326 %!assert (chol ([2, 1; 1, 1], "upper"), chol ([2, 1; 1, 1], "Upper")) 330 %!assert (chol ([2, 1; 1, 1], "upper"), chol ([2, 1; 1, 1], "Upper"))
327 %!assert (chol ([2, 1; 1, 1], "vector"), chol ([2, 1; 1, 1], "VECTOR")) 331
332 ## Check the "vector" option which only affects the 3rd argument and
333 ## is only valid for sparse input.
334 %!test
335 %! a = sparse ([2 1; 1 1]);
336 %! r = sparse ([sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)]);
337 %! [rd, pd, qd] = chol (a);
338 %! [rv, pv, qv] = chol (a, "vector");
339 %! assert (r, rd, eps)
340 %! assert (r, rv, eps)
341 %! assert (pd, 0)
342 %! assert (pd, pv)
343 %! assert (qd, sparse (eye (2)))
344 %! assert (qv, [1 2])
345 %!
346 %! [rv, pv, qv] = chol (a, "Vector"); # check case sensitivity
347 %! assert (r, rv, eps)
348 %! assert (pd, pv)
349 %! assert (qv, [1 2])
328 350
329 %!testif HAVE_CHOLMOD 351 %!testif HAVE_CHOLMOD
330 %! ## Bug #42587 352 %! ## Bug #42587
331 %! A = sparse ([1 0 8;0 1 8;8 8 1]); 353 %! A = sparse ([1 0 8;0 1 8;8 8 1]);
332 %! [Q, p] = chol (A); 354 %! [Q, p] = chol (A);
336 %!error <matrix must be positive definite> chol ([1, 2; 3, 4]) 358 %!error <matrix must be positive definite> chol ([1, 2; 3, 4])
337 %!error <requires square matrix> chol ([1, 2; 3, 4; 5, 6]) 359 %!error <requires square matrix> chol ([1, 2; 3, 4; 5, 6])
338 %!error <optional arguments must be strings> chol (1, 2) 360 %!error <optional arguments must be strings> chol (1, 2)
339 %!error <optional argument must be one of "vector", "lower"> chol (1, "foobar") 361 %!error <optional argument must be one of "vector", "lower"> chol (1, "foobar")
340 %!error <matrix A must be sparse> [L,p,Q] = chol ([1, 2; 3, 4]) 362 %!error <matrix A must be sparse> [L,p,Q] = chol ([1, 2; 3, 4])
363 %!error <A must be sparse> [L, p] = chol ([1, 2; 3, 4], "vector")
341 */ 364 */
342 365
343 DEFUN_DLD (cholinv, args, , 366 DEFUN_DLD (cholinv, args, ,
344 doc: /* -*- texinfo -*- 367 doc: /* -*- texinfo -*-
345 @deftypefn {} {} cholinv (@var{A}) 368 @deftypefn {} {} cholinv (@var{A})