ColPivHouseholderQR_MKL.h
Go to the documentation of this file.
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 
38 
39 namespace Eigen {
40 
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  using std::abs; \
51  typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
52  typedef MatrixType::Scalar Scalar; \
53  typedef MatrixType::RealScalar RealScalar; \
54  Index rows = matrix.rows();\
55  Index cols = matrix.cols();\
56  Index size = matrix.diagonalSize();\
57 \
58  m_qr = matrix;\
59  m_hCoeffs.resize(size);\
60 \
61  m_colsTranspositions.resize(cols);\
62  /*Index number_of_transpositions = 0;*/ \
63 \
64  m_nonzero_pivots = 0; \
65  m_maxpivot = RealScalar(0);\
66  m_colsPermutation.resize(cols); \
67  m_colsPermutation.indices().setZero(); \
68 \
69  lapack_int lda = m_qr.outerStride(), i; \
70  lapack_int matrix_order = MKLCOLROW; \
71  LAPACKE_##MKLPREFIX##geqp3( matrix_order, rows, cols, (MKLTYPE*)m_qr.data(), lda, (lapack_int*)m_colsPermutation.indices().data(), (MKLTYPE*)m_hCoeffs.data()); \
72  m_isInitialized = true; \
73  m_maxpivot=m_qr.diagonal().cwiseAbs().maxCoeff(); \
74  m_hCoeffs.adjointInPlace(); \
75  RealScalar premultiplied_threshold = abs(m_maxpivot) * threshold(); \
76  lapack_int *perm = m_colsPermutation.indices().data(); \
77  for(i=0;i<size;i++) { \
78  m_nonzero_pivots += (abs(m_qr.coeff(i,i)) > premultiplied_threshold);\
79  } \
80  for(i=0;i<cols;i++) perm[i]--;\
81 \
82  /*m_det_pq = (number_of_transpositions%2) ? -1 : 1; // TODO: It's not needed now; fix upon availability in Eigen */ \
83 \
84  return *this; \
85 }
86 
87 EIGEN_MKL_QR_COLPIV(double, double, d, ColMajor, LAPACK_COL_MAJOR)
88 EIGEN_MKL_QR_COLPIV(float, float, s, ColMajor, LAPACK_COL_MAJOR)
89 EIGEN_MKL_QR_COLPIV(dcomplex, MKL_Complex16, z, ColMajor, LAPACK_COL_MAJOR)
90 EIGEN_MKL_QR_COLPIV(scomplex, MKL_Complex8, c, ColMajor, LAPACK_COL_MAJOR)
91 
92 EIGEN_MKL_QR_COLPIV(double, double, d, RowMajor, LAPACK_ROW_MAJOR)
93 EIGEN_MKL_QR_COLPIV(float, float, s, RowMajor, LAPACK_ROW_MAJOR)
94 EIGEN_MKL_QR_COLPIV(dcomplex, MKL_Complex16, z, RowMajor, LAPACK_ROW_MAJOR)
95 EIGEN_MKL_QR_COLPIV(scomplex, MKL_Complex8, c, RowMajor, LAPACK_ROW_MAJOR)
96 
97 } // end namespace Eigen
98 
99 #endif // EIGEN_COLPIVOTINGHOUSEHOLDERQR_MKL_H
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
#define EIGEN_MKL_QR_COLPIV(EIGTYPE, MKLTYPE, MKLPREFIX, EIGCOLROW, MKLCOLROW)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:30