Eigne Matrix Class Library

Dependents:   MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more

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?

UserRevisionLine numberNew 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 * LLt decomposition based on LAPACKE_?potrf function.
ykuroda 0:13a5d365ba16 30 ********************************************************************************
ykuroda 0:13a5d365ba16 31 */
ykuroda 0:13a5d365ba16 32
ykuroda 0:13a5d365ba16 33 #ifndef EIGEN_LLT_MKL_H
ykuroda 0:13a5d365ba16 34 #define EIGEN_LLT_MKL_H
ykuroda 0:13a5d365ba16 35
ykuroda 0:13a5d365ba16 36 #include "Eigen/src/Core/util/MKL_support.h"
ykuroda 0:13a5d365ba16 37 #include <iostream>
ykuroda 0:13a5d365ba16 38
ykuroda 0:13a5d365ba16 39 namespace Eigen {
ykuroda 0:13a5d365ba16 40
ykuroda 0:13a5d365ba16 41 namespace internal {
ykuroda 0:13a5d365ba16 42
ykuroda 0:13a5d365ba16 43 template<typename Scalar> struct mkl_llt;
ykuroda 0:13a5d365ba16 44
ykuroda 0:13a5d365ba16 45 #define EIGEN_MKL_LLT(EIGTYPE, MKLTYPE, MKLPREFIX) \
ykuroda 0:13a5d365ba16 46 template<> struct mkl_llt<EIGTYPE> \
ykuroda 0:13a5d365ba16 47 { \
ykuroda 0:13a5d365ba16 48 template<typename MatrixType> \
ykuroda 0:13a5d365ba16 49 static inline typename MatrixType::Index potrf(MatrixType& m, char uplo) \
ykuroda 0:13a5d365ba16 50 { \
ykuroda 0:13a5d365ba16 51 lapack_int matrix_order; \
ykuroda 0:13a5d365ba16 52 lapack_int size, lda, info, StorageOrder; \
ykuroda 0:13a5d365ba16 53 EIGTYPE* a; \
ykuroda 0:13a5d365ba16 54 eigen_assert(m.rows()==m.cols()); \
ykuroda 0:13a5d365ba16 55 /* Set up parameters for ?potrf */ \
ykuroda 0:13a5d365ba16 56 size = m.rows(); \
ykuroda 0:13a5d365ba16 57 StorageOrder = MatrixType::Flags&RowMajorBit?RowMajor:ColMajor; \
ykuroda 0:13a5d365ba16 58 matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \
ykuroda 0:13a5d365ba16 59 a = &(m.coeffRef(0,0)); \
ykuroda 0:13a5d365ba16 60 lda = m.outerStride(); \
ykuroda 0:13a5d365ba16 61 \
ykuroda 0:13a5d365ba16 62 info = LAPACKE_##MKLPREFIX##potrf( matrix_order, uplo, size, (MKLTYPE*)a, lda ); \
ykuroda 0:13a5d365ba16 63 info = (info==0) ? -1 : info>0 ? info-1 : size; \
ykuroda 0:13a5d365ba16 64 return info; \
ykuroda 0:13a5d365ba16 65 } \
ykuroda 0:13a5d365ba16 66 }; \
ykuroda 0:13a5d365ba16 67 template<> struct llt_inplace<EIGTYPE, Lower> \
ykuroda 0:13a5d365ba16 68 { \
ykuroda 0:13a5d365ba16 69 template<typename MatrixType> \
ykuroda 0:13a5d365ba16 70 static typename MatrixType::Index blocked(MatrixType& m) \
ykuroda 0:13a5d365ba16 71 { \
ykuroda 0:13a5d365ba16 72 return mkl_llt<EIGTYPE>::potrf(m, 'L'); \
ykuroda 0:13a5d365ba16 73 } \
ykuroda 0:13a5d365ba16 74 template<typename MatrixType, typename VectorType> \
ykuroda 0:13a5d365ba16 75 static typename MatrixType::Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \
ykuroda 0:13a5d365ba16 76 { return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); } \
ykuroda 0:13a5d365ba16 77 }; \
ykuroda 0:13a5d365ba16 78 template<> struct llt_inplace<EIGTYPE, Upper> \
ykuroda 0:13a5d365ba16 79 { \
ykuroda 0:13a5d365ba16 80 template<typename MatrixType> \
ykuroda 0:13a5d365ba16 81 static typename MatrixType::Index blocked(MatrixType& m) \
ykuroda 0:13a5d365ba16 82 { \
ykuroda 0:13a5d365ba16 83 return mkl_llt<EIGTYPE>::potrf(m, 'U'); \
ykuroda 0:13a5d365ba16 84 } \
ykuroda 0:13a5d365ba16 85 template<typename MatrixType, typename VectorType> \
ykuroda 0:13a5d365ba16 86 static typename MatrixType::Index rankUpdate(MatrixType& mat, const VectorType& vec, const typename MatrixType::RealScalar& sigma) \
ykuroda 0:13a5d365ba16 87 { \
ykuroda 0:13a5d365ba16 88 Transpose<MatrixType> matt(mat); \
ykuroda 0:13a5d365ba16 89 return llt_inplace<EIGTYPE, Lower>::rankUpdate(matt, vec.conjugate(), sigma); \
ykuroda 0:13a5d365ba16 90 } \
ykuroda 0:13a5d365ba16 91 };
ykuroda 0:13a5d365ba16 92
ykuroda 0:13a5d365ba16 93 EIGEN_MKL_LLT(double, double, d)
ykuroda 0:13a5d365ba16 94 EIGEN_MKL_LLT(float, float, s)
ykuroda 0:13a5d365ba16 95 EIGEN_MKL_LLT(dcomplex, MKL_Complex16, z)
ykuroda 0:13a5d365ba16 96 EIGEN_MKL_LLT(scomplex, MKL_Complex8, c)
ykuroda 0:13a5d365ba16 97
ykuroda 0:13a5d365ba16 98 } // end namespace internal
ykuroda 0:13a5d365ba16 99
ykuroda 0:13a5d365ba16 100 } // end namespace Eigen
ykuroda 0:13a5d365ba16 101
ykuroda 0:13a5d365ba16 102 #endif // EIGEN_LLT_MKL_H