Eigen  3.3.3
JacobiSVD_LAPACKE.h
00001 /*
00002  Copyright (c) 2011, Intel Corporation. All rights reserved.
00003 
00004  Redistribution and use in source and binary forms, with or without modification,
00005  are permitted provided that the following conditions are met:
00006 
00007  * Redistributions of source code must retain the above copyright notice, this
00008    list of conditions and the following disclaimer.
00009  * Redistributions in binary form must reproduce the above copyright notice,
00010    this list of conditions and the following disclaimer in the documentation
00011    and/or other materials provided with the distribution.
00012  * Neither the name of Intel Corporation nor the names of its contributors may
00013    be used to endorse or promote products derived from this software without
00014    specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00020  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00023  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027  ********************************************************************************
00028  *   Content : Eigen bindings to LAPACKe
00029  *    Singular Value Decomposition - SVD.
00030  ********************************************************************************
00031 */
00032 
00033 #ifndef EIGEN_JACOBISVD_LAPACKE_H
00034 #define EIGEN_JACOBISVD_LAPACKE_H
00035 
00036 namespace Eigen { 
00037 
00040 #define EIGEN_LAPACKE_SVD(EIGTYPE, LAPACKE_TYPE, LAPACKE_RTYPE, LAPACKE_PREFIX, EIGCOLROW, LAPACKE_COLROW) \
00041 template<> inline \
00042 JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>& \
00043 JacobiSVD<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>, ColPivHouseholderQRPreconditioner>::compute(const Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic>& matrix, unsigned int computationOptions) \
00044 { \
00045   typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW, Dynamic, Dynamic> MatrixType; \
00046   /*typedef MatrixType::Scalar Scalar;*/ \
00047   /*typedef MatrixType::RealScalar RealScalar;*/ \
00048   allocate(matrix.rows(), matrix.cols(), computationOptions); \
00049 \
00050   /*const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();*/ \
00051   m_nonzeroSingularValues = m_diagSize; \
00052 \
00053   lapack_int lda = internal::convert_index<lapack_int>(matrix.outerStride()), ldu, ldvt; \
00054   lapack_int matrix_order = LAPACKE_COLROW; \
00055   char jobu, jobvt; \
00056   LAPACKE_TYPE *u, *vt, dummy; \
00057   jobu  = (m_computeFullU) ? 'A' : (m_computeThinU) ? 'S' : 'N'; \
00058   jobvt = (m_computeFullV) ? 'A' : (m_computeThinV) ? 'S' : 'N'; \
00059   if (computeU()) { \
00060     ldu  = internal::convert_index<lapack_int>(m_matrixU.outerStride()); \
00061     u    = (LAPACKE_TYPE*)m_matrixU.data(); \
00062   } else { ldu=1; u=&dummy; }\
00063   MatrixType localV; \
00064   ldvt = (m_computeFullV) ? internal::convert_index<lapack_int>(m_cols) : (m_computeThinV) ? internal::convert_index<lapack_int>(m_diagSize) : 1; \
00065   if (computeV()) { \
00066     localV.resize(ldvt, m_cols); \
00067     vt   = (LAPACKE_TYPE*)localV.data(); \
00068   } else { ldvt=1; vt=&dummy; }\
00069   Matrix<LAPACKE_RTYPE, Dynamic, Dynamic> superb; superb.resize(m_diagSize, 1); \
00070   MatrixType m_temp; m_temp = matrix; \
00071   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()); \
00072   if (computeV()) m_matrixV = localV.adjoint(); \
00073  /* for(int i=0;i<m_diagSize;i++) if (m_singularValues.coeffRef(i) < precision) { m_nonzeroSingularValues--; m_singularValues.coeffRef(i)=RealScalar(0);}*/ \
00074   m_isInitialized = true; \
00075   return *this; \
00076 }
00077 
00078 EIGEN_LAPACKE_SVD(double,   double,                double, d, ColMajor, LAPACK_COL_MAJOR)
00079 EIGEN_LAPACKE_SVD(float,    float,                 float , s, ColMajor, LAPACK_COL_MAJOR)
00080 EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, ColMajor, LAPACK_COL_MAJOR)
00081 EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float,  float , c, ColMajor, LAPACK_COL_MAJOR)
00082 
00083 EIGEN_LAPACKE_SVD(double,   double,                double, d, RowMajor, LAPACK_ROW_MAJOR)
00084 EIGEN_LAPACKE_SVD(float,    float,                 float , s, RowMajor, LAPACK_ROW_MAJOR)
00085 EIGEN_LAPACKE_SVD(dcomplex, lapack_complex_double, double, z, RowMajor, LAPACK_ROW_MAJOR)
00086 EIGEN_LAPACKE_SVD(scomplex, lapack_complex_float,  float , c, RowMajor, LAPACK_ROW_MAJOR)
00087 
00088 } // end namespace Eigen
00089 
00090 #endif // EIGEN_JACOBISVD_LAPACKE_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends