diff --git a/include/albatross/src/models/sparse_gp.hpp b/include/albatross/src/models/sparse_gp.hpp index c9f4c313..69eae477 100644 --- a/include/albatross/src/models/sparse_gp.hpp +++ b/include/albatross/src/models/sparse_gp.hpp @@ -315,6 +315,7 @@ class SparseGaussianProcessRegression } B.bottomRows(n_new) = A_ldlt.sqrt_solve(K_fu); const auto B_qr = B.colPivHouseholderQr(); + ALBATROSS_ASSERT(B_qr.rank() == B_qr.cols()); // Form: // y_aug = |R_old P_old^T v_old| @@ -379,8 +380,9 @@ class SparseGaussianProcessRegression compute_internal_components(u, features, targets, &A_ldlt, &K_uu_ldlt, &K_fu, &y); const auto B_qr = compute_sigma_qr(K_uu_ldlt, A_ldlt, K_fu); + ALBATROSS_ASSERT(B_qr.rank() == B_qr.cols()); - Eigen::VectorXd y_augmented = Eigen::VectorXd::Zero(B_qr.matrixR().rows()); + Eigen::VectorXd y_augmented = Eigen::VectorXd::Zero(B_qr.rows()); if (Base::use_async_) { y_augmented.topRows(y.size()) = A_ldlt.async_sqrt_solve(y); } else { diff --git a/include/albatross/src/utils/linalg_utils.hpp b/include/albatross/src/utils/linalg_utils.hpp index 78de0214..be0102f7 100644 --- a/include/albatross/src/utils/linalg_utils.hpp +++ b/include/albatross/src/utils/linalg_utils.hpp @@ -20,8 +20,10 @@ get_R(const Eigen::ColPivHouseholderQR &qr) { // Unfortunately the matrixR() method in Eigen's QR decomposition isn't // actually the R matrix, it's tall skinny matrix whose lower trapezoid // contains internal data, only the upper triangular portion is useful + // + // https://eigen.tuxfamily.org/dox/classEigen_1_1ColPivHouseholderQR.html#abe18678c6af88786f2902eeaf2483251 return qr.matrixR() - .topRows(qr.matrixR().cols()) + .topLeftCorner(qr.rank(), qr.rank()) .template triangularView(); } @@ -32,7 +34,9 @@ template inline Eigen::MatrixXd sqrt_solve(const Eigen::MatrixXd &R, const Eigen::VectorXi &permutation_indices, const MatrixType &rhs) { - + // If `R` is not full-rank, the solve operation below isn't + // well-defined. + ALBATROSS_ASSERT(R.rows() == rhs.rows()); Eigen::MatrixXd sqrt(rhs.rows(), rhs.cols()); for (Eigen::Index i = 0; i < permutation_indices.size(); ++i) { sqrt.row(i) = rhs.row(permutation_indices.coeff(i));