1 //=================================================================================================
2 /*!
3 //  \file blaze/math/lapack/clapack/heevd.h
4 //  \brief Header file for the CLAPACK heevd 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_HEEVD_H_
36 #define _BLAZE_MATH_LAPACK_CLAPACK_HEEVD_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 cheevd_( char* jobz, char* uplo, blaze::blas_int_t* n, float* A, blaze::blas_int_t* lda,
61               float* w, float* work, blaze::blas_int_t* lwork, float* rwork, blaze::blas_int_t* lrwork,
62               blaze::blas_int_t* iwork, blaze::blas_int_t* liwork, blaze::blas_int_t* info,
63               blaze::fortran_charlen_t njobz, blaze::fortran_charlen_t nuplo );
64 void zheevd_( char* jobz, char* uplo, blaze::blas_int_t* n, double* A, blaze::blas_int_t* lda,
65               double* w, double* work, blaze::blas_int_t* lwork, double* rwork, blaze::blas_int_t* lrwork,
66               blaze::blas_int_t* iwork, blaze::blas_int_t* liwork, blaze::blas_int_t* info,
67               blaze::fortran_charlen_t njobz, blaze::fortran_charlen_t nuplo );
68 
69 }
70 #endif
71 /*! \endcond */
72 //*************************************************************************************************
73 
74 
75 
76 
77 namespace blaze {
78 
79 //=================================================================================================
80 //
81 //  LAPACK HERMITIAN MATRIX EIGENVALUE FUNCTIONS (HEEVD)
82 //
83 //=================================================================================================
84 
85 //*************************************************************************************************
86 /*!\name LAPACK Hermitian matrix eigenvalue functions (heevd) */
87 //@{
88 void heevd( char jobz, char uplo, blas_int_t n, complex<float>* A, blas_int_t lda,
89             float* w, complex<float>* work, blas_int_t lwork, float* rwork,
90             blas_int_t lrwork, blas_int_t* iwork, blas_int_t liwork, blas_int_t* info );
91 
92 void heevd( char jobz, char uplo, blas_int_t n, complex<double>* A, blas_int_t lda,
93             double* w, complex<double>* work, blas_int_t lwork, double* rwork,
94             blas_int_t lrwork, blas_int_t* iwork, blas_int_t liwork, blas_int_t* info );
95 //@}
96 //*************************************************************************************************
97 
98 
99 //*************************************************************************************************
100 /*!\brief LAPACK kernel for computing the eigenvalues of the given dense Hermitian single
101 //        precision column-major matrix.
102 // \ingroup lapack_eigenvalue
103 //
104 // \param jobz \c 'V' to compute the eigenvectors of \a A, \c 'N' to only compute the eigenvalues.
105 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
106 // \param n The number of rows and columns of the given matrix \f$[0..\infty)\f$.
107 // \param A Pointer to the first element of the single precision column-major matrix.
108 // \param lda The total number of elements between two columns of the matrix A \f$[0..\infty)\f$.
109 // \param w Pointer to the first element of the vector for the eigenvalues.
110 // \param work Auxiliary array; size >= max( 1, \a lwork ).
111 // \param lwork The dimension of the array \a work; see online reference for details.
112 // \param rwork Auxiliary array; size >= max( 1, \a lrwork ).
113 // \param lrwork The dimension of the array \a rwork; see online reference for details.
114 // \param iwork Auxiliary array; size >= max( 1, \a liwork ).
115 // \param liwork The dimension of the array \a iwork; see online reference for details.
116 // \param info Return code of the function call.
117 // \return void
118 //
119 // This function computes the eigenvalues of an Hermitian \a n-by-\a n single precision complex
120 // column-major matrix based on the LAPACK cheevd() function. Optionally, it computes the left
121 // and right eigenvectors using a divide-and-conquer strategy. The real eigenvalues are returned
122 // in ascending order in the given \a n-dimensional vector \a w.
123 //
124 // The parameter \a jobz specifies the computation of the orthonormal eigenvectors of \a A:
125 //
126 //   - \c 'V': The eigenvectors of \a A are computed and returned within the matrix \a A.
127 //   - \c 'N': The eigenvectors of \a A are not computed.
128 //
129 // The \a info argument provides feedback on the success of the function call:
130 //
131 //   - = 0: The computation finished successfully.
132 //   - < 0: If info = -i, the i-th argument had an illegal value.
133 //   - > 0: If info = i, the algorithm failed to converge; i values did not converge to zero.
134 //
135 // For more information on the cheevd() function, see the LAPACK online documentation browser:
136 //
137 //        http://www.netlib.org/lapack/explore-html/
138 //
139 // \note This function can only be used if a fitting LAPACK library, which supports this function,
140 // is available and linked to the executable. Otherwise a call to this function will result in a
141 // linker error.
142 */
heevd(char jobz,char uplo,blas_int_t n,complex<float> * A,blas_int_t lda,float * w,complex<float> * work,blas_int_t lwork,float * rwork,blas_int_t lrwork,blas_int_t * iwork,blas_int_t liwork,blas_int_t * info)143 inline void heevd( char jobz, char uplo, blas_int_t n, complex<float>* A, blas_int_t lda,
144                    float* w, complex<float>* work, blas_int_t lwork, float* rwork,
145                    blas_int_t lrwork, blas_int_t* iwork, blas_int_t liwork, blas_int_t* info )
146 {
147    BLAZE_STATIC_ASSERT( sizeof( complex<float> ) == 2UL*sizeof( float ) );
148 
149 #if defined(INTEL_MKL_VERSION)
150    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
151    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex8 ) == sizeof( complex<float> ) );
152    using ET = MKL_Complex8;
153 #else
154    using ET = float;
155 #endif
156 
157    cheevd_( &jobz, &uplo, &n, reinterpret_cast<ET*>( A ), &lda, w,
158             reinterpret_cast<ET*>( work ), &lwork, rwork, &lrwork, iwork, &liwork, info
159 #if !defined(INTEL_MKL_VERSION)
160           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
161 #endif
162           );
163 }
164 //*************************************************************************************************
165 
166 
167 //*************************************************************************************************
168 /*!\brief LAPACK kernel for computing the eigenvalues of the given dense Hermitian double
169 //        precision column-major matrix.
170 // \ingroup lapack_eigenvalue
171 //
172 // \param jobz \c 'V' to compute the eigenvectors of \a A, \c 'N' to only compute the eigenvalues.
173 // \param uplo \c 'L' to use the lower part of the matrix, \c 'U' to use the upper part.
174 // \param n The number of rows and columns of the given matrix \f$[0..\infty)\f$.
175 // \param A Pointer to the first element of the double precision column-major matrix.
176 // \param lda The total number of elements between two columns of the matrix A \f$[0..\infty)\f$.
177 // \param w Pointer to the first element of the vector for the eigenvalues.
178 // \param work Auxiliary array; size >= max( 1, \a lwork ).
179 // \param lwork The dimension of the array \a work; see online reference for details.
180 // \param rwork Auxiliary array; size >= max( 1, \a lrwork ).
181 // \param lrwork The dimension of the array \a rwork; see online reference for details.
182 // \param iwork Auxiliary array; size >= max( 1, \a liwork ).
183 // \param liwork The dimension of the array \a iwork; see online reference for details.
184 // \param info Return code of the function call.
185 // \return void
186 //
187 // This function computes the eigenvalues of an Hermitian \a n-by-\a n double precision complex
188 // column-major matrix based on the LAPACK cheevd() function. Optionally, it computes the left
189 // and right eigenvectors using a divide-and-conquer strategy. The real eigenvalues are returned
190 // in ascending order in the given \a n-dimensional vector \a w.
191 //
192 // The parameter \a jobz specifies the computation of the orthonormal eigenvectors of \a A:
193 //
194 //   - \c 'V': The eigenvectors of \a A are computed and returned within the matrix \a A.
195 //   - \c 'N': The eigenvectors of \a A are not computed.
196 //
197 // The \a info argument provides feedback on the success of the function call:
198 //
199 //   - = 0: The computation finished successfully.
200 //   - < 0: If info = -i, the i-th argument had an illegal value.
201 //   - > 0: If info = i, the algorithm failed to converge; i values did not converge to zero.
202 //
203 // For more information on the cheevd() function, see the LAPACK online documentation browser:
204 //
205 //        http://www.netlib.org/lapack/explore-html/
206 //
207 // \note This function can only be used if a fitting LAPACK library, which supports this function,
208 // is available and linked to the executable. Otherwise a call to this function will result in a
209 // linker error.
210 */
heevd(char jobz,char uplo,blas_int_t n,complex<double> * A,blas_int_t lda,double * w,complex<double> * work,blas_int_t lwork,double * rwork,blas_int_t lrwork,blas_int_t * iwork,blas_int_t liwork,blas_int_t * info)211 inline void heevd( char jobz, char uplo, blas_int_t n, complex<double>* A, blas_int_t lda,
212                    double* w, complex<double>* work, blas_int_t lwork, double* rwork,
213                    blas_int_t lrwork, blas_int_t* iwork, blas_int_t liwork, blas_int_t* info )
214 {
215    BLAZE_STATIC_ASSERT( sizeof( complex<double> ) == 2UL*sizeof( double ) );
216 
217 #if defined(INTEL_MKL_VERSION)
218    BLAZE_STATIC_ASSERT( sizeof( MKL_INT ) == sizeof( blas_int_t ) );
219    BLAZE_STATIC_ASSERT( sizeof( MKL_Complex16 ) == sizeof( complex<double> ) );
220    using ET = MKL_Complex16;
221 #else
222    using ET = double;
223 #endif
224 
225    zheevd_( &jobz, &uplo, &n, reinterpret_cast<ET*>( A ), &lda, w,
226             reinterpret_cast<ET*>( work ), &lwork, rwork, &lrwork, iwork, &liwork, info
227 #if !defined(INTEL_MKL_VERSION)
228           , blaze::fortran_charlen_t(1), blaze::fortran_charlen_t(1)
229 #endif
230           );
231 }
232 //*************************************************************************************************
233 
234 } // namespace blaze
235 
236 #endif
237