JacobiSVD_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  * Singular Value Decomposition - SVD.
30  ********************************************************************************
31 */
32 
33 #ifndef EIGEN_JACOBISVD_MKL_H
34 #define EIGEN_JACOBISVD_MKL_H
35 
37 
38 namespace Eigen {
39 
42 #define EIGEN_MKL_SVD(EIGTYPE, MKLTYPE, MKLRTYPE, MKLPREFIX, EIGCOLROW, MKLCOLROW) \
43 template<> inline \
44 JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>& \
45 JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>::compute(const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix, unsigned int computationOptions) \
46 { \
47  typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
48  typedef MatrixType::Scalar Scalar; \
49  typedef MatrixType::RealScalar RealScalar; \
50  allocate(matrix.rows(), matrix.cols(), computationOptions); \
51 \
52  /*const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();*/ \
53  m_nonzeroSingularValues = m_diagSize; \
54 \
55  lapack_int lda = matrix.outerStride(), ldu, ldvt; \
56  lapack_int matrix_order = MKLCOLROW; \
57  char jobu, jobvt; \
58  MKLTYPE *u, *vt, dummy; \
59  jobu = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \
60  jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \
61  if (computeU()) { \
62  ldu = m_matrixU.outerStride(); \
63  u = (MKLTYPE*)m_matrixU.data(); \
64  } else { ldu=1; u=&dummy; }\
65  MatrixType localV; \
66  ldvt = (m_computeFullV) ? m_cols : (m_computeThinV) ? m_diagSize : 1; \
67  if (computeV()) { \
68  localV.resize(ldvt, m_cols); \
69  vt = (MKLTYPE*)localV.data(); \
70  } else { ldvt=1; vt=&dummy; }\
71  Matrix<MKLRTYPE, Dynamic, Dynamic> superb; superb.resize(m_diagSize, 1); \
72  MatrixType m_temp; m_temp = matrix; \
73  LAPACKE_##MKLPREFIX##gesvd( matrix_order, jobu, jobvt, m_rows, m_cols, (MKLTYPE*)m_temp.data(), lda, (MKLRTYPE*)m_singularValues.data(), u, ldu, vt, ldvt, superb.data()); \
74  if (computeV()) m_matrixV = localV.adjoint(); \
75  /* for(int i=0;i<m_diagSize;i++) if (m_singularValues.coeffRef(i) < precision) { m_nonzeroSingularValues--; m_singularValues.coeffRef(i)=RealScalar(0);}*/ \
76  m_isInitialized = true; \
77  return *this; \
78 }
79 
80 EIGEN_MKL_SVD(double, double, double, d, ColMajor, LAPACK_COL_MAJOR)
81 EIGEN_MKL_SVD(float, float, float , s, ColMajor, LAPACK_COL_MAJOR)
82 EIGEN_MKL_SVD(dcomplex, MKL_Complex16, double, z, ColMajor, LAPACK_COL_MAJOR)
83 EIGEN_MKL_SVD(scomplex, MKL_Complex8, float , c, ColMajor, LAPACK_COL_MAJOR)
84 
85 EIGEN_MKL_SVD(double, double, double, d, RowMajor, LAPACK_ROW_MAJOR)
86 EIGEN_MKL_SVD(float, float, float , s, RowMajor, LAPACK_ROW_MAJOR)
87 EIGEN_MKL_SVD(dcomplex, MKL_Complex16, double, z, RowMajor, LAPACK_ROW_MAJOR)
88 EIGEN_MKL_SVD(scomplex, MKL_Complex8, float , c, RowMajor, LAPACK_ROW_MAJOR)
89 
90 } // end namespace Eigen
91 
92 #endif // EIGEN_JACOBISVD_MKL_H
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
#define EIGEN_MKL_SVD(EIGTYPE, MKLTYPE, MKLRTYPE, MKLPREFIX, EIGCOLROW, MKLCOLROW)
Definition: JacobiSVD_MKL.h:42


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