File indexing completed on 2025-04-19 09:06:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
0035 #define EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
0036
0037 namespace RivetEigen {
0038
0039
0040
0041 #define EIGEN_LAPACKE_QR_COLPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \
0042 template<> template<typename InputType> inline \
0043 ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >& \
0044 ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >::compute( \
0045 const EigenBase<InputType>& matrix) \
0046 \
0047 { \
0048 using std::abs; \
0049 typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
0050 typedef MatrixType::RealScalar RealScalar; \
0051 Index rows = matrix.rows();\
0052 Index cols = matrix.cols();\
0053 \
0054 m_qr = matrix;\
0055 Index size = m_qr.diagonalSize();\
0056 m_hCoeffs.resize(size);\
0057 \
0058 m_colsTranspositions.resize(cols);\
0059 \
0060 \
0061 m_nonzero_pivots = 0; \
0062 m_maxpivot = RealScalar(0);\
0063 m_colsPermutation.resize(cols); \
0064 m_colsPermutation.indices().setZero(); \
0065 \
0066 lapack_int lda = internal::convert_index<lapack_int,Index>(m_qr.outerStride()); \
0067 lapack_int matrix_order = LAPACKE_COLROW; \
0068 LAPACKE_##LAPACKE_PREFIX##geqp3( matrix_order, internal::convert_index<lapack_int,Index>(rows), internal::convert_index<lapack_int,Index>(cols), \
0069 (LAPACKE_TYPE*)m_qr.data(), lda, (lapack_int*)m_colsPermutation.indices().data(), (LAPACKE_TYPE*)m_hCoeffs.data()); \
0070 m_isInitialized = true; \
0071 m_maxpivot=m_qr.diagonal().cwiseAbs().maxCoeff(); \
0072 m_hCoeffs.adjointInPlace(); \
0073 RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); \
0074 lapack_int *perm = m_colsPermutation.indices().data(); \
0075 for(Index i=0;i<size;i++) { \
0076 m_nonzero_pivots += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);\
0077 } \
0078 for(Index i=0;i<cols;i++) perm[i]--;\
0079 \
0080 \
0081 \
0082 return *this; \
0083 }
0084
0085 EIGEN_LAPACKE_QR_COLPIV(double, double, d, ColMajor, LAPACK_COL_MAJOR)
0086 EIGEN_LAPACKE_QR_COLPIV(float, float, s, ColMajor, LAPACK_COL_MAJOR)
0087 EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, ColMajor, LAPACK_COL_MAJOR)
0088 EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float, c, ColMajor, LAPACK_COL_MAJOR)
0089
0090 EIGEN_LAPACKE_QR_COLPIV(double, double, d, RowMajor, LAPACK_ROW_MAJOR)
0091 EIGEN_LAPACKE_QR_COLPIV(float, float, s, RowMajor, LAPACK_ROW_MAJOR)
0092 EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, RowMajor, LAPACK_ROW_MAJOR)
0093 EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float, c, RowMajor, LAPACK_ROW_MAJOR)
0094
0095 }
0096
0097 #endif