@@ -112,6 +112,22 @@ void cholesky_lsolve(Op transpose, Matrix<T>& A, Matrix<T>& X) {
112112 TA_LAPACK (trtrs, uplo, transpose, diag, n, nrhs, a, lda, b, ldb);
113113}
114114
115+ template <typename T>
116+ void qr_solve (Matrix<T>& A, Matrix<T>& B,
117+ const TiledArray::detail::real_t <T> cond) {
118+ integer m = A.rows ();
119+ integer n = A.cols ();
120+ integer nrhs = B.cols ();
121+ T* a = A.data ();
122+ integer lda = A.rows ();
123+ T* b = B.data ();
124+ integer ldb = B.rows ();
125+ std::vector<integer> jpiv (n);
126+ const TiledArray::detail::real_t <T> rcond = 1 / cond;
127+ integer rank = -1 ;
128+ TA_LAPACK (gelsy, m, n, nrhs, a, lda, b, ldb, jpiv.data (), rcond, &rank);
129+ }
130+
115131template <typename T>
116132void heig (Matrix<T>& A, std::vector<TiledArray::detail::real_t <T>>& W) {
117133 auto jobz = lapack::Job::Vec;
@@ -250,7 +266,7 @@ void householder_qr(Matrix<T>& V, Matrix<T>& R) {
250266 lapack::orgqr (m, n, k, v, ldv, tau.data ());
251267}
252268
253- #define TA_LAPACK_EXPLICIT (MATRIX, VECTOR ) \
269+ #define TA_LAPACK_EXPLICIT (MATRIX, VECTOR, DOUBLE ) \
254270 template void cholesky (MATRIX&); \
255271 template void cholesky_linv (MATRIX&); \
256272 template void cholesky_solve (MATRIX&, MATRIX&); \
@@ -261,11 +277,12 @@ void householder_qr(Matrix<T>& V, Matrix<T>& R) {
261277 template void lu_solve (MATRIX&, MATRIX&); \
262278 template void lu_inv (MATRIX&); \
263279 template void householder_qr<true >(MATRIX&, MATRIX&); \
264- template void householder_qr<false >(MATRIX&, MATRIX&);
280+ template void householder_qr<false >(MATRIX&, MATRIX&); \
281+ template void qr_solve (MATRIX&, MATRIX&, DOUBLE)
265282
266- TA_LAPACK_EXPLICIT (Matrix<double >, std::vector<double >);
267- TA_LAPACK_EXPLICIT (Matrix<float >, std::vector<float >);
268- TA_LAPACK_EXPLICIT (Matrix<std::complex <double >>, std::vector<double >);
269- TA_LAPACK_EXPLICIT (Matrix<std::complex <float >>, std::vector<float >);
283+ TA_LAPACK_EXPLICIT(Matrix<double >, std::vector<double >, double );
284+ TA_LAPACK_EXPLICIT (Matrix<float >, std::vector<float >, float );
285+ TA_LAPACK_EXPLICIT (Matrix<std::complex <double >>, std::vector<double >, double );
286+ TA_LAPACK_EXPLICIT (Matrix<std::complex <float >>, std::vector<float >, float );
270287
271288} // namespace TiledArray::math::linalg::rank_local
0 commit comments