JacobiSVD_LAPACKE.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 LAPACKe
29  * Singular Value Decomposition - SVD.
30  ********************************************************************************
31 */
32 
33 #ifndef EIGEN_JACOBISVD_LAPACKE_H
34 #define EIGEN_JACOBISVD_LAPACKE_H
35 
36 namespace Eigen {
37 
40 #define EIGEN_LAPACKE_SVD(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \
41 template<> inline \
42 JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>& \
43 JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>::compute(const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix, unsigned int computationOptions) \
44 { \
45  typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
46  /*typedef MatrixType::Scalar Scalar;*/ \
47  /*typedef MatrixType::RealScalar RealScalar;*/ \
48  allocate(matrix.rows(), matrix.cols(), computationOptions); \
49 \
50  /*const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();*/ \
51  m_nonzeroSingularValues = m_diagSize; \
52 \
53  lapack_int lda = internal::convert_index<lapack_int>(matrix.outerStride()), ldu, ldvt; \
54  lapack_int matrix_order = LAPACKE_COLROW; \
55  char jobu, jobvt; \
56  LAPACKE_TYPE *u, *vt, dummy; \
57  jobu = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \
58  jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \
59  if (computeU()) { \
60  ldu = internal::convert_index<lapack_int>(m_matrixU.outerStride()); \
61  u = (LAPACKE_TYPE*)m_matrixU.data(); \
62  } else { ldu=1; u=&dummy; }\
63  MatrixType localV; \
64  lapack_int vt_rows = (m_computeFullV) ? internal::convert_index<lapack_int>(m_cols) : (m_computeThinV) ? internal::convert_index<lapack_int>(m_diagSize) : 1; \
65  if (computeV()) { \
66  localV.resize(vt_rows, m_cols); \
67  ldvt = internal::convert_index<lapack_int>(localV.outerStride()); \
68  vt = (LAPACKE_TYPE*)localV.data(); \
69  } else { ldvt=1; vt=&dummy; }\
70  Matrix<LAPACKE_RTYPE, Dynamic, Dynamic> superb; superb.resize(m_diagSize, 1); \
71  MatrixType m_temp; m_temp = matrix; \
72  LAPACKE_##LAPACKE_PREFIX##gesvd( matrix_order, jobu, jobvt, internal::convert_index<lapack_int>(m_rows), internal::convert_index<lapack_int>(m_cols), (LAPACKE_TYPE*)m_temp.data(), lda, (LAPACKE_RTYPE*)m_singularValues.data(), u, ldu, vt, ldvt, superb.data()); \
73  if (computeV()) m_matrixV = localV.adjoint(); \
74  /* for(int i=0;i<m_diagSize;i++) if (m_singularValues.coeffRef(i) < precision) { m_nonzeroSingularValues--; m_singularValues.coeffRef(i)=RealScalar(0);}*/ \
75  m_isInitialized = true; \
76  return *this; \
77 }
78 
79 EIGEN_LAPACKE_SVD(double, double, double, d, ColMajor, LAPACK_COL_MAJOR)
80 EIGEN_LAPACKE_SVD(float, float, float , s, ColMajor, LAPACK_COL_MAJOR)
83 
84 EIGEN_LAPACKE_SVD(double, double, double, d, RowMajor, LAPACK_ROW_MAJOR)
85 EIGEN_LAPACKE_SVD(float, float, float , s, RowMajor, LAPACK_ROW_MAJOR)
86 EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, RowMajor, LAPACK_ROW_MAJOR)
87 EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float, float , c, RowMajor, LAPACK_ROW_MAJOR)
88 
89 } // end namespace Eigen
90 
91 #endif // EIGEN_JACOBISVD_LAPACKE_H
#define lapack_complex_float
Definition: lapacke.h:80
#define LAPACK_COL_MAJOR
Definition: lapacke.h:122
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
std::complex< float > scomplex
Definition: MKL_support.h:119
std::complex< double > dcomplex
Definition: MKL_support.h:118
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:121
RealScalar s
#define EIGEN_LAPACKE_SVD(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW)
#define lapack_complex_double
Definition: lapacke.h:96


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:26