xref: /aosp_15_r20/external/eigen/Eigen/src/Eigenvalues/ComplexSchur_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  *    Complex Schur needed to complex unsymmetrical eigenvalues/eigenvectors.
30*bf2c3715SXin Li  ********************************************************************************
31*bf2c3715SXin Li */
32*bf2c3715SXin Li 
33*bf2c3715SXin Li #ifndef EIGEN_COMPLEX_SCHUR_LAPACKE_H
34*bf2c3715SXin Li #define EIGEN_COMPLEX_SCHUR_LAPACKE_H
35*bf2c3715SXin Li 
36*bf2c3715SXin Li namespace Eigen {
37*bf2c3715SXin Li 
38*bf2c3715SXin Li /** \internal Specialization for the data types supported by LAPACKe */
39*bf2c3715SXin Li 
40*bf2c3715SXin Li #define EIGEN_LAPACKE_SCHUR_COMPLEX(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, LAPACKE_PREFIX_U, EIGCOLROW, LAPACKE_COLROW) \
41*bf2c3715SXin Li template<> template<typename InputType> inline \
42*bf2c3715SXin Li ComplexSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >& \
43*bf2c3715SXin Li ComplexSchur<Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> >::compute(const EigenBase<InputType>& matrix, bool computeU) \
44*bf2c3715SXin Li { \
45*bf2c3715SXin Li   typedef Matrix<EIGTYPE, Dynamic, Dynamic, EIGCOLROW> MatrixType; \
46*bf2c3715SXin Li   typedef MatrixType::RealScalar RealScalar; \
47*bf2c3715SXin Li   typedef std::complex<RealScalar> ComplexScalar; \
48*bf2c3715SXin Li \
49*bf2c3715SXin Li   eigen_assert(matrix.cols() == matrix.rows()); \
50*bf2c3715SXin Li \
51*bf2c3715SXin Li   m_matUisUptodate = false; \
52*bf2c3715SXin Li   if(matrix.cols() == 1) \
53*bf2c3715SXin Li   { \
54*bf2c3715SXin Li     m_matT = matrix.derived().template cast<ComplexScalar>(); \
55*bf2c3715SXin Li     if(computeU)  m_matU = ComplexMatrixType::Identity(1,1); \
56*bf2c3715SXin Li       m_info = Success; \
57*bf2c3715SXin Li       m_isInitialized = true; \
58*bf2c3715SXin Li       m_matUisUptodate = computeU; \
59*bf2c3715SXin Li       return *this; \
60*bf2c3715SXin Li   } \
61*bf2c3715SXin Li   lapack_int n = internal::convert_index<lapack_int>(matrix.cols()), sdim, info; \
62*bf2c3715SXin Li   lapack_int matrix_order = LAPACKE_COLROW; \
63*bf2c3715SXin Li   char jobvs, sort='N'; \
64*bf2c3715SXin Li   LAPACK_##LAPACKE_PREFIX_U##_SELECT1 select = 0; \
65*bf2c3715SXin Li   jobvs = (computeU) ? 'V' : 'N'; \
66*bf2c3715SXin Li   m_matU.resize(n, n); \
67*bf2c3715SXin Li   lapack_int ldvs  = internal::convert_index<lapack_int>(m_matU.outerStride()); \
68*bf2c3715SXin Li   m_matT = matrix; \
69*bf2c3715SXin Li   lapack_int lda = internal::convert_index<lapack_int>(m_matT.outerStride()); \
70*bf2c3715SXin Li   Matrix<EIGTYPE, Dynamic, Dynamic> w; \
71*bf2c3715SXin Li   w.resize(n, 1);\
72*bf2c3715SXin Li   info = LAPACKE_##LAPACKE_PREFIX##gees( matrix_order, jobvs, sort, select, n, (LAPACKE_TYPE*)m_matT.data(), lda, &sdim, (LAPACKE_TYPE*)w.data(), (LAPACKE_TYPE*)m_matU.data(), ldvs ); \
73*bf2c3715SXin Li   if(info == 0) \
74*bf2c3715SXin Li     m_info = Success; \
75*bf2c3715SXin Li   else \
76*bf2c3715SXin Li     m_info = NoConvergence; \
77*bf2c3715SXin Li \
78*bf2c3715SXin Li   m_isInitialized = true; \
79*bf2c3715SXin Li   m_matUisUptodate = computeU; \
80*bf2c3715SXin Li   return *this; \
81*bf2c3715SXin Li \
82*bf2c3715SXin Li }
83*bf2c3715SXin Li 
84*bf2c3715SXin Li EIGEN_LAPACKE_SCHUR_COMPLEX(dcomplex, lapack_complex_double, z, Z, ColMajor, LAPACK_COL_MAJOR)
85*bf2c3715SXin Li EIGEN_LAPACKE_SCHUR_COMPLEX(scomplex, lapack_complex_float,  c, C, ColMajor, LAPACK_COL_MAJOR)
86*bf2c3715SXin Li EIGEN_LAPACKE_SCHUR_COMPLEX(dcomplex, lapack_complex_double, z, Z, RowMajor, LAPACK_ROW_MAJOR)
87*bf2c3715SXin Li EIGEN_LAPACKE_SCHUR_COMPLEX(scomplex, lapack_complex_float,  c, C, RowMajor, LAPACK_ROW_MAJOR)
88*bf2c3715SXin Li 
89*bf2c3715SXin Li } // end namespace Eigen
90*bf2c3715SXin Li 
91*bf2c3715SXin Li #endif // EIGEN_COMPLEX_SCHUR_LAPACKE_H
92