1*bf2c3715SXin Li /* 2*bf2c3715SXin Li Copyright (c) 2011, Intel Corporation. All rights reserved. 3*bf2c3715SXin Li 4*bf2c3715SXin Li Redistribution and use in source and binary forms, with or without modification, 5*bf2c3715SXin Li are permitted provided that the following conditions are met: 6*bf2c3715SXin Li 7*bf2c3715SXin Li * Redistributions of source code must retain the above copyright notice, this 8*bf2c3715SXin Li list of conditions and the following disclaimer. 9*bf2c3715SXin Li * Redistributions in binary form must reproduce the above copyright notice, 10*bf2c3715SXin Li this list of conditions and the following disclaimer in the documentation 11*bf2c3715SXin Li and/or other materials provided with the distribution. 12*bf2c3715SXin Li * Neither the name of Intel Corporation nor the names of its contributors may 13*bf2c3715SXin Li be used to endorse or promote products derived from this software without 14*bf2c3715SXin Li specific prior written permission. 15*bf2c3715SXin Li 16*bf2c3715SXin Li THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17*bf2c3715SXin Li ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18*bf2c3715SXin Li WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19*bf2c3715SXin Li DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20*bf2c3715SXin Li ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21*bf2c3715SXin Li (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22*bf2c3715SXin Li LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23*bf2c3715SXin Li ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*bf2c3715SXin Li (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25*bf2c3715SXin Li SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*bf2c3715SXin Li 27*bf2c3715SXin Li ******************************************************************************** 28*bf2c3715SXin Li * Content : Eigen bindings to LAPACKe 29*bf2c3715SXin Li * LLt decomposition based on LAPACKE_?potrf function. 30*bf2c3715SXin Li ******************************************************************************** 31*bf2c3715SXin Li */ 32*bf2c3715SXin Li 33*bf2c3715SXin Li #ifndef EIGEN_LLT_LAPACKE_H 34*bf2c3715SXin Li #define EIGEN_LLT_LAPACKE_H 35*bf2c3715SXin Li 36*bf2c3715SXin Li namespace Eigen { 37*bf2c3715SXin Li 38*bf2c3715SXin Li namespace internal { 39*bf2c3715SXin Li 40*bf2c3715SXin Li template<typename Scalar> struct lapacke_llt; 41*bf2c3715SXin Li 42*bf2c3715SXin Li #define EIGEN_LAPACKE_LLT(EIGTYPE, BLASTYPE, LAPACKE_PREFIX) \ 43*bf2c3715SXin Li template<> struct lapacke_llt<EIGTYPE> \ 44*bf2c3715SXin Li { \ 45*bf2c3715SXin Li template<typename MatrixType> \ 46*bf2c3715SXin Li static inline Index potrf(MatrixType& m, char uplo) \ 47*bf2c3715SXin Li { \ 48*bf2c3715SXin Li lapack_int matrix_order; \ 49*bf2c3715SXin Li lapack_int size, lda, info, StorageOrder; \ 50*bf2c3715SXin Li EIGTYPE* a; \ 51*bf2c3715SXin Li eigen_assert(m.rows()==m.cols()); \ 52*bf2c3715SXin Li /* Set up parameters for ?potrf */ \ 53*bf2c3715SXin Li size = convert_index<lapack_int>(m.rows()); \ 54*bf2c3715SXin Li StorageOrder = MatrixType::Flags&RowMajorBit?RowMajor:ColMajor; \ 55*bf2c3715SXin Li matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 56*bf2c3715SXin Li a = &(m.coeffRef(0,0)); \ 57*bf2c3715SXin Li lda = convert_index<lapack_int>(m.outerStride()); \ 58*bf2c3715SXin Li \ 59*bf2c3715SXin Li info = LAPACKE_##LAPACKE_PREFIX##potrf( matrix_order, uplo, size, (BLASTYPE*)a, lda ); \ 60*bf2c3715SXin Li info = (info==0) ? -1 : info>0 ? info-1 : size; \ 61*bf2c3715SXin Li return info; \ 62*bf2c3715SXin Li } \ 63*bf2c3715SXin Li }; \ 64*bf2c3715SXin Li template<> struct llt_inplace<EIGTYPE, Lower> \ 65*bf2c3715SXin Li { \ 66*bf2c3715SXin Li template<typename MatrixType> \ 67*bf2c3715SXin Li static Index blocked(MatrixType& m) \ 68*bf2c3715SXin Li { \ 69*bf2c3715SXin Li return lapacke_llt<EIGTYPE>::potrf(m, 'L'); \ 70*bf2c3715SXin Li } \ 71*bf2c3715SXin Li template<typename MatrixType, typename VectorType> \ 72*bf2c3715SXin Li static Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \ 73*bf2c3715SXin Li { return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); } \ 74*bf2c3715SXin Li }; \ 75*bf2c3715SXin Li template<> struct llt_inplace<EIGTYPE, Upper> \ 76*bf2c3715SXin Li { \ 77*bf2c3715SXin Li template<typename MatrixType> \ 78*bf2c3715SXin Li static Index blocked(MatrixType& m) \ 79*bf2c3715SXin Li { \ 80*bf2c3715SXin Li return lapacke_llt<EIGTYPE>::potrf(m, 'U'); \ 81*bf2c3715SXin Li } \ 82*bf2c3715SXin Li template<typename MatrixType, typename VectorType> \ 83*bf2c3715SXin Li static Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \ 84*bf2c3715SXin Li { \ 85*bf2c3715SXin Li Transpose<MatrixType> matt(mat); \ 86*bf2c3715SXin Li return llt_inplace<EIGTYPE, Lower>::rankUpdate(matt, vec.conjugate(), sigma); \ 87*bf2c3715SXin Li } \ 88*bf2c3715SXin Li }; 89*bf2c3715SXin Li 90*bf2c3715SXin Li EIGEN_LAPACKE_LLT(double, double, d) 91*bf2c3715SXin Li EIGEN_LAPACKE_LLT(float, float, s) 92*bf2c3715SXin Li EIGEN_LAPACKE_LLT(dcomplex, lapack_complex_double, z) 93*bf2c3715SXin Li EIGEN_LAPACKE_LLT(scomplex, lapack_complex_float, c) 94*bf2c3715SXin Li 95*bf2c3715SXin Li } // end namespace internal 96*bf2c3715SXin Li 97*bf2c3715SXin Li } // end namespace Eigen 98*bf2c3715SXin Li 99*bf2c3715SXin Li #endif // EIGEN_LLT_LAPACKE_H 100