Mercurial > octave
comparison liboctave/numeric/sparse-qr.cc @ 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 | 796f54d4ddbf |
children | e88a07dec498 |
comparison
equal
deleted
inserted
replaced
31255:43068d904d9d | 31256:fa4bb329a51a |
---|---|
507 m_HPinv (nullptr) | 507 m_HPinv (nullptr) |
508 { | 508 { |
509 octave_idx_type nr = a.rows (); | 509 octave_idx_type nr = a.rows (); |
510 octave_idx_type nc = a.cols (); | 510 octave_idx_type nc = a.cols (); |
511 | 511 |
512 if (nr <= 0 || nc <= 0) | 512 if (nr < 0 || nc < 0) |
513 (*current_liboctave_error_handler) | 513 (*current_liboctave_error_handler) |
514 ("matrix dimension with negative or zero size"); | 514 ("matrix dimension with negative size"); |
515 | 515 |
516 if (order < 0 || order > 9) | 516 if (order < 0 || order > 9) |
517 (*current_liboctave_error_handler) | 517 (*current_liboctave_error_handler) |
518 ("ordering %d is not supported by SPQR", order); | 518 ("ordering %d is not supported by SPQR", order); |
519 | 519 |
705 Matrix ret (nr, b_nc); | 705 Matrix ret (nr, b_nc); |
706 | 706 |
707 if (nrows != b_nr) | 707 if (nrows != b_nr) |
708 (*current_liboctave_error_handler) | 708 (*current_liboctave_error_handler) |
709 ("sparse_qr: matrix dimension mismatch"); | 709 ("sparse_qr: matrix dimension mismatch"); |
710 else if (b_nc <= 0 || b_nr <= 0) | 710 else if (b_nc < 0 || b_nr < 0) |
711 (*current_liboctave_error_handler) | 711 (*current_liboctave_error_handler) |
712 ("sparse_qr: matrix dimension with negative or zero size"); | 712 ("sparse_qr: matrix dimension with negative size"); |
713 | 713 |
714 cholmod_dense *QTB; // Q' * B | 714 cholmod_dense *QTB; // Q' * B |
715 cholmod_dense B = rod2rcd (b); | 715 cholmod_dense B = rod2rcd (b); |
716 | 716 |
717 QTB = SuiteSparseQR_qmult<double> (SPQR_QTX, m_H, m_Htau, m_HPinv, &B, | 717 QTB = SuiteSparseQR_qmult<double> (SPQR_QTX, m_H, m_Htau, m_HPinv, &B, |
902 | 902 |
903 octave_idx_type b_nr = b.rows (); | 903 octave_idx_type b_nr = b.rows (); |
904 octave_idx_type b_nc = b.cols (); | 904 octave_idx_type b_nc = b.cols (); |
905 Matrix x (ncols, b_nc); // X = m_E'*(m_R\(Q'*B)) | 905 Matrix x (ncols, b_nc); // X = m_E'*(m_R\(Q'*B)) |
906 | 906 |
907 if (nrows <= 0 || ncols <= 0 || b_nc <= 0 || b_nr <= 0) | 907 if (nrows < 0 || ncols < 0 || b_nc < 0 || b_nr < 0) |
908 (*current_liboctave_error_handler) | 908 (*current_liboctave_error_handler) |
909 ("matrix dimension with negative or zero size"); | 909 ("matrix dimension with negative size"); |
910 | 910 |
911 if (nrows < 0 || ncols < 0 || nrows != b_nr) | 911 if (nrows < 0 || ncols < 0 || nrows != b_nr) |
912 (*current_liboctave_error_handler) ("matrix dimension mismatch"); | 912 (*current_liboctave_error_handler) ("matrix dimension mismatch"); |
913 | 913 |
914 cholmod_dense *QTB; // Q' * B | 914 cholmod_dense *QTB; // Q' * B |
1442 m_Htau (nullptr), m_HPinv (nullptr) | 1442 m_Htau (nullptr), m_HPinv (nullptr) |
1443 { | 1443 { |
1444 octave_idx_type nr = a.rows (); | 1444 octave_idx_type nr = a.rows (); |
1445 octave_idx_type nc = a.cols (); | 1445 octave_idx_type nc = a.cols (); |
1446 | 1446 |
1447 if (nr <= 0 || nc <= 0) | 1447 if (nr < 0 || nc < 0) |
1448 (*current_liboctave_error_handler) | 1448 (*current_liboctave_error_handler) |
1449 ("matrix dimension with negative or zero size"); | 1449 ("matrix dimension with negative size"); |
1450 | 1450 |
1451 if (order < 0 || order > 9) | 1451 if (order < 0 || order > 9) |
1452 (*current_liboctave_error_handler) | 1452 (*current_liboctave_error_handler) |
1453 ("ordering %d is not supported by SPQR", order); | 1453 ("ordering %d is not supported by SPQR", order); |
1454 | 1454 |
1641 ComplexMatrix ret (nr, b_nc); | 1641 ComplexMatrix ret (nr, b_nc); |
1642 | 1642 |
1643 if (nrows != b_nr) | 1643 if (nrows != b_nr) |
1644 (*current_liboctave_error_handler) ("matrix dimension mismatch"); | 1644 (*current_liboctave_error_handler) ("matrix dimension mismatch"); |
1645 | 1645 |
1646 if (b_nc <= 0 || b_nr <= 0) | 1646 if (b_nc < 0 || b_nr < 0) |
1647 (*current_liboctave_error_handler) | 1647 (*current_liboctave_error_handler) |
1648 ("matrix dimension with negative or zero size"); | 1648 ("matrix dimension with negative size"); |
1649 | 1649 |
1650 cholmod_dense *QTB; // Q' * B | 1650 cholmod_dense *QTB; // Q' * B |
1651 cholmod_dense B = cod2ccd (b); | 1651 cholmod_dense B = cod2ccd (b); |
1652 | 1652 |
1653 QTB = SuiteSparseQR_qmult<Complex> (SPQR_QTX, m_H, m_Htau, m_HPinv, &B, | 1653 QTB = SuiteSparseQR_qmult<Complex> (SPQR_QTX, m_H, m_Htau, m_HPinv, &B, |
3116 octave_idx_type b_nc = b.cols (); | 3116 octave_idx_type b_nc = b.cols (); |
3117 octave_idx_type b_nr = b.rows (); | 3117 octave_idx_type b_nr = b.rows (); |
3118 | 3118 |
3119 int order = cxsparse_defaults<SPARSE_T>::order; | 3119 int order = cxsparse_defaults<SPARSE_T>::order; |
3120 | 3120 |
3121 if (nr <= 0 || nc <= 0 || b_nc <= 0 || b_nr <= 0) | 3121 if (nr < 0 || nc < 0 || b_nc < 0 || b_nr < 0) |
3122 (*current_liboctave_error_handler) | 3122 (*current_liboctave_error_handler) |
3123 ("matrix dimension with negative or zero size"); | 3123 ("matrix dimension with negative size"); |
3124 | 3124 |
3125 if ( nr != b_nr) | 3125 if ( nr != b_nr) |
3126 (*current_liboctave_error_handler) | 3126 (*current_liboctave_error_handler) |
3127 ("matrix dimension mismatch in solution of minimum norm problem"); | 3127 ("matrix dimension mismatch in solution of minimum norm problem"); |
3128 | 3128 |