33 #include <mkl_lapacke.h> 34 #include <mkl_lapack.h> 39 #define lapack_complex_double std::complex<double> 40 #define lapack_complex_float std::complex<float> 75 float LAPACKE_slange(
int matrix_order,
char norm, lapack_int m, lapack_int n,
const float* a, lapack_int lda );
76 double LAPACKE_dlange(
int matrix_order,
char norm, lapack_int m, lapack_int n,
const double* a, lapack_int lda );
77 double LAPACKE_zlange(
int matrix_order,
char norm, lapack_int m, lapack_int n,
const std::complex<double>* a, lapack_int lda );
78 float LAPACKE_clange(
int matrix_order,
char norm, lapack_int m, lapack_int n,
const std::complex<float>* a, lapack_int lda );
169 template <
class T>
inline int 170 syev(
int matrix_order,
char JOBZ,
char UPLO,
int N, T *A,
int LDA, T* W);
171 template <
class T>
inline int 172 syevd(
int matrix_order,
char JOBZ,
char UPLO,
int N, T *A,
int LDA, T* W);
173 template <
class T>
inline int 174 geev(
int matrix_layout,
char jobvl,
char jobvr,
int n, T* a,
int lda, T* wr, T* wi, T* vl,
int ldvl, T* vr,
int ldvr );
176 template <
class T>
inline int 177 gesvd(
int matrix_order,
char JOBU,
char JOBVT,
int M,
int N, T *A,
int LDA, T* S, T* U,
int LDU, T* VT,
int LDVT, T* superb);
178 template <
class T>
inline int 179 gesdd(
int matrix_order,
char JOBZ,
int M,
int N, T *A,
int LDA, T* S, T* U,
int LDU, T* VT,
int LDVT);
181 template <
class T>
inline int 182 sytri(
int matrix_order,
char UPLO,
int N, T *A,
int LDA,
const int* IPIV);
183 template <
class T>
inline int 184 sytrf(
int matrix_order,
char UPLO,
int N, T* A,
int LDA,
int* IPIV);
186 template <
class T>
inline T
187 lange(
int matrix_order,
char norm,
int m,
int n,
const T* A,
int LDA);
190 template <
class T>
inline int 191 getrf (
int matrix_layout ,
int m ,
int n , T * a ,
int lda,
int * ipiv );
193 template <
class T>
inline int 194 getri(
int matrix_layout ,
int n , T * a ,
int lda ,
const int * ipiv);
199 template <>
inline int 200 syev<double>(
int matrix_order,
char JOBZ,
char UPLO,
int N,
double *A,
int LDA,
double* W)
201 {
return LAPACKE_dsyev(matrix_order,JOBZ,UPLO,N,A,LDA,W);}
202 template <>
inline int 203 syev<float>(
int matrix_order,
char JOBZ,
char UPLO,
int N,
float *A,
int LDA,
float* W)
204 {
return LAPACKE_ssyev(matrix_order,JOBZ,UPLO,N,A,LDA,W);}
206 template <>
inline int 207 syevd<double>(
int matrix_order,
char JOBZ,
char UPLO,
int N,
double *A,
int LDA,
double* W)
208 {
return LAPACKE_dsyevd(matrix_order,JOBZ,UPLO,N,A,LDA,W);}
209 template <>
inline int 210 syevd<float>(
int matrix_order,
char JOBZ,
char UPLO,
int N,
float *A,
int LDA,
float* W)
211 {
return LAPACKE_ssyevd(matrix_order,JOBZ,UPLO,N,A,LDA,W);}
212 template <>
inline int 213 syevd<std::complex<double> >(
int matrix_order,
char JOBZ,
char UPLO,
int N, std::complex<double> *A,
int LDA, std::complex<double>* W)
215 template <>
inline int 216 syevd<std::complex<float> >(
int matrix_order,
char JOBZ,
char UPLO,
int N, std::complex<float> *A,
int LDA, std::complex<float>* W)
219 template <>
inline int 220 geev<double>(
int matrix_layout,
char jobvl,
char jobvr,
int n,
double* a,
int lda,
double* wr,
double* wi,
double* vl,
int ldvl,
double* vr,
int ldvr )
221 {
return LAPACKE_dgeev( matrix_layout, jobvl, jobvr, n, a, lda, wr, wi, vl, ldvl, vr, ldvr ); }
222 template <>
inline int 223 geev<float>(
int matrix_layout,
char jobvl,
char jobvr,
int n,
float* a,
int lda,
float* wr,
float* wi,
float* vl,
int ldvl,
float* vr,
int ldvr )
224 {
return LAPACKE_sgeev( matrix_layout, jobvl, jobvr, n, a, lda, wr, wi, vl, ldvl, vr, ldvr ); }
225 template <>
inline int 226 geev<std::complex<double> >(
int matrix_layout,
char jobvl,
char jobvr,
int n, std::complex<double>* a,
int lda, std::complex<double>* wr, std::complex<double>* wi, std::complex<double>* vl,
int ldvl, std::complex<double>* vr,
int ldvr )
228 template <>
inline int 229 geev<std::complex<float> >(
int matrix_layout,
char jobvl,
char jobvr,
int n, std::complex<float>* a,
int lda, std::complex<float>* wr, std::complex<float>* wi, std::complex<float>* vl,
int ldvl, std::complex<float>* vr,
int ldvr )
232 geev(
int matrix_layout,
char jobvl,
char jobvr,
int n, std::complex<double>* a,
int lda, std::complex<double>* w, std::complex<double>* vl,
int ldvl, std::complex<double>* vr,
int ldvr )
233 {
return LAPACKE_zgeev( matrix_layout, jobvl, jobvr, n, a, lda, w, vl, ldvl, vr, ldvr ); }
235 template <>
inline int 236 gesvd<double>(
int matrix_order,
char JOBU,
char JOBVT,
int M,
int N,
double *A,
int LDA,
double* S,
double* U,
int LDU,
double* VT,
int LDVT,
double* superb)
237 {
return LAPACKE_dgesvd(matrix_order,JOBU,JOBVT,M,N,A,LDA,S,U,LDU,VT,LDVT,superb);}
238 template <>
inline int 239 gesvd<float>(
int matrix_order,
char JOBU,
char JOBVT,
int M,
int N,
float *A,
int LDA,
float* S,
float* U,
int LDU,
float* VT,
int LDVT,
float* superb)
240 {
return LAPACKE_sgesvd(matrix_order,JOBU,JOBVT,M,N,A,LDA,S,U,LDU,VT,LDVT,superb);}
242 template <>
inline int 243 gesdd<double>(
int matrix_order,
char JOBZ,
int M,
int N,
double *A,
int LDA,
double* S,
double* U,
int LDU,
double* VT,
int LDVT)
244 {
return LAPACKE_dgesdd(matrix_order,JOBZ,M,N,A,LDA,S,U,LDU,VT,LDVT);}
245 template <>
inline int 246 gesdd<float>(
int matrix_order,
char JOBZ,
int M,
int N,
float *A,
int LDA,
float* S,
float* U,
int LDU,
float* VT,
int LDVT)
247 {
return LAPACKE_sgesdd(matrix_order,JOBZ,M,N,A,LDA,S,U,LDU,VT,LDVT);}
249 gesdd(
int matrix_order,
char JOBZ,
int M,
int N, std::complex<double> *A,
int LDA,
double* S, std::complex<double>* U,
int LDU, std::complex<double>* VT,
int LDVT)
250 {
return LAPACKE_zgesdd(matrix_order,JOBZ,M,N,A,LDA,S,U,LDU,VT,LDVT);}
252 gesdd(
int matrix_order,
char JOBZ,
int M,
int N, std::complex<float> *A,
int LDA,
float* S, std::complex<float>* U,
int LDU, std::complex<float>* VT,
int LDVT)
253 {
return LAPACKE_cgesdd(matrix_order,JOBZ,M,N,A,LDA,S,U,LDU,VT,LDVT);}
255 template <>
inline int 256 sytri<double>(
int matrix_order,
char UPLO,
int N,
double *A,
int LDA,
const int* IPIV)
257 {
return LAPACKE_dsytri(matrix_order,UPLO,N,A,LDA,IPIV);}
258 template <>
inline int 259 sytri<float>(
int matrix_order,
char UPLO,
int N,
float *A,
int LDA,
const int* IPIV)
260 {
return LAPACKE_ssytri(matrix_order,UPLO,N,A,LDA,IPIV); }
261 template <>
inline int 262 sytri<std::complex<double> >(
int matrix_order,
char UPLO,
int N, std::complex<double> *A,
int LDA,
const int* IPIV)
263 {
return LAPACKE_zsytri(matrix_order,UPLO,N,A,LDA,IPIV);}
264 template <>
inline int 265 sytri<std::complex<float> >(
int matrix_order,
char UPLO,
int N, std::complex<float> *A,
int LDA,
const int* IPIV)
266 {
return LAPACKE_csytri(matrix_order,UPLO,N,A,LDA,IPIV);}
268 template <>
inline int 269 sytrf<double>(
int matrix_order,
char UPLO,
int N,
double* A,
int LDA,
int* IPIV)
270 {
return LAPACKE_dsytrf(matrix_order,UPLO,N,A,LDA,IPIV); }
271 template <>
inline int 272 sytrf<float>(
int matrix_order,
char UPLO,
int N,
float* A,
int LDA,
int* IPIV)
273 {
return LAPACKE_ssytrf(matrix_order,UPLO,N,A,LDA,IPIV); }
274 template <>
inline int 275 sytrf<std::complex<double> >(
int matrix_order,
char UPLO,
int N, std::complex<double>* A,
int LDA,
int* IPIV)
276 {
return LAPACKE_zsytrf(matrix_order,UPLO,N,A,LDA,IPIV); }
277 template <>
inline int 278 sytrf<std::complex<float> >(
int matrix_order,
char UPLO,
int N, std::complex<float>* A,
int LDA,
int* IPIV)
279 {
return LAPACKE_csytrf(matrix_order,UPLO,N,A,LDA,IPIV); }
281 template <>
inline double 282 lange<double>(
int matrix_order,
char norm,
int m,
int n,
const double* A,
int LDA)
284 template <>
inline float 285 lange<float>(
int matrix_order,
char norm,
int m,
int n,
const float* A,
int LDA)
288 lange(
int matrix_order,
char norm,
int m,
int n,
const std::complex<double>* A,
int LDA)
291 lange(
int matrix_order,
char norm,
int m,
int n,
const std::complex<float>* A,
int LDA)
294 template <>
inline int 295 getrf<double>(
int matrix_layout ,
int m ,
int n ,
double * a ,
int lda,
int * ipiv )
296 {
return LAPACKE_dgetrf(matrix_layout, m, n, a, lda, ipiv); }
297 template <>
inline int 298 getrf<float>(
int matrix_layout ,
int m ,
int n ,
float * a ,
int lda,
int * ipiv )
299 {
return LAPACKE_sgetrf(matrix_layout, m, n, a, lda, ipiv); }
300 template <>
inline int 301 getrf<std::complex<double> >(
int matrix_layout ,
int m ,
int n , std::complex<double> * a ,
int lda,
int * ipiv )
302 {
return LAPACKE_zgetrf(matrix_layout, m, n, a, lda, ipiv); }
303 template <>
inline int 304 getrf<std::complex<float> >(
int matrix_layout ,
int m ,
int n , std::complex<float> * a ,
int lda,
int * ipiv )
305 {
return LAPACKE_cgetrf(matrix_layout, m, n, a, lda, ipiv); }
307 template <>
inline int 308 getri<double>(
int matrix_layout ,
int n ,
double * a ,
int lda ,
const int * ipiv)
309 {
return LAPACKE_dgetri(matrix_layout, n, a, lda, ipiv); }
310 template <>
inline int 311 getri<float>(
int matrix_layout ,
int n ,
float * a ,
int lda ,
const int * ipiv)
312 {
return LAPACKE_sgetri(matrix_layout, n, a, lda, ipiv); }
313 template <>
inline int 314 getri<std::complex<double> >(
int matrix_layout ,
int n , std::complex<double> * a ,
int lda ,
const int * ipiv)
315 {
return LAPACKE_zgetri(matrix_layout, n, a, lda, ipiv); }
316 template <>
inline int 317 getri<std::complex<float> >(
int matrix_layout ,
int n , std::complex<float> * a ,
int lda ,
const int * ipiv)
318 {
return LAPACKE_cgetri(matrix_layout, n, a, lda, ipiv); }
321 #define __utl_getri_Matrix(T, FuncName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, MatrixGetDataFuncName, ReSizeFuncName) \ 322 template <class T> inline void \ 323 FuncName(const RowMajorMatrixName& mat, RowMajorMatrixName& result) \ 325 int N = mat.GetRowsFuncName(),INFO=0; \ 328 INFO = getrf<T>(LAPACK_ROW_MAJOR, N,N,result.MatrixGetDataFuncName(),N,ipiv); \ 329 INFO = getri<T>(LAPACK_ROW_MAJOR, N,result.MatrixGetDataFuncName(),N,ipiv); \ 355 #define __utl_geev_Matrix(T, FuncName, RowMajorMatrixName, GetRowsFuncName, GetColsFuncName, MatrixGetDataFuncName, VectorName, VectorGetDataFuncName, ReSizeFuncName) \ 356 template <class T> inline void \ 357 FuncName ( const RowMajorMatrixName& mat, VectorName& valReal, VectorName& valImg, RowMajorMatrixName& vecRealR, RowMajorMatrixName& vecImgR, RowMajorMatrixName& vecRealL, RowMajorMatrixName& vecImgL) \ 359 utlException(mat.GetRowsFuncName()!=mat.GetColsFuncName(), "The matrix should be square"); \ 360 char JOBVL='V', JOBVR='V'; \ 361 int N = mat.GetRowsFuncName(),INFO=0; \ 362 int LDA=N, LDVL=N, LDVR=N; \ 364 RowMajorMatrixName matCopy(mat), vecR(N,N), vecL(N,N); \ 365 valReal.ReSizeFuncName(N); \ 366 valImg.ReSizeFuncName(N); \ 367 vecRealR.ReSizeFuncName(N,N); \ 368 vecImgR.ReSizeFuncName(N,N); \ 369 vecRealL.ReSizeFuncName(N,N); \ 370 vecImgL.ReSizeFuncName(N,N); \ 372 INFO = geev<T>( LAPACK_ROW_MAJOR, JOBVL, JOBVR, N, matCopy.MatrixGetDataFuncName(), LDA, valReal.VectorGetDataFuncName(), valImg.VectorGetDataFuncName(), vecL.MatrixGetDataFuncName(), LDVL, vecR.MatrixGetDataFuncName(), LDVR ); \ 374 T const * vecR_data=vecR.MatrixGetDataFuncName(); \ 375 T* vecRealR_data=vecRealR.MatrixGetDataFuncName(); \ 376 T* vecImgR_data=vecImgR.MatrixGetDataFuncName(); \ 377 T const * vecL_data=vecL.MatrixGetDataFuncName(); \ 378 T* vecRealL_data=vecRealL.MatrixGetDataFuncName(); \ 379 T* vecImgL_data=vecImgL.MatrixGetDataFuncName(); \ 380 for ( int i = 0; i < N; ++i ) \ 387 if( valImg[j] == (double)0.0 ) \ 389 vecRealR_data[kk] = vecR_data[kk]; \ 390 vecImgR_data[kk] = 0.0; \ 391 vecRealL_data[kk] = vecL_data[kk]; \ 392 vecImgL_data[kk] = 0.0; \ 397 vecRealR_data[kk] = vecR_data[kk]; \ 398 vecImgR_data[kk] = vecR_data[kk+1]; \ 400 vecRealR_data[kk+1] = vecR_data[kk]; \ 401 vecImgR_data[kk+1] = -vecR_data[kk+1]; \ 403 vecRealL_data[kk] = vecL_data[kk]; \ 404 vecImgL_data[kk] = vecL_data[kk+1]; \ 406 vecRealL_data[kk+1] = vecL_data[kk]; \ 407 vecImgL_data[kk+1] = -vecL_data[kk+1]; \ 415 template <class T> inline void \ 416 FuncName ( const RowMajorMatrixName& mat, VectorName& valReal, VectorName& valImg) \ 418 utlException(mat.GetRowsFuncName()!=mat.GetColsFuncName(), "The matrix should be square"); \ 419 char JOBVL='N', JOBVR='N'; \ 420 int N = mat.GetRowsFuncName(),INFO=0; \ 421 int LDA=N, LDVL=N, LDVR=N; \ 423 RowMajorMatrixName matCopy(mat); \ 424 valReal.ReSizeFuncName(N); \ 425 valImg.ReSizeFuncName(N); \ 427 INFO = geev<T>( LAPACK_ROW_MAJOR, JOBVL, JOBVR, N, matCopy.MatrixGetDataFuncName(), LDA, valReal.VectorGetDataFuncName(), valImg.VectorGetDataFuncName(), NULL, LDVL, NULL, LDVR ); \ 430 template <class T> inline void \ 431 FuncName ( const RowMajorMatrixName& mat, VectorName& valReal, VectorName& valImg, RowMajorMatrixName& vecRealR, RowMajorMatrixName& vecImgR) \ 433 utlException(mat.GetRowsFuncName()!=mat.GetColsFuncName(), "The matrix should be square"); \ 434 char JOBVL='N', JOBVR='V'; \ 435 int N = mat.GetRowsFuncName(),INFO=0; \ 436 int LDA=N, LDVL=N, LDVR=N; \ 438 RowMajorMatrixName matCopy(mat), eigenVectorCopy(N,N); \ 439 valReal.ReSizeFuncName(N); \ 440 valImg.ReSizeFuncName(N); \ 441 vecRealR.ReSizeFuncName(N,N); \ 442 vecImgR.ReSizeFuncName(N,N); \ 444 INFO = geev<T>( LAPACK_ROW_MAJOR, JOBVL, JOBVR, N, matCopy.MatrixGetDataFuncName(), LDA, valReal.VectorGetDataFuncName(), valImg.VectorGetDataFuncName(), NULL, LDVL, eigenVectorCopy.MatrixGetDataFuncName(), LDVR ); \ 446 T const * vecR_data=eigenVectorCopy.MatrixGetDataFuncName(); \ 447 T* vecRealR_data=vecRealR.MatrixGetDataFuncName(); \ 448 T* vecImgR_data=vecImgR.MatrixGetDataFuncName(); \ 449 for ( int i = 0; i < N; ++i ) \ 456 if( valImg[j] == (double)0.0 ) \ 458 vecRealR_data[kk] = vecR_data[kk]; \ 459 vecImgR_data[kk] = 0.0; \ 464 vecRealR_data[kk] = vecR_data[kk]; \ 465 vecImgR_data[kk] = vecR_data[kk+1]; \ 467 vecRealR_data[kk+1] = vecR_data[kk]; \ 468 vecImgR_data[kk+1] = -vecR_data[kk+1]; \ int gesvd< float >(int matrix_order, char JOBU, char JOBVT, int M, int N, float *A, int LDA, float *S, float *U, int LDU, float *VT, int LDVT, float *superb)
int sytrf(int matrix_order, char UPLO, int N, T *A, int LDA, int *IPIV)
int getri< double >(int matrix_layout, int n, double *a, int lda, const int *ipiv)
int sytrf< double >(int matrix_order, char UPLO, int N, double *A, int LDA, int *IPIV)
int syevd< float >(int matrix_order, char JOBZ, char UPLO, int N, float *A, int LDA, float *W)
float LAPACKE_slange(int matrix_order, char norm, lapack_int m, lapack_int n, const float *a, lapack_int lda)
int sytri(int matrix_order, char UPLO, int N, T *A, int LDA, const int *IPIV)
int getri(int matrix_layout, int n, T *a, int lda, const int *ipiv)
int sytri< float >(int matrix_order, char UPLO, int N, float *A, int LDA, const int *IPIV)
float lange< float >(int matrix_order, char norm, int m, int n, const float *A, int LDA)
int geev< double >(int matrix_layout, char jobvl, char jobvr, int n, double *a, int lda, double *wr, double *wi, double *vl, int ldvl, double *vr, int ldvr)
int sytri< double >(int matrix_order, char UPLO, int N, double *A, int LDA, const int *IPIV)
int sytrf< float >(int matrix_order, char UPLO, int N, float *A, int LDA, int *IPIV)
int syevd(int matrix_order, char JOBZ, char UPLO, int N, T *A, int LDA, T *W)
int gesdd(int matrix_order, char JOBZ, int M, int N, T *A, int LDA, T *S, T *U, int LDU, T *VT, int LDVT)
#define utlGlobalException(cond, expout)
int getrf(int matrix_layout, int m, int n, T *a, int lda, int *ipiv)
int syev< float >(int matrix_order, char JOBZ, char UPLO, int N, float *A, int LDA, float *W)
double LAPACKE_dlange(int matrix_order, char norm, lapack_int m, lapack_int n, const double *a, lapack_int lda)
int getrf< double >(int matrix_layout, int m, int n, double *a, int lda, int *ipiv)
int getrf< float >(int matrix_layout, int m, int n, float *a, int lda, int *ipiv)
double lange< double >(int matrix_order, char norm, int m, int n, const double *A, int LDA)
int gesvd< double >(int matrix_order, char JOBU, char JOBVT, int M, int N, double *A, int LDA, double *S, double *U, int LDU, double *VT, int LDVT, double *superb)
int gesvd(int matrix_order, char JOBU, char JOBVT, int M, int N, T *A, int LDA, T *S, T *U, int LDU, T *VT, int LDVT, T *superb)
T lange(int matrix_order, char norm, int m, int n, const T *A, int LDA)
double LAPACKE_zlange(int matrix_order, char norm, lapack_int m, lapack_int n, const std::complex< double > *a, lapack_int lda)
int syevd< double >(int matrix_order, char JOBZ, char UPLO, int N, double *A, int LDA, double *W)
int gesdd< float >(int matrix_order, char JOBZ, int M, int N, float *A, int LDA, float *S, float *U, int LDU, float *VT, int LDVT)
int getri< float >(int matrix_layout, int n, float *a, int lda, const int *ipiv)
int gesdd< double >(int matrix_order, char JOBZ, int M, int N, double *A, int LDA, double *S, double *U, int LDU, double *VT, int LDVT)
int syev(int matrix_order, char JOBZ, char UPLO, int N, T *A, int LDA, T *W)
int geev(int matrix_layout, char jobvl, char jobvr, int n, T *a, int lda, T *wr, T *wi, T *vl, int ldvl, T *vr, int ldvr)
int syev< double >(int matrix_order, char JOBZ, char UPLO, int N, double *A, int LDA, double *W)
int geev< float >(int matrix_layout, char jobvl, char jobvr, int n, float *a, int lda, float *wr, float *wi, float *vl, int ldvl, float *vr, int ldvr)
float LAPACKE_clange(int matrix_order, char norm, lapack_int m, lapack_int n, const std::complex< float > *a, lapack_int lda)