Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
PartialPivLU_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 * LU decomposition with partial pivoting based on LAPACKE_?getrf function.
30 ********************************************************************************
31*/
32
33#ifndef EIGEN_PARTIALLU_LAPACK_H
34#define EIGEN_PARTIALLU_LAPACK_H
35
36// IWYU pragma: private
37#include "./InternalHeaderCheck.h"
38
39namespace Eigen {
40
41namespace internal {
42
43namespace lapacke_helpers {
44// -------------------------------------------------------------------------------------------------------------------
45// Generic lapacke partial lu implementation that converts arguments and dispatches to the function above
46// -------------------------------------------------------------------------------------------------------------------
47
48template <typename Scalar, int StorageOrder>
49struct lapacke_partial_lu {
51 static lapack_int blocked_lu(Index rows, Index cols, Scalar* lu_data, Index luStride, lapack_int* row_transpositions,
52 lapack_int& nb_transpositions, lapack_int maxBlockSize = 256) {
53 EIGEN_UNUSED_VARIABLE(maxBlockSize);
54 // Set up parameters for getrf
55 lapack_int matrix_order = StorageOrder == RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR;
56 lapack_int lda = to_lapack(luStride);
57 Scalar* a = lu_data;
58 lapack_int* ipiv = row_transpositions;
59 lapack_int m = to_lapack(rows);
60 lapack_int n = to_lapack(cols);
61 nb_transpositions = 0;
62
63 lapack_int info = getrf(matrix_order, m, n, to_lapack(a), lda, ipiv);
64 eigen_assert(info >= 0);
65
66 for (int i = 0; i < m; i++) {
67 ipiv[i]--;
68 if (ipiv[i] != i) nb_transpositions++;
69 }
70 lapack_int first_zero_pivot = info;
71 return first_zero_pivot;
72 }
73};
74} // end namespace lapacke_helpers
75
76/*
77 * Here, we just put the generic implementation from lapacke_partial_lu into a partial specialization of the
78 * partial_lu_impl type. This specialization is more specialized than the generic implementations that Eigen implements,
79 * so if the Scalar type matches they will be chosen.
80 */
81#define EIGEN_LAPACKE_PARTIAL_LU(EIGTYPE) \
82 template <int StorageOrder> \
83 struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int, Dynamic> \
84 : public lapacke_helpers::lapacke_partial_lu<EIGTYPE, StorageOrder> {};
85
86EIGEN_LAPACKE_PARTIAL_LU(double)
87EIGEN_LAPACKE_PARTIAL_LU(float)
88EIGEN_LAPACKE_PARTIAL_LU(std::complex<double>)
89EIGEN_LAPACKE_PARTIAL_LU(std::complex<float>)
90
91#undef EIGEN_LAPACKE_PARTIAL_LU
92
93} // end namespace internal
94
95} // end namespace Eigen
96
97#endif // EIGEN_PARTIALLU_LAPACK_H
@ RowMajor
Definition Constants.h:320
Namespace containing all symbols from the Eigen library.
Definition Core:137