Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
LLT_LAPACKE.h
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
39namespace Eigen {
40
41namespace internal {
42
43namespace lapacke_helpers {
44// -------------------------------------------------------------------------------------------------------------------
45// Dispatch for rank update handling upper and lower parts
46// -------------------------------------------------------------------------------------------------------------------
47
48template <UpLoType Mode>
49struct rank_update {};
50
51template <>
52struct rank_update<Lower> {
53 template <typename MatrixType, typename VectorType>
54 static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) {
55 return Eigen::internal::llt_rank_update_lower(mat, vec, sigma);
56 }
57};
58
59template <>
60struct rank_update<Upper> {
61 template <typename MatrixType, typename VectorType>
62 static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) {
63 Transpose<MatrixType> matt(mat);
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
72template <typename Scalar, UpLoType Mode>
73struct 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
113EIGEN_LAPACKE_LLT(double)
114EIGEN_LAPACKE_LLT(float)
115EIGEN_LAPACKE_LLT(std::complex<double>)
116EIGEN_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
@ Lower
Definition Constants.h:211
@ Upper
Definition Constants.h:213
Namespace containing all symbols from the Eigen library.
Definition Core:137