Eigne Matrix Class Library
Dependents: MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more
src/SVD/JacobiSVD_MKL.h@0:13a5d365ba16, 2016-10-13 (annotated)
- Committer:
- ykuroda
- Date:
- Thu Oct 13 04:07:23 2016 +0000
- Revision:
- 0:13a5d365ba16
First commint, Eigne Matrix Class Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ykuroda | 0:13a5d365ba16 | 1 | /* |
ykuroda | 0:13a5d365ba16 | 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. |
ykuroda | 0:13a5d365ba16 | 3 | |
ykuroda | 0:13a5d365ba16 | 4 | Redistribution and use in source and binary forms, with or without modification, |
ykuroda | 0:13a5d365ba16 | 5 | are permitted provided that the following conditions are met: |
ykuroda | 0:13a5d365ba16 | 6 | |
ykuroda | 0:13a5d365ba16 | 7 | * Redistributions of source code must retain the above copyright notice, this |
ykuroda | 0:13a5d365ba16 | 8 | list of conditions and the following disclaimer. |
ykuroda | 0:13a5d365ba16 | 9 | * Redistributions in binary form must reproduce the above copyright notice, |
ykuroda | 0:13a5d365ba16 | 10 | this list of conditions and the following disclaimer in the documentation |
ykuroda | 0:13a5d365ba16 | 11 | and/or other materials provided with the distribution. |
ykuroda | 0:13a5d365ba16 | 12 | * Neither the name of Intel Corporation nor the names of its contributors may |
ykuroda | 0:13a5d365ba16 | 13 | be used to endorse or promote products derived from this software without |
ykuroda | 0:13a5d365ba16 | 14 | specific prior written permission. |
ykuroda | 0:13a5d365ba16 | 15 | |
ykuroda | 0:13a5d365ba16 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
ykuroda | 0:13a5d365ba16 | 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
ykuroda | 0:13a5d365ba16 | 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ykuroda | 0:13a5d365ba16 | 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
ykuroda | 0:13a5d365ba16 | 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
ykuroda | 0:13a5d365ba16 | 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
ykuroda | 0:13a5d365ba16 | 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
ykuroda | 0:13a5d365ba16 | 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
ykuroda | 0:13a5d365ba16 | 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
ykuroda | 0:13a5d365ba16 | 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ykuroda | 0:13a5d365ba16 | 26 | |
ykuroda | 0:13a5d365ba16 | 27 | ******************************************************************************** |
ykuroda | 0:13a5d365ba16 | 28 | * Content : Eigen bindings to Intel(R) MKL |
ykuroda | 0:13a5d365ba16 | 29 | * Singular Value Decomposition - SVD. |
ykuroda | 0:13a5d365ba16 | 30 | ******************************************************************************** |
ykuroda | 0:13a5d365ba16 | 31 | */ |
ykuroda | 0:13a5d365ba16 | 32 | |
ykuroda | 0:13a5d365ba16 | 33 | #ifndef EIGEN_JACOBISVD_MKL_H |
ykuroda | 0:13a5d365ba16 | 34 | #define EIGEN_JACOBISVD_MKL_H |
ykuroda | 0:13a5d365ba16 | 35 | |
ykuroda | 0:13a5d365ba16 | 36 | #include "Eigen/src/Core/util/MKL_support.h" |
ykuroda | 0:13a5d365ba16 | 37 | |
ykuroda | 0:13a5d365ba16 | 38 | namespace Eigen { |
ykuroda | 0:13a5d365ba16 | 39 | |
ykuroda | 0:13a5d365ba16 | 40 | /** \internal Specialization for the data types supported by MKL */ |
ykuroda | 0:13a5d365ba16 | 41 | |
ykuroda | 0:13a5d365ba16 | 42 | #define EIGEN_MKL_SVD(EIGTYPE, MKLTYPE, MKLRTYPE, MKLPREFIX, EIGCOLROW, MKLCOLROW) \ |
ykuroda | 0:13a5d365ba16 | 43 | template<> inline \ |
ykuroda | 0:13a5d365ba16 | 44 | JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>& \ |
ykuroda | 0:13a5d365ba16 | 45 | JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>::compute(const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix, unsigned int computationOptions) \ |
ykuroda | 0:13a5d365ba16 | 46 | { \ |
ykuroda | 0:13a5d365ba16 | 47 | typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \ |
ykuroda | 0:13a5d365ba16 | 48 | /*typedef MatrixType::Scalar Scalar;*/ \ |
ykuroda | 0:13a5d365ba16 | 49 | /*typedef MatrixType::RealScalar RealScalar;*/ \ |
ykuroda | 0:13a5d365ba16 | 50 | allocate(matrix.rows(), matrix.cols(), computationOptions); \ |
ykuroda | 0:13a5d365ba16 | 51 | \ |
ykuroda | 0:13a5d365ba16 | 52 | /*const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();*/ \ |
ykuroda | 0:13a5d365ba16 | 53 | m_nonzeroSingularValues = m_diagSize; \ |
ykuroda | 0:13a5d365ba16 | 54 | \ |
ykuroda | 0:13a5d365ba16 | 55 | lapack_int lda = matrix.outerStride(), ldu, ldvt; \ |
ykuroda | 0:13a5d365ba16 | 56 | lapack_int matrix_order = MKLCOLROW; \ |
ykuroda | 0:13a5d365ba16 | 57 | char jobu, jobvt; \ |
ykuroda | 0:13a5d365ba16 | 58 | MKLTYPE *u, *vt, dummy; \ |
ykuroda | 0:13a5d365ba16 | 59 | jobu = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \ |
ykuroda | 0:13a5d365ba16 | 60 | jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \ |
ykuroda | 0:13a5d365ba16 | 61 | if (computeU()) { \ |
ykuroda | 0:13a5d365ba16 | 62 | ldu = m_matrixU.outerStride(); \ |
ykuroda | 0:13a5d365ba16 | 63 | u = (MKLTYPE*)m_matrixU.data(); \ |
ykuroda | 0:13a5d365ba16 | 64 | } else { ldu=1; u=&dummy; }\ |
ykuroda | 0:13a5d365ba16 | 65 | MatrixType localV; \ |
ykuroda | 0:13a5d365ba16 | 66 | ldvt = (m_computeFullV) ? m_cols : (m_computeThinV) ? m_diagSize : 1; \ |
ykuroda | 0:13a5d365ba16 | 67 | if (computeV()) { \ |
ykuroda | 0:13a5d365ba16 | 68 | localV.resize(ldvt, m_cols); \ |
ykuroda | 0:13a5d365ba16 | 69 | vt = (MKLTYPE*)localV.data(); \ |
ykuroda | 0:13a5d365ba16 | 70 | } else { ldvt=1; vt=&dummy; }\ |
ykuroda | 0:13a5d365ba16 | 71 | Matrix<MKLRTYPE, Dynamic, Dynamic> superb; superb.resize(m_diagSize, 1); \ |
ykuroda | 0:13a5d365ba16 | 72 | MatrixType m_temp; m_temp = matrix; \ |
ykuroda | 0:13a5d365ba16 | 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()); \ |
ykuroda | 0:13a5d365ba16 | 74 | if (computeV()) m_matrixV = localV.adjoint(); \ |
ykuroda | 0:13a5d365ba16 | 75 | /* for(int i=0;i<m_diagSize;i++) if (m_singularValues.coeffRef(i) < precision) { m_nonzeroSingularValues--; m_singularValues.coeffRef(i)=RealScalar(0);}*/ \ |
ykuroda | 0:13a5d365ba16 | 76 | m_isInitialized = true; \ |
ykuroda | 0:13a5d365ba16 | 77 | return *this; \ |
ykuroda | 0:13a5d365ba16 | 78 | } |
ykuroda | 0:13a5d365ba16 | 79 | |
ykuroda | 0:13a5d365ba16 | 80 | EIGEN_MKL_SVD(double, double, double, d, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 81 | EIGEN_MKL_SVD(float, float, float , s, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 82 | EIGEN_MKL_SVD(dcomplex, MKL_Complex16, double, z, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 83 | EIGEN_MKL_SVD(scomplex, MKL_Complex8, float , c, ColMajor, LAPACK_COL_MAJOR) |
ykuroda | 0:13a5d365ba16 | 84 | |
ykuroda | 0:13a5d365ba16 | 85 | EIGEN_MKL_SVD(double, double, double, d, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 86 | EIGEN_MKL_SVD(float, float, float , s, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 87 | EIGEN_MKL_SVD(dcomplex, MKL_Complex16, double, z, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 88 | EIGEN_MKL_SVD(scomplex, MKL_Complex8, float , c, RowMajor, LAPACK_ROW_MAJOR) |
ykuroda | 0:13a5d365ba16 | 89 | |
ykuroda | 0:13a5d365ba16 | 90 | } // end namespace Eigen |
ykuroda | 0:13a5d365ba16 | 91 | |
ykuroda | 0:13a5d365ba16 | 92 | #endif // EIGEN_JACOBISVD_MKL_H |