1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/heevx.h
4 //  \brief Header file for the CLAPACK heevx wrapper functions
5 //
6 //  Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 //  This file is part of the Blaze library. You can redistribute it and/or modify it under
9 //  the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 //  forms, with or without modification, are permitted provided that the following conditions
11 //  are met:
12 //
13 //  1. Redistributions of source code must retain the above copyright notice, this list of
14 //     conditions and the following disclaimer.
15 //  2. Redistributions in binary form must reproduce the above copyright notice, this list
16 //     of conditions and the following disclaimer in the documentation and/or other materials
17 //     provided with the distribution.
18 //  3. Neither the names of the Blaze development group nor the names of its contributors
19 //     may be used to endorse or promote products derived from this software without specific
20 //     prior written permission.
21 //
22 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 //  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 //  SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 //  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 //  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 //  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 //  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 //  DAMAGE.
32 */
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_LAPACK_CLAPACK_HEEVX_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_HEEVX_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/blas/Types.h>
44 #include <blaze/util/Complex.h>
45 #include <blaze/util/StaticAssert.h>
46 #include <blaze/util/Types.h>
47 
48 
49 //=================================================================================================
50 //
51 //  LAPACK FORWARD DECLARATIONS
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
56 /*! \cond BLAZE_INTERNAL */
57 #if !defined(INTEL_MKL_VERSION)
58 extern "C" {
59 
60 void cheevx_( char* jobz, char* range, char* uplo, blaze::blas_int_t* n, float* A,
61               blaze::blas_int_t* lda, float* vl, float* vu, blaze::blas_int_t* il,
62               blaze::blas_int_t* iu, float* abstol, blaze::blas_int_t* m, float* w,
63               float* Z, blaze::blas_int_t* ldz, float* work, blaze::blas_int_t* lwork,
64               float* rwork, blaze::blas_int_t* iwork, blaze::blas_int_t* ifail,
65               blaze::blas_int_t* info, blaze::fortran_charlen_t njobz,
66               blaze::fortran_charlen_t nrange, blaze::fortran_charlen_t nuplo );
67 void zheevx_( char* jobz, char* range, char* uplo, blaze::blas_int_t* n, double* A,
68               blaze::blas_int_t* lda, double* vl, double* vu, blaze::blas_int_t* il,
69               blaze::blas_int_t* iu, double* abstol, blaze::blas_int_t* m, double* w,
70               double* Z, blaze::blas_int_t* ldz, double* work, blaze::blas_int_t* lwork,
71               double* rwork, blaze::blas_int_t* iwork, blaze::blas_int_t* ifail,
72               blaze::blas_int_t* info, blaze::fortran_charlen_t njobz,
73               blaze::fortran_charlen_t nrange, blaze::fortran_charlen_t nuplo );
74 
75 }
76 #endif
77 /*! \endcond */
78 //*************************************************************************************************
79 
80 
81 
82 
83 namespace blaze {
84 
85 //=================================================================================================
86 //
87 //  LAPACK HERMITIAN MATRIX EIGENVALUE FUNCTIONS (HEEVX)
88 //
89 //=================================================================================================
90 
91 //*************************************************************************************************
92 /*!\name LAPACK Hermitian matrix eigenvalue functions (heevx) */
93 //@{
94 void heevx( char jobz, char range, char uplo, blas_int_t n, complex<float>* A,
95             blas_int_t lda, float vl, float vu, blas_int_t il, blas_int_t iu,
96             float abstol, blas_int_t* m, float* w, complex<float>* Z, blas_int_t ldz,
97             complex<float>* work, blas_int_t lwork, float* rwork, blas_int_t* iwork,
98             blas_int_t* ifail, blas_int_t* info );
99 
100 void heevx( char jobz, char range, char uplo, blas_int_t n, complex<double>* A,
101             blas_int_t lda, double vl, double vu, blas_int_t il, blas_int_t iu,
102             double abstol, blas_int_t* m, double* w, complex<double>* Z, blas_int_t ldz,
103             complex<double>* work, blas_int_t lwork, double* rwork, blas_int_t* iwork,
104             blas_int_t* ifail, blas_int_t* info );
105 //@}
106 //*************************************************************************************************
107 
108 
109 //*************************************************************************************************
110 /*!\brief LAPACK kernel for computing the eigenvalues of the given dense Hermitian single
111 //        precision complex column-major matrix.
112 // \ingroup lapack_eigenvalue
113 //
114 // \param jobz \c 'V' to compute the eigenvectors of \a A, \c 'N' to only compute the eigenvalues.
115 // \param range Specifies the range of eigenvalues to find (\c 'A', \c 'V', or \c 'I').
116 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
117 // \param n The number of rows and columns of the given matrix \f$[0..\infty)\f$.
118 // \param A Pointer to the first element of the single precision complex column-major matrix.
119 // \param lda The total number of elements between two columns of the matrix A \f$[0..\infty)\f$.
120 // \param vl The lower bound of the interval to be searched for eigenvalues (\a vl < \a vu).
121 // \param vu The upper bound of the interval to be searched for eigenvalues (\a vl < \a vu).
122 // \param il The index of the smallest eigenvalue to be returned (0 <= \a il <= \a iu).
123 // \param iu The index of the largest eigenvalue to be returned (0 <= \a il <= \a iu).
124 // \param abstol The absolute error tolerance for the computation of the eigenvalues.
125 // \param m The total number of eigenvalues found (0 <= \a m <= \a n).
126 // \param w Pointer to the first element of the vector for the eigenvalues.
127 // \param Z Pointer to the first element of the column-major matrix for the eigenvectors.
128 // \param ldz The total number of elements between two columns of the matrix Z \f$[0..\infty)\f$.
129 // \param work Auxiliary array; size >= max( 1, \a lwork ).
130 // \param lwork The dimension of the array \a work; see online reference for details.
131 // \param rwork Auxiliary array; size >= 7*\a n.
132 // \param iwork Auxiliary array; size >= 5*\a n.
133 // \param ifail Index array of eigenvectors that failed to converge.
134 // \param info Return code of the function call.
135 // \return void
136 //
137 // This function computes a specified number of eigenvalues of a Hermitian \a n-by-\a n single
138 // precision complex column-major matrix based on the LAPACK cheevx() function. Optionally, it
139 // computes a specified number of eigenvectors. The selected real eigenvalues are returned in
140 // ascending order in the given \a n-dimensional vector \a w.
141 //
142 // The parameter \a jobz specifies the computation of the orthonormal eigenvectors of \a A:
143 //
144 //   - \c 'V': The eigenvectors of \a A are computed and returned within the matrix \a Z.
145 //   - \c 'N': The eigenvectors of \a A are not computed.
146 //
147 // The parameter \a range specifies the amount of eigenvalues/eigenvectors to be found:
148 //
149 //   - \c 'A': All eigenvalues will be found.
150 //   - \c 'V': All eigenvalues in the half-open interval \f$(vl..vu]\f$ will be found.
151 //   - \c 'I': The \a il-th through \a iu-th eigenvalues will be found.
152 //
153 // The \a info argument provides feedback on the success of the function call:
154 //
155 //   - = 0: The computation finished successfully.
156 //   - < 0: If info = -i, the i-th argument had an illegal value.
157 //   - > 0: If info = i, the algorithm failed to converge; i values did not converge to zero.
158 //
159 // For more information on the cheevx() function, see the LAPACK online documentation browser:
160 //
161 //        http://www.netlib.org/lapack/explore-html/
162 //
163 // \note This function can only be used if a fitting LAPACK library, which supports this function,
164 // is available and linked to the executable. Otherwise a call to this function will result in a
165 // linker error.
166 */
heevx(char jobz,char range,char uplo,blas_int_t n,complex<float> * A,blas_int_t lda,float vl,float vu,blas_int_t il,blas_int_t iu,float abstol,blas_int_t * m,float * w,complex<float> * Z,blas_int_t ldz,complex<float> * work,blas_int_t lwork,float * rwork,blas_int_t * iwork,blas_int_t * ifail,blas_int_t * info)167 inline void heevx( char jobz, char range, char uplo, blas_int_t n, complex<float>* A,
168                    blas_int_t lda, float vl, float vu, blas_int_t il, blas_int_t iu,
169                    float abstol, blas_int_t* m, float* w, complex<float>* Z, blas_int_t ldz,
170                    complex<float>* work, blas_int_t lwork, float* rwork, blas_int_t* iwork,
171                    blas_int_t* ifail, blas_int_t* info )
172 {
173    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
174 
175 #if defined(INTEL_MKL_VERSION)
176    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
177    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
178    using ET = MKL_Complex8;
179 #else
180    using ET = float;
181 #endif
182 
183    ++il;
184    ++iu;
185 
186    cheevx_( &jobz, &range, &uplo, &n, reinterpret_cast<ET*>( A ), &lda, &vl, &vu, &il, &iu,
187             &abstol, m, w, reinterpret_cast<ET*>( Z ), &ldz, reinterpret_cast<ET*>( work ),
188             &lwork, rwork, iwork, ifail, info
189 #if !defined(INTEL_MKL_VERSION)
190           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
191 #endif
192           );
193 }
194 //*************************************************************************************************
195 
196 
197 //*************************************************************************************************
198 /*!\brief LAPACK kernel for computing the eigenvalues of the given dense Hermitian double
199 //        precision complex column-major matrix.
200 // \ingroup lapack_eigenvalue
201 //
202 // \param jobz \c 'V' to compute the eigenvectors of \a A, \c 'N' to only compute the eigenvalues.
203 // \param range Specifies the range of eigenvalues to find (\c 'A', \c 'V', or \c 'I').
204 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
205 // \param n The number of rows and columns of the given matrix \f$[0..\infty)\f$.
206 // \param A Pointer to the first element of the double precision complex column-major matrix.
207 // \param lda The total number of elements between two columns of the matrix A \f$[0..\infty)\f$.
208 // \param vl The lower bound of the interval to be searched for eigenvalues (\a vl < \a vu).
209 // \param vu The upper bound of the interval to be searched for eigenvalues (\a vl < \a vu).
210 // \param il The index of the smallest eigenvalue to be returned (0 <= \a il <= \a iu).
211 // \param iu The index of the largest eigenvalue to be returned (0 <= \a il <= \a iu).
212 // \param abstol The absolute error tolerance for the computation of the eigenvalues.
213 // \param m The total number of eigenvalues found (0 <= \a m <= \a n).
214 // \param w Pointer to the first element of the vector for the eigenvalues.
215 // \param Z Pointer to the first element of the column-major matrix for the eigenvectors.
216 // \param ldz The total number of elements between two columns of the matrix Z \f$[0..\infty)\f$.
217 // \param work Auxiliary array; size >= max( 1, \a lwork ).
218 // \param lwork The dimension of the array \a work; see online reference for details.
219 // \param rwork Auxiliary array; size >= 7*\a n.
220 // \param iwork Auxiliary array; size >= 5*\a n.
221 // \param ifail Index array of eigenvectors that failed to converge.
222 // \param info Return code of the function call.
223 // \return void
224 //
225 // This function computes a specified number of eigenvalues of a Hermitian \a n-by-\a n double
226 // precision complex column-major matrix based on the LAPACK cheevx() function. Optionally, it
227 // computes a specified number of eigenvectors. The selected real eigenvalues are returned in
228 // ascending order in the given \a n-dimensional vector \a w.
229 //
230 // The parameter \a jobz specifies the computation of the orthonormal eigenvectors of \a A:
231 //
232 //   - \c 'V': The eigenvectors of \a A are computed and returned within the matrix \a Z.
233 //   - \c 'N': The eigenvectors of \a A are not computed.
234 //
235 // The parameter \a range specifies the amount of eigenvalues/eigenvectors to be found:
236 //
237 //   - \c 'A': All eigenvalues will be found.
238 //   - \c 'V': All eigenvalues in the half-open interval \f$(vl..vu]\f$ will be found.
239 //   - \c 'I': The \a il-th through \a iu-th eigenvalues will be found.
240 //
241 // The \a info argument provides feedback on the success of the function call:
242 //
243 //   - = 0: The computation finished successfully.
244 //   - < 0: If info = -i, the i-th argument had an illegal value.
245 //   - > 0: If info = i, the algorithm failed to converge; i values did not converge to zero.
246 //
247 // For more information on the cheevx() function, see the LAPACK online documentation browser:
248 //
249 //        http://www.netlib.org/lapack/explore-html/
250 //
251 // \note This function can only be used if a fitting LAPACK library, which supports this function,
252 // is available and linked to the executable. Otherwise a call to this function will result in a
253 // linker error.
254 */
heevx(char jobz,char range,char uplo,blas_int_t n,complex<double> * A,blas_int_t lda,double vl,double vu,blas_int_t il,blas_int_t iu,double abstol,blas_int_t * m,double * w,complex<double> * Z,blas_int_t ldz,complex<double> * work,blas_int_t lwork,double * rwork,blas_int_t * iwork,blas_int_t * ifail,blas_int_t * info)255 inline void heevx( char jobz, char range, char uplo, blas_int_t n, complex<double>* A,
256                    blas_int_t lda, double vl, double vu, blas_int_t il, blas_int_t iu,
257                    double abstol, blas_int_t* m, double* w, complex<double>* Z, blas_int_t ldz,
258                    complex<double>* work, blas_int_t lwork, double* rwork, blas_int_t* iwork,
259                    blas_int_t* ifail, blas_int_t* info )
260 {
261    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
262 
263 #if defined(INTEL_MKL_VERSION)
264    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
265    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
266    using ET = MKL_Complex16;
267 #else
268    using ET = double;
269 #endif
270 
271    ++il;
272    ++iu;
273 
274    zheevx_( &jobz, &range, &uplo, &n, reinterpret_cast<ET*>( A ), &lda, &vl, &vu, &il, &iu,
275             &abstol, m, w, reinterpret_cast<ET*>( Z ), &ldz, reinterpret_cast<ET*>( work ),
276             &lwork, rwork, iwork, ifail, info
277 #if !defined(INTEL_MKL_VERSION)
278           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
279 #endif
280           );
281 }
282 //*************************************************************************************************
283 
284 } // namespace blaze
285 
286 #endif
287