Mercurial > octave
changeset 31256:fa4bb329a51a
Allow empty sparse matrix inputs to qr() (bug #63069)
* qr.cc (Fqr): Add BIST tests for bug #63069.
* sparse-qr.cc (sparse_qr<SparseMatrix>::sparse_qr_rep::sparse_qr_rep,
sparse_qr<SparseMatrix>::sparse_qr_rep::C,
sparse_qr<SparseMatrix>::sparse_qr_rep::tall_solve<MArray<double>, Matrix>,
sparse_qr<SparseComplexMatrix>::sparse_qr_rep::sparse_qr_rep,
sparse_qr<SparseComplexMatrix>::sparse_qr_rep::C,
sparse_qr<SPARSE_T>::solve):
Change input validation from "<= 0" to "< 0".
Change error message to "matrix dimension with negative size" from
"matrix dimension with negative or zero size".
author | Rik <rik@octave.org> |
---|---|
date | Tue, 04 Oct 2022 17:05:21 -0700 |
parents | 43068d904d9d |
children | 2deb14b9ad27 |
files | libinterp/corefcn/qr.cc liboctave/numeric/sparse-qr.cc |
diffstat | 2 files changed, 18 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/qr.cc Tue Oct 04 16:58:14 2022 -0400 +++ b/libinterp/corefcn/qr.cc Tue Oct 04 17:05:21 2022 -0700 @@ -800,11 +800,17 @@ %! assert (r, re, sqrt (eps)); %! assert (q'*b, c, sqrt (eps)); +## Empty matrices %!test %! assert (qr (zeros (0, 0)), zeros (0, 0)) %! assert (qr (zeros (1, 0)), zeros (1, 0)) %! assert (qr (zeros (0, 1)), zeros (0, 1)) +%!test <*63069> +%! assert (qr (sparse (0, 0)), sparse (0, 0)) +%! assert (qr (sparse (1, 0)), sparse (1, 0)) +%! assert (qr (sparse (0, 1)), sparse (0, 1)) + %!error qr () %!error qr ([1, 2; 3, 4], 0, 2) %!error <option string must be .*, not "foo"> qr (magic (3), "foo")
--- a/liboctave/numeric/sparse-qr.cc Tue Oct 04 16:58:14 2022 -0400 +++ b/liboctave/numeric/sparse-qr.cc Tue Oct 04 17:05:21 2022 -0700 @@ -509,9 +509,9 @@ octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - if (nr <= 0 || nc <= 0) + if (nr < 0 || nc < 0) (*current_liboctave_error_handler) - ("matrix dimension with negative or zero size"); + ("matrix dimension with negative size"); if (order < 0 || order > 9) (*current_liboctave_error_handler) @@ -707,9 +707,9 @@ if (nrows != b_nr) (*current_liboctave_error_handler) ("sparse_qr: matrix dimension mismatch"); - else if (b_nc <= 0 || b_nr <= 0) + else if (b_nc < 0 || b_nr < 0) (*current_liboctave_error_handler) - ("sparse_qr: matrix dimension with negative or zero size"); + ("sparse_qr: matrix dimension with negative size"); cholmod_dense *QTB; // Q' * B cholmod_dense B = rod2rcd (b); @@ -904,9 +904,9 @@ octave_idx_type b_nc = b.cols (); Matrix x (ncols, b_nc); // X = m_E'*(m_R\(Q'*B)) - if (nrows <= 0 || ncols <= 0 || b_nc <= 0 || b_nr <= 0) + if (nrows < 0 || ncols < 0 || b_nc < 0 || b_nr < 0) (*current_liboctave_error_handler) - ("matrix dimension with negative or zero size"); + ("matrix dimension with negative size"); if (nrows < 0 || ncols < 0 || nrows != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch"); @@ -1444,9 +1444,9 @@ octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - if (nr <= 0 || nc <= 0) + if (nr < 0 || nc < 0) (*current_liboctave_error_handler) - ("matrix dimension with negative or zero size"); + ("matrix dimension with negative size"); if (order < 0 || order > 9) (*current_liboctave_error_handler) @@ -1643,9 +1643,9 @@ if (nrows != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch"); - if (b_nc <= 0 || b_nr <= 0) + if (b_nc < 0 || b_nr < 0) (*current_liboctave_error_handler) - ("matrix dimension with negative or zero size"); + ("matrix dimension with negative size"); cholmod_dense *QTB; // Q' * B cholmod_dense B = cod2ccd (b); @@ -3118,9 +3118,9 @@ int order = cxsparse_defaults<SPARSE_T>::order; - if (nr <= 0 || nc <= 0 || b_nc <= 0 || b_nr <= 0) + if (nr < 0 || nc < 0 || b_nc < 0 || b_nr < 0) (*current_liboctave_error_handler) - ("matrix dimension with negative or zero size"); + ("matrix dimension with negative size"); if ( nr != b_nr) (*current_liboctave_error_handler)