LLT_LAPACKE.h
Go to the documentation of this file.
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 LAPACKe
29  * LLt decomposition based on LAPACKE_?potrf function.
30  ********************************************************************************
31 */
32 
33 #ifndef EIGEN_LLT_LAPACKE_H
34 #define EIGEN_LLT_LAPACKE_H
35 
36 // IWYU pragma: private
37 #include "./InternalHeaderCheck.h"
38 
39 namespace Eigen {
40 
41 namespace internal {
42 
43 namespace lapacke_helpers {
44 // -------------------------------------------------------------------------------------------------------------------
45 // Dispatch for rank update handling upper and lower parts
46 // -------------------------------------------------------------------------------------------------------------------
47 
48 template <UpLoType Mode>
49 struct rank_update {};
50 
51 template <>
52 struct rank_update<Lower> {
53  template <typename MatrixType, typename VectorType>
54  static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) {
56  }
57 };
58 
59 template <>
60 struct rank_update<Upper> {
61  template <typename MatrixType, typename VectorType>
62  static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) {
64  return Eigen::internal::llt_rank_update_lower(matt, vec.conjugate(), sigma);
65  }
66 };
67 
68 // -------------------------------------------------------------------------------------------------------------------
69 // Generic lapacke llt implementation that hands of to the dispatches
70 // -------------------------------------------------------------------------------------------------------------------
71 
72 template <typename Scalar, UpLoType Mode>
73 struct lapacke_llt {
74  EIGEN_STATIC_ASSERT(((Mode == Lower) || (Mode == Upper)), MODE_MUST_BE_UPPER_OR_LOWER)
75  template <typename MatrixType>
76  static Index blocked(MatrixType &m) {
77  eigen_assert(m.rows() == m.cols());
78  if (m.rows() == 0) {
79  return -1;
80  }
81  /* Set up parameters for ?potrf */
82  lapack_int size = to_lapack(m.rows());
83  lapack_int matrix_order = lapack_storage_of(m);
84  constexpr char uplo = Mode == Upper ? 'U' : 'L';
85  Scalar *a = &(m.coeffRef(0, 0));
86  lapack_int lda = to_lapack(m.outerStride());
87 
88  lapack_int info = potrf(matrix_order, uplo, size, to_lapack(a), lda);
89  info = (info == 0) ? -1 : info > 0 ? info - 1 : size;
90  return info;
91  }
92 
93  template <typename MatrixType, typename VectorType>
94  static Index rankUpdate(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) {
95  return rank_update<Mode>::run(mat, vec, sigma);
96  }
97 };
98 } // namespace lapacke_helpers
99 // end namespace lapacke_helpers
100 
101 /*
102  * Here, we just put the generic implementation from lapacke_llt into a full specialization of the llt_inplace
103  * type. By being a full specialization, the versions defined here thus get precedence over the generic implementation
104  * in LLT.h for double, float and complex double, complex float types.
105  */
106 
107 #define EIGEN_LAPACKE_LLT(EIGTYPE) \
108  template <> \
109  struct llt_inplace<EIGTYPE, Lower> : public lapacke_helpers::lapacke_llt<EIGTYPE, Lower> {}; \
110  template <> \
111  struct llt_inplace<EIGTYPE, Upper> : public lapacke_helpers::lapacke_llt<EIGTYPE, Upper> {};
112 
113 EIGEN_LAPACKE_LLT(double)
114 EIGEN_LAPACKE_LLT(float)
115 EIGEN_LAPACKE_LLT(std::complex<double>)
116 EIGEN_LAPACKE_LLT(std::complex<float>)
117 
118 #undef EIGEN_LAPACKE_LLT
119 
120 } // end namespace internal
121 
122 } // end namespace Eigen
123 
124 #endif // EIGEN_LLT_LAPACKE_H
#define EIGEN_LAPACKE_LLT(EIGTYPE)
Definition: LLT_LAPACKE.h:107
#define eigen_assert(x)
Definition: Macros.h:910
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Expression of the transpose of a matrix.
Definition: Transpose.h:56
@ Lower
Definition: Constants.h:211
@ Upper
Definition: Constants.h:213
#define lapack_int
Definition: lapacke.h:52
const char * uplo
Definition: level2_cplx_impl.h:20
const Scalar * a
Definition: level2_cplx_impl.h:32
const char const int const RealScalar const RealScalar const int * lda
Definition: level2_cplx_impl.h:20
int * m
Definition: level2_cplx_impl.h:294
int info
Definition: level2_cplx_impl.h:39
EIGEN_ALWAYS_INLINE auto to_lapack(Source value)
Definition: lapacke_helpers.h:61
EIGEN_ALWAYS_INLINE EIGEN_CONSTEXPR lapack_int lapack_storage_of(const EigenBase< Derived > &)
translates storage order of the given Eigen object to the corresponding lapack constant
Definition: lapacke_helpers.h:78
static Index llt_rank_update_lower(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma)
Definition: LLT.h:220
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
int sigma
Definition: calibrate.py:179
Definition: Eigen_Colamd.h:49
EIGEN_STATIC_ASSERT(((Mode==Lower)||(Mode==Upper)), MODE_MUST_BE_UPPER_OR_LOWER) template< typename MatrixType > static Index blocked(MatrixType &m)
Definition: LLT_LAPACKE.h:74
static Index rankUpdate(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma)
Definition: LLT_LAPACKE.h:94
static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma)
Definition: LLT_LAPACKE.h:54
static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma)
Definition: LLT_LAPACKE.h:62
Definition: fft_test_shared.h:66
void run(const string &dir_name, LinearSolver *linear_solver_pt, const unsigned nel_1d, bool mess_up_order)
Definition: two_d_poisson_compare_solvers.cc:317