PartialPivLU_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  * 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 #include "./InternalHeaderCheck.h"
37 
38 namespace Eigen {
39 
40 namespace internal {
41 
42 namespace lapacke_helpers {
43 // -------------------------------------------------------------------------------------------------------------------
44 // Generic lapacke partial lu implementation that converts arguments and dispatches to the function above
45 // -------------------------------------------------------------------------------------------------------------------
46 
47 template<typename Scalar, int StorageOrder>
48 struct lapacke_partial_lu {
50  static lapack_int blocked_lu(Index rows, Index cols, Scalar* lu_data, Index luStride, lapack_int* row_transpositions,
51  lapack_int& nb_transpositions, lapack_int maxBlockSize=256)
52  {
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 partial_lu_impl
78  * type. This specialization is more specialized than the generic implementations that Eigen implements, so if the
79  * 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> : public lapacke_helpers::lapacke_partial_lu<EIGTYPE, StorageOrder> {};
84 
87 EIGEN_LAPACKE_PARTIAL_LU(std::complex<double>)
88 EIGEN_LAPACKE_PARTIAL_LU(std::complex<float>)
89 
90 #undef EIGEN_LAPACKE_PARTIAL_LU
91 
92 } // end namespace internal
93 
94 } // end namespace Eigen
95 
96 #endif // EIGEN_PARTIALLU_LAPACK_H
Matrix3f m
int n
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:957
#define eigen_assert(x)
Definition: Macros.h:902
#define EIGEN_LAPACKE_PARTIAL_LU(EIGTYPE)
@ RowMajor
Definition: Constants.h:323
#define LAPACK_COL_MAJOR
Definition: lapacke.h:125
#define lapack_int
Definition: lapacke.h:52
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:124
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82