Eigne Matrix Class Library
Dependents: MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more
src/QR/ColPivHouseholderQR_MKL.h@0:13a5d365ba16, 2016-10-13 (annotated)
- Committer:
- ykuroda
- Date:
- Thu Oct 13 04:07:23 2016 +0000
- Revision:
- 0:13a5d365ba16
First commint, Eigne Matrix Class Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ykuroda | 0:13a5d365ba16 | 1 | /* |
ykuroda | 0:13a5d365ba16 | 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. |
ykuroda | 0:13a5d365ba16 | 3 | |
ykuroda | 0:13a5d365ba16 | 4 | Redistribution and use in source and binary forms, with or without modification, |
ykuroda | 0:13a5d365ba16 | 5 | are permitted provided that the following conditions are met: |
ykuroda | 0:13a5d365ba16 | 6 | |
ykuroda | 0:13a5d365ba16 | 7 | * Redistributions of source code must retain the above copyright notice, this |
ykuroda | 0:13a5d365ba16 | 8 | list of conditions and the following disclaimer. |
ykuroda | 0:13a5d365ba16 | 9 | * Redistributions in binary form must reproduce the above copyright notice, |
ykuroda | 0:13a5d365ba16 | 10 | this list of conditions and the following disclaimer in the documentation |
ykuroda | 0:13a5d365ba16 | 11 | and/or other materials provided with the distribution. |
ykuroda | 0:13a5d365ba16 | 12 | * Neither the name of Intel Corporation nor the names of its contributors may |
ykuroda | 0:13a5d365ba16 | 13 | be used to endorse or promote products derived from this software without |
ykuroda | 0:13a5d365ba16 | 14 | specific prior written permission. |
ykuroda | 0:13a5d365ba16 | 15 | |
ykuroda | 0:13a5d365ba16 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
ykuroda | 0:13a5d365ba16 | 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
ykuroda | 0:13a5d365ba16 | 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ykuroda | 0:13a5d365ba16 | 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
ykuroda | 0:13a5d365ba16 | 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
ykuroda | 0:13a5d365ba16 | 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
ykuroda | 0:13a5d365ba16 | 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
ykuroda | 0:13a5d365ba16 | 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
ykuroda | 0:13a5d365ba16 | 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
ykuroda | 0:13a5d365ba16 | 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ykuroda | 0:13a5d365ba16 | 26 | |
ykuroda | 0:13a5d365ba16 | 27 | ******************************************************************************** |
ykuroda | 0:13a5d365ba16 | 28 | * Content : Eigen bindings to Intel(R) MKL |
ykuroda | 0:13a5d365ba16 | 29 | * Householder QR decomposition of a matrix with column pivoting based on |
ykuroda | 0:13a5d365ba16 | 30 | * LAPACKE_?geqp3 function. |
ykuroda | 0:13a5d365ba16 | 31 | ******************************************************************************** |
ykuroda | 0:13a5d365ba16 | 32 | */ |
ykuroda | 0:13a5d365ba16 | 33 | |
ykuroda | 0:13a5d365ba16 | 34 | #ifndef EIGEN_COLPIVOTINGHOUSEHOLDERQR_MKL_H |
ykuroda | 0:13a5d365ba16 | 35 | #define EIGEN_COLPIVOTINGHOUSEHOLDERQR_MKL_H |
ykuroda | 0:13a5d365ba16 | 36 | |
ykuroda | 0:13a5d365ba16 | 37 | #include "Eigen/src/Core/util/MKL_support.h" |
ykuroda | 0:13a5d365ba16 | 38 | |
ykuroda | 0:13a5d365ba16 | 39 | namespace Eigen { |
ykuroda | 0:13a5d365ba16 | 40 | |
ykuroda | 0:13a5d365ba16 | 41 | /** \internal Specialization for the data types supported by MKL */ |
ykuroda | 0:13a5d365ba16 | 42 | |
ykuroda | 0:13a5d365ba16 | 43 | #define EIGEN_MKL_QR_COLPIV(EIGTYPE, MKLTYPE, MKLPREFIX, EIGCOLROW, MKLCOLROW) \ |
ykuroda | 0:13a5d365ba16 | 44 | template<> inline \ |
ykuroda | 0:13a5d365ba16 | 45 | ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >& \ |
ykuroda | 0:13a5d365ba16 | 46 | ColPivHouseholderQR<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> >::compute( \ |
ykuroda | 0:13a5d365ba16 | 47 | const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix) \ |
ykuroda | 0:13a5d365ba16 | 48 | \ |
ykuroda | 0:13a5d365ba16 | 49 | { \ |
ykuroda | 0:13a5d365ba16 | 50 | using std::abs; \ |
ykuroda | 0:13a5d365ba16 | 51 | typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \ |
ykuroda | 0:13a5d365ba16 | 52 | typedef MatrixType::RealScalar RealScalar; \ |
ykuroda | 0:13a5d365ba16 | 53 | Index rows = matrix.rows();\ |
ykuroda | 0:13a5d365ba16 | 54 | Index cols = matrix.cols();\ |
ykuroda | 0:13a5d365ba16 | 55 | Index size = matrix.diagonalSize();\ |
ykuroda | 0:13a5d365ba16 | 56 | \ |
ykuroda | 0:13a5d365ba16 | 57 | m_qr = matrix;\ |
ykuroda | 0:13a5d365ba16 | 58 | m_hCoeffs.resize(size);\ |
ykuroda | 0:13a5d365ba16 | 59 | \ |
ykuroda | 0:13a5d365ba16 | 60 | m_colsTranspositions.resize(cols);\ |
ykuroda | 0:13a5d365ba16 | 61 | /*Index number_of_transpositions = 0;*/ \ |
ykuroda | 0:13a5d365ba16 | 62 | \ |
ykuroda | 0:13a5d365ba16 | 63 | m_nonzero_pivots = 0; \ |
ykuroda | 0:13a5d365ba16 | 64 | m_maxpivot = RealScalar(0);\ |
ykuroda | 0:13a5d365ba16 | 65 | m_colsPermutation.resize(cols); \ |
ykuroda | 0:13a5d365ba16 | 66 | m_colsPermutation.indices().setZero(); \ |
ykuroda | 0:13a5d365ba16 | 67 | \ |
ykuroda | 0:13a5d365ba16 | 68 | lapack_int lda = m_qr.outerStride(), i; \ |
ykuroda | 0:13a5d365ba16 | 69 | lapack_int matrix_order = MKLCOLROW; \ |
ykuroda | 0:13a5d365ba16 | 70 | LAPACKE_##MKLPREFIX##geqp3( matrix_order, rows, cols, (MKLTYPE*)m_qr.data(), lda, (lapack_int*)m_colsPermutation.indices().data(), (MKLTYPE*)m_hCoeffs.data()); \ |
ykuroda | 0:13a5d365ba16 | 71 | m_isInitialized = true; \ |
ykuroda | 0:13a5d365ba16 | 72 | m_maxpivot=m_qr.diagonal().cwiseAbs().maxCoeff(); \ |
ykuroda | 0:13a5d365ba16 | 73 | m_hCoeffs.adjointInPlace(); \ |
ykuroda | 0:13a5d365ba16 | 74 | RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); \ |
ykuroda | 0:13a5d365ba16 | 75 | lapack_int *perm = m_colsPermutation.indices().data(); \ |
ykuroda | 0:13a5d365ba16 | 76 | for(i=0;i<size;i++) { \ |
ykuroda | 0:13a5d365ba16 | 77 | m_nonzero_pivots += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);\ |
ykuroda | 0:13a5d365ba16 | 78 | } \ |
ykuroda | 0:13a5d365ba16 | 79 | for(i=0;i<cols;i++) perm[i]--;\ |
ykuroda | 0:13a5d365ba16 | 80 | \ |
ykuroda | 0:13a5d365ba16 | 81 | /*m_det_pq = (number_of_transpositions%2) ? -1 : 1; // TODO: It's not needed now; fix upon availability in Eigen */ \ |
ykuroda | 0:13a5d365ba16 | 82 | \ |
ykuroda | 0:13a5d365ba16 | 83 | return *this; \ |
ykuroda | 0:13a5d365ba16 | 84 | } |
ykuroda | 0:13a5d365ba16 | 85 | |
ykuroda | 0:13a5d365ba16 | 86 | EIGEN_MKL_QR_COLPIV(double, double, d, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 87 | EIGEN_MKL_QR_COLPIV(float, float, s, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 88 | EIGEN_MKL_QR_COLPIV(dcomplex, MKL_Complex16, z, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 89 | EIGEN_MKL_QR_COLPIV(scomplex, MKL_Complex8, c, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 90 | |
ykuroda | 0:13a5d365ba16 | 91 | EIGEN_MKL_QR_COLPIV(double, double, d, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 92 | EIGEN_MKL_QR_COLPIV(float, float, s, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 93 | EIGEN_MKL_QR_COLPIV(dcomplex, MKL_Complex16, z, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 94 | EIGEN_MKL_QR_COLPIV(scomplex, MKL_Complex8, c, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 95 | |
ykuroda | 0:13a5d365ba16 | 96 | } // end namespace Eigen |
ykuroda | 0:13a5d365ba16 | 97 | |
ykuroda | 0:13a5d365ba16 | 98 | #endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_MKL_H |