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