xref: /aosp_15_r20/external/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li /*
2*bf2c3715SXin Li  Copyright (c) 2011, Intel Corporation. All rights reserved.
3*bf2c3715SXin Li 
4*bf2c3715SXin Li  Redistribution and use in source and binary forms, with or without modification,
5*bf2c3715SXin Li  are permitted provided that the following conditions are met:
6*bf2c3715SXin Li 
7*bf2c3715SXin Li  * Redistributions of source code must retain the above copyright notice, this
8*bf2c3715SXin Li    list of conditions and the following disclaimer.
9*bf2c3715SXin Li  * Redistributions in binary form must reproduce the above copyright notice,
10*bf2c3715SXin Li    this list of conditions and the following disclaimer in the documentation
11*bf2c3715SXin Li    and/or other materials provided with the distribution.
12*bf2c3715SXin Li  * Neither the name of Intel Corporation nor the names of its contributors may
13*bf2c3715SXin Li    be used to endorse or promote products derived from this software without
14*bf2c3715SXin Li    specific prior written permission.
15*bf2c3715SXin Li 
16*bf2c3715SXin Li  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17*bf2c3715SXin Li  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18*bf2c3715SXin Li  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19*bf2c3715SXin Li  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20*bf2c3715SXin Li  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21*bf2c3715SXin Li  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*bf2c3715SXin Li  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23*bf2c3715SXin Li  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*bf2c3715SXin Li  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25*bf2c3715SXin Li  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*bf2c3715SXin Li 
27*bf2c3715SXin Li  ********************************************************************************
28*bf2c3715SXin Li  *   Content : Eigen bindings to LAPACKe
29*bf2c3715SXin Li  *     LU decomposition with partial pivoting based on LAPACKE_?getrf function.
30*bf2c3715SXin Li  ********************************************************************************
31*bf2c3715SXin Li */
32*bf2c3715SXin Li 
33*bf2c3715SXin Li #ifndef EIGEN_PARTIALLU_LAPACK_H
34*bf2c3715SXin Li #define EIGEN_PARTIALLU_LAPACK_H
35*bf2c3715SXin Li 
36*bf2c3715SXin Li namespace Eigen {
37*bf2c3715SXin Li 
38*bf2c3715SXin Li namespace internal {
39*bf2c3715SXin Li 
40*bf2c3715SXin Li /** \internal Specialization for the data types supported by LAPACKe */
41*bf2c3715SXin Li 
42*bf2c3715SXin Li #define EIGEN_LAPACKE_LU_PARTPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \
43*bf2c3715SXin Li template<int StorageOrder> \
44*bf2c3715SXin Li struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int> \
45*bf2c3715SXin Li { \
46*bf2c3715SXin Li   /* \internal performs the LU decomposition in-place of the matrix represented */ \
47*bf2c3715SXin Li   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*bf2c3715SXin Li   { \
49*bf2c3715SXin Li     EIGEN_UNUSED_VARIABLE(maxBlockSize);\
50*bf2c3715SXin Li     lapack_int matrix_order, first_zero_pivot; \
51*bf2c3715SXin Li     lapack_int m, n, lda, *ipiv, info; \
52*bf2c3715SXin Li     EIGTYPE* a; \
53*bf2c3715SXin Li /* Set up parameters for ?getrf */ \
54*bf2c3715SXin Li     matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \
55*bf2c3715SXin Li     lda = convert_index<lapack_int>(luStride); \
56*bf2c3715SXin Li     a = lu_data; \
57*bf2c3715SXin Li     ipiv = row_transpositions; \
58*bf2c3715SXin Li     m = convert_index<lapack_int>(rows); \
59*bf2c3715SXin Li     n = convert_index<lapack_int>(cols); \
60*bf2c3715SXin Li     nb_transpositions = 0; \
61*bf2c3715SXin Li \
62*bf2c3715SXin Li     info = LAPACKE_##LAPACKE_PREFIX##getrf( matrix_order, m, n, (LAPACKE_TYPE*)a, lda, ipiv ); \
63*bf2c3715SXin Li \
64*bf2c3715SXin Li     for(int i=0;i<m;i++) { ipiv[i]--; if (ipiv[i]!=i) nb_transpositions++; } \
65*bf2c3715SXin Li \
66*bf2c3715SXin Li     eigen_assert(info >= 0); \
67*bf2c3715SXin Li /* something should be done with nb_transpositions */ \
68*bf2c3715SXin Li \
69*bf2c3715SXin Li     first_zero_pivot = info; \
70*bf2c3715SXin Li     return first_zero_pivot; \
71*bf2c3715SXin Li   } \
72*bf2c3715SXin Li };
73*bf2c3715SXin Li 
74*bf2c3715SXin Li EIGEN_LAPACKE_LU_PARTPIV(double, double, d)
75*bf2c3715SXin Li EIGEN_LAPACKE_LU_PARTPIV(float, float, s)
76*bf2c3715SXin Li EIGEN_LAPACKE_LU_PARTPIV(dcomplex, lapack_complex_double, z)
77*bf2c3715SXin Li EIGEN_LAPACKE_LU_PARTPIV(scomplex, lapack_complex_float,  c)
78*bf2c3715SXin Li 
79*bf2c3715SXin Li } // end namespace internal
80*bf2c3715SXin Li 
81*bf2c3715SXin Li } // end namespace Eigen
82*bf2c3715SXin Li 
83*bf2c3715SXin Li #endif // EIGEN_PARTIALLU_LAPACK_H
84