Eigen  3.3.3
ColPivHouseholderQR_LAPACKE.h
00001 /*
00002  Copyright (c) 2011, Intel Corporation. All rights reserved.
00003 
00004  Redistribution and use in source and binary forms, with or without modification,
00005  are permitted provided that the following conditions are met:
00006 
00007  * Redistributions of source code must retain the above copyright notice, this
00008    list of conditions and the following disclaimer.
00009  * Redistributions in binary form must reproduce the above copyright notice,
00010    this list of conditions and the following disclaimer in the documentation
00011    and/or other materials provided with the distribution.
00012  * Neither the name of Intel Corporation nor the names of its contributors may
00013    be used to endorse or promote products derived from this software without
00014    specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00020  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00023  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027  ********************************************************************************
00028  *   Content : Eigen bindings to LAPACKe
00029  *    Householder QR decomposition of a matrix with column pivoting based on
00030  *    LAPACKE_?geqp3 function.
00031  ********************************************************************************
00032 */
00033 
00034 #ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
00035 #define EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
00036 
00037 namespace Eigen { 
00038 
00041 #define EIGEN_LAPACKE_QR_COLPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \
00042 template<> template<typename InputType> inline \
00043 ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >& \
00044 ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >::compute( \
00045               const EigenBase<InputType>& matrix) \
00046 \
00047 { \
00048   using std::abs; \
00049   typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
00050   typedef MatrixType::RealScalar RealScalar; \
00051   Index rows = matrix.rows();\
00052   Index cols = matrix.cols();\
00053 \
00054   m_qr = matrix;\
00055   Index size = m_qr.diagonalSize();\
00056   m_hCoeffs.resize(size);\
00057 \
00058   m_colsTranspositions.resize(cols);\
00059   /*Index number_of_transpositions = 0;*/ \
00060 \
00061   m_nonzero_pivots = 0; \
00062   m_maxpivot = RealScalar(0);\
00063   m_colsPermutation.resize(cols); \
00064   m_colsPermutation.indices().setZero(); \
00065 \
00066   lapack_int lda = internal::convert_index<lapack_int,Index>(m_qr.outerStride()); \
00067   lapack_int matrix_order = LAPACKE_COLROW; \
00068   LAPACKE_##LAPACKE_PREFIX##geqp3( matrix_order, internal::convert_index<lapack_int,Index>(rows), internal::convert_index<lapack_int,Index>(cols), \
00069                               (LAPACKE_TYPE*)m_qr.data(), lda, (lapack_int*)m_colsPermutation.indices().data(), (LAPACKE_TYPE*)m_hCoeffs.data()); \
00070   m_isInitialized = true; \
00071   m_maxpivot=m_qr.diagonal().cwiseAbs().maxCoeff(); \
00072   m_hCoeffs.adjointInPlace(); \
00073   RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); \
00074   lapack_int *perm = m_colsPermutation.indices().data(); \
00075   for(Index i=0;i<size;i++) { \
00076     m_nonzero_pivots += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);\
00077   } \
00078   for(Index i=0;i<cols;i++) perm[i]--;\
00079 \
00080   /*m_det_pq = (number_of_transpositions%2) ? -1 : 1;  // TODO: It's not needed now; fix upon availability in Eigen */ \
00081 \
00082   return *this; \
00083 }
00084 
00085 EIGEN_LAPACKE_QR_COLPIV(double,   double,        d, ColMajor, LAPACK_COL_MAJOR)
00086 EIGEN_LAPACKE_QR_COLPIV(float,    float,         s, ColMajor, LAPACK_COL_MAJOR)
00087 EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, ColMajor, LAPACK_COL_MAJOR)
00088 EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float,  c, ColMajor, LAPACK_COL_MAJOR)
00089 
00090 EIGEN_LAPACKE_QR_COLPIV(double,   double,        d, RowMajor, LAPACK_ROW_MAJOR)
00091 EIGEN_LAPACKE_QR_COLPIV(float,    float,         s, RowMajor, LAPACK_ROW_MAJOR)
00092 EIGEN_LAPACKE_QR_COLPIV(dcomplex, lapack_complex_double, z, RowMajor, LAPACK_ROW_MAJOR)
00093 EIGEN_LAPACKE_QR_COLPIV(scomplex, lapack_complex_float,  c, RowMajor, LAPACK_ROW_MAJOR)
00094 
00095 } // end namespace Eigen
00096 
00097 #endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_LAPACKE_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends