Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
JacobiSVD_LAPACKE.h
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// IWYU pragma: private
37#include "./InternalHeaderCheck.h"
38
39namespace Eigen {
40
43#define EIGEN_LAPACKE_SVD(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW, OPTIONS) \
44 template <> \
45 inline JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, OPTIONS>& \
46 JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, OPTIONS>::compute_impl( \
47 const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix, unsigned int computationOptions) { \
48 typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
49 /*typedef MatrixType::Scalar Scalar;*/ \
50 /*typedef MatrixType::RealScalar RealScalar;*/ \
51 allocate(matrix.rows(), matrix.cols(), computationOptions); \
52 \
53 /*const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();*/ \
54 m_nonzeroSingularValues = diagSize(); \
55 \
56 lapack_int lda = internal::convert_index<lapack_int>(matrix.outerStride()), ldu, ldvt; \
57 lapack_int matrix_order = LAPACKE_COLROW; \
58 char jobu, jobvt; \
59 LAPACKE_TYPE *u, *vt, dummy; \
60 jobu = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \
61 jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \
62 if (computeU()) { \
63 ldu = internal::convert_index<lapack_int>(m_matrixU.outerStride()); \
64 u = (LAPACKE_TYPE*)m_matrixU.data(); \
65 } else { \
66 ldu = 1; \
67 u = &dummy; \
68 } \
69 MatrixType localV; \
70 lapack_int vt_rows = (m_computeFullV) ? internal::convert_index<lapack_int>(cols()) \
71 : (m_computeThinV) ? internal::convert_index<lapack_int>(diagSize()) \
72 : 1; \
73 if (computeV()) { \
74 localV.resize(vt_rows, cols()); \
75 ldvt = internal::convert_index<lapack_int>(localV.outerStride()); \
76 vt = (LAPACKE_TYPE*)localV.data(); \
77 } else { \
78 ldvt = 1; \
79 vt = &dummy; \
80 } \
81 Matrix<LAPACKE_RTYPE, Dynamic, Dynamic> superb; \
82 superb.resize(diagSize(), 1); \
83 MatrixType m_temp; \
84 m_temp = matrix; \
85 lapack_int info = LAPACKE_##LAPACKE_PREFIX##gesvd( \
86 matrix_order, jobu, jobvt, internal::convert_index<lapack_int>(rows()), \
87 internal::convert_index<lapack_int>(cols()), (LAPACKE_TYPE*)m_temp.data(), lda, \
88 (LAPACKE_RTYPE*)m_singularValues.data(), u, ldu, vt, ldvt, superb.data()); \
89 /* Check the result of the LAPACK call */ \
90 if (info < 0 || !m_singularValues.allFinite()) { \
91 m_info = InvalidInput; \
92 } else if (info > 0) { \
93 m_info = NoConvergence; \
94 } else { \
95 m_info = Success; \
96 if (computeV()) m_matrixV = localV.adjoint(); \
97 } \
98 /* for(int i=0;i<diagSize();i++) if (m_singularValues.coeffRef(i) < precision) { m_nonzeroSingularValues--; \
99 * m_singularValues.coeffRef(i)=RealScalar(0);}*/ \
100 m_isInitialized = true; \
101 return *this; \
102 }
103
104#define EIGEN_LAPACK_SVD_OPTIONS(OPTIONS) \
105 EIGEN_LAPACKE_SVD(double, double, double, d, ColMajor, LAPACK_COL_MAJOR, OPTIONS) \
106 EIGEN_LAPACKE_SVD(float, float, float, s, ColMajor, LAPACK_COL_MAJOR, OPTIONS) \
107 EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, ColMajor, LAPACK_COL_MAJOR, OPTIONS) \
108 EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float, float, c, ColMajor, LAPACK_COL_MAJOR, OPTIONS) \
109 \
110 EIGEN_LAPACKE_SVD(double, double, double, d, RowMajor, LAPACK_ROW_MAJOR, OPTIONS) \
111 EIGEN_LAPACKE_SVD(float, float, float, s, RowMajor, LAPACK_ROW_MAJOR, OPTIONS) \
112 EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, RowMajor, LAPACK_ROW_MAJOR, OPTIONS) \
113 EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float, float, c, RowMajor, LAPACK_ROW_MAJOR, OPTIONS)
114
115EIGEN_LAPACK_SVD_OPTIONS(0)
116EIGEN_LAPACK_SVD_OPTIONS(ComputeThinU)
117EIGEN_LAPACK_SVD_OPTIONS(ComputeThinV)
118EIGEN_LAPACK_SVD_OPTIONS(ComputeFullU)
119EIGEN_LAPACK_SVD_OPTIONS(ComputeFullV)
120EIGEN_LAPACK_SVD_OPTIONS(ComputeThinU | ComputeThinV)
121EIGEN_LAPACK_SVD_OPTIONS(ComputeFullU | ComputeFullV)
122EIGEN_LAPACK_SVD_OPTIONS(ComputeThinU | ComputeFullV)
123EIGEN_LAPACK_SVD_OPTIONS(ComputeFullU | ComputeThinV)
124
125} // end namespace Eigen
126
127#endif // EIGEN_JACOBISVD_LAPACKE_H
Namespace containing all symbols from the Eigen library.
Definition Core:137