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 * Self-adjoint eigenvalues/eigenvectors. 30 ******************************************************************************** 31 */ 32 33 #ifndef EIGEN_SAEIGENSOLVER_MKL_H 34 #define EIGEN_SAEIGENSOLVER_MKL_H 35 36 #include "Eigen/src/Core/util/MKL_support.h" 37 38 namespace Eigen { 39 40 /** \internal Specialization for the data types supported by MKL */ 41 42 #define EIGEN_MKL_EIG_SELFADJ(EIGTYPE, MKLTYPE, MKLRTYPE, MKLNAME, EIGCOLROW, MKLCOLROW ) \ 43 template<> inline \ 44 SelfAdjointEigenSolver<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \ 45 SelfAdjointEigenSolver<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW>& matrix, int options) \ 46 { \ 47 eigen_assert(matrix.cols() == matrix.rows()); \ 48 eigen_assert((options&~(EigVecMask|GenEigMask))==0 \ 49 && (options&EigVecMask)!=EigVecMask \ 50 && "invalid option parameter"); \ 51 bool computeEigenvectors = (options&ComputeEigenvectors)==ComputeEigenvectors; \ 52 lapack_int n = matrix.cols(), lda, matrix_order, info; \ 53 m_eivalues.resize(n,1); \ 54 m_subdiag.resize(n-1); \ 55 m_eivec = matrix; \ 56 \ 57 if(n==1) \ 58 { \ 59 m_eivalues.coeffRef(0,0) = numext::real(matrix.coeff(0,0)); \ 60 if(computeEigenvectors) m_eivec.setOnes(n,n); \ 61 m_info = Success; \ 62 m_isInitialized = true; \ 63 m_eigenvectorsOk = computeEigenvectors; \ 64 return *this; \ 65 } \ 66 \ 67 lda = matrix.outerStride(); \ 68 matrix_order=MKLCOLROW; \ 69 char jobz, uplo='L'/*, range='A'*/; \ 70 jobz = computeEigenvectors ? 'V' : 'N'; \ 71 \ 72 info = LAPACKE_##MKLNAME( matrix_order, jobz, uplo, n, (MKLTYPE*)m_eivec.data(), lda, (MKLRTYPE*)m_eivalues.data() ); \ 73 m_info = (info==0) ? Success : NoConvergence; \ 74 m_isInitialized = true; \ 75 m_eigenvectorsOk = computeEigenvectors; \ 76 return *this; \ 77 } 78 79 80 EIGEN_MKL_EIG_SELFADJ(double, double, double, dsyev, ColMajor, LAPACK_COL_MAJOR) 81 EIGEN_MKL_EIG_SELFADJ(float, float, float, ssyev, ColMajor, LAPACK_COL_MAJOR) 82 EIGEN_MKL_EIG_SELFADJ(dcomplex, MKL_Complex16, double, zheev, ColMajor, LAPACK_COL_MAJOR) 83 EIGEN_MKL_EIG_SELFADJ(scomplex, MKL_Complex8, float, cheev, ColMajor, LAPACK_COL_MAJOR) 84 85 EIGEN_MKL_EIG_SELFADJ(double, double, double, dsyev, RowMajor, LAPACK_ROW_MAJOR) 86 EIGEN_MKL_EIG_SELFADJ(float, float, float, ssyev, RowMajor, LAPACK_ROW_MAJOR) 87 EIGEN_MKL_EIG_SELFADJ(dcomplex, MKL_Complex16, double, zheev, RowMajor, LAPACK_ROW_MAJOR) 88 EIGEN_MKL_EIG_SELFADJ(scomplex, MKL_Complex8, float, cheev, RowMajor, LAPACK_ROW_MAJOR) 89 90 } // end namespace Eigen 91 92 #endif // EIGEN_SAEIGENSOLVER_H 93