• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace Eigen {
37 
38 namespace internal {
39 
40 /** \internal Specialization for the data types supported by LAPACKe */
41 
42 #define EIGEN_LAPACKE_LU_PARTPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \
43 template<int StorageOrder> \
44 struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int> \
45 { \
46   /* \internal performs the LU decomposition in-place of the matrix represented */ \
47   static lapack_int blocked_lu(Index rows, Index cols, EIGTYPE* lu_data, Index luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \
48   { \
49     EIGEN_UNUSED_VARIABLE(maxBlockSize);\
50     lapack_int matrix_order, first_zero_pivot; \
51     lapack_int m, n, lda, *ipiv, info; \
52     EIGTYPE* a; \
53 /* Set up parameters for ?getrf */ \
54     matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \
55     lda = convert_index<lapack_int>(luStride); \
56     a = lu_data; \
57     ipiv = row_transpositions; \
58     m = convert_index<lapack_int>(rows); \
59     n = convert_index<lapack_int>(cols); \
60     nb_transpositions = 0; \
61 \
62     info = LAPACKE_##LAPACKE_PREFIX##getrf( matrix_order, m, n, (LAPACKE_TYPE*)a, lda, ipiv ); \
63 \
64     for(int i=0;i<m;i++) { ipiv[i]--; if (ipiv[i]!=i) nb_transpositions++; } \
65 \
66     eigen_assert(info >= 0); \
67 /* something should be done with nb_transpositions */ \
68 \
69     first_zero_pivot = info; \
70     return first_zero_pivot; \
71   } \
72 };
73 
74 EIGEN_LAPACKE_LU_PARTPIV(double, double, d)
75 EIGEN_LAPACKE_LU_PARTPIV(float, float, s)
76 EIGEN_LAPACKE_LU_PARTPIV(dcomplex, lapack_complex_double, z)
77 EIGEN_LAPACKE_LU_PARTPIV(scomplex, lapack_complex_float,  c)
78 
79 } // end namespace internal
80 
81 } // end namespace Eigen
82 
83 #endif // EIGEN_PARTIALLU_LAPACK_H
84