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