# HG changeset patch # User Barbara Locsi # Date 1470505112 -7200 # Node ID 71d86e88589f72e7fc42388e1bc0fe02b13f1661 # Parent 669fc8cf1fdd03df21539050ed9b0523bbfa1e6f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437) * liboctave/array/MatrixType.cc: a Banded matrix can also be Upper or Lower. In such case, set type to Lower/Upper and not to Banded. The check for Banded matrix does not exist when input is non-sparse, which is why this only affected sparse matrices. * libinterp/dldfcn/chol.cc: add tests for sparse matrices. diff -r 669fc8cf1fdd -r 71d86e88589f libinterp/dldfcn/chol.cc --- a/libinterp/dldfcn/chol.cc Tue Aug 09 15:07:30 2016 -0700 +++ b/libinterp/dldfcn/chol.cc Sat Aug 06 19:38:32 2016 +0200 @@ -570,6 +570,35 @@ return retval; } +/* + +## Test for bug #36437 +%!function sparse_chol2inv (T, tol) +%! iT = inv (T); +%! ciT = chol2inv (chol (T)); +%! assert (ciT, iT, tol); +%! assert (chol2inv (chol ( full (T))), ciT, tol*2); +%!endfunction + +%!test +%! A = gallery ("poisson", 3); +%! sparse_chol2inv (A, eps); + +%!test +%! n = 10; +%! B = spdiags (ones (n, 1) * [1 2 1], [-1 0 1], n, n); +%! sparse_chol2inv (B, eps*100); + +%!test +%! C = gallery("tridiag", 5); +%! sparse_chol2inv (C, eps*10); + +%!test +%! D = gallery("wathen", 1, 1); +%! sparse_chol2inv (D, eps*10^4); + +*/ + DEFUN_DLD (cholupdate, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {[@var{R1}, @var{info}] =} cholupdate (@var{R}, @var{u}, @var{op}) diff -r 669fc8cf1fdd -r 71d86e88589f liboctave/array/MatrixType.cc --- a/liboctave/array/MatrixType.cc Tue Aug 09 15:07:30 2016 -0700 +++ b/liboctave/array/MatrixType.cc Sat Aug 06 19:38:32 2016 +0200 @@ -351,7 +351,9 @@ else dense = false; } - else if (upper_band == 0) + + // If a matrix is Banded but also Upper/Lower, set to the latter. + if (upper_band == 0) typ = MatrixType::Lower; else if (lower_band == 0) typ = MatrixType::Upper; @@ -668,7 +670,9 @@ else dense = false; } - else if (upper_band == 0) + + // If a matrix is Banded but also Upper/Lower, set to the latter. + if (upper_band == 0) typ = MatrixType::Lower; else if (lower_band == 0) typ = MatrixType::Upper;