57 lines
4.6 KiB
C
57 lines
4.6 KiB
C
|
#ifndef LAPACKADAPTER_H
|
||
|
#define LAPACKADAPTER_H
|
||
|
|
||
|
#include <complex>
|
||
|
|
||
|
#ifndef _CONCAT
|
||
|
#define _CONCAT(A, B) A ## B
|
||
|
#endif
|
||
|
|
||
|
//#ifndef __INTEL_COMPILER
|
||
|
typedef int lapack_int;
|
||
|
typedef std::complex<float> lapack_complex_float;
|
||
|
typedef std::complex<double> lapack_complex_double;
|
||
|
|
||
|
extern "C" void sgetrf_( lapack_int* m, lapack_int* n, float* a, lapack_int* lda, lapack_int* ipiv, lapack_int *info );
|
||
|
extern "C" void dgetrf_( lapack_int* m, lapack_int* n, double* a, lapack_int* lda, lapack_int* ipiv, lapack_int *info );
|
||
|
extern "C" void cgetrf_( lapack_int* m, lapack_int* n, lapack_complex_float* a, lapack_int* lda, lapack_int* ipiv, lapack_int *info );
|
||
|
extern "C" void zgetrf_( lapack_int* m, lapack_int* n, lapack_complex_double* a, lapack_int* lda, lapack_int* ipiv, lapack_int *info );
|
||
|
extern "C" void sgetri_( lapack_int* n, float* a, lapack_int* lda, lapack_int* ipiv, float* work, lapack_int* lwork, lapack_int *info );
|
||
|
extern "C" void dgetri_( lapack_int* n, double* a, lapack_int* lda, lapack_int* ipiv, double* work, lapack_int* lwork, lapack_int *info );
|
||
|
extern "C" void cgetri_( lapack_int* n, lapack_complex_float* a, lapack_int* lda, lapack_int* ipiv, lapack_complex_float* work, lapack_int* lwork, lapack_int *info );
|
||
|
extern "C" void zgetri_( lapack_int* n, lapack_complex_double* a, lapack_int* lda, lapack_int* ipiv, lapack_complex_double* work, lapack_int* lwork, lapack_int *info );
|
||
|
extern "C" void sspsv_( char* uplo, lapack_int* n, lapack_int* nrhs, float* ap, lapack_int* ipiv, float* b, lapack_int* ldb, lapack_int *info );
|
||
|
extern "C" void dspsv_( char* uplo, lapack_int* n, lapack_int* nrhs, double* ap, lapack_int* ipiv, double* b, lapack_int* ldb, lapack_int *info );
|
||
|
extern "C" void cspsv_( char* uplo, lapack_int* n, lapack_int* nrhs, lapack_complex_float* ap, lapack_int* ipiv, lapack_complex_float* b, lapack_int* ldb, lapack_int *info );
|
||
|
extern "C" void zspsv_( char* uplo, lapack_int* n, lapack_int* nrhs, lapack_complex_double* ap, lapack_int* ipiv, lapack_complex_double* b, lapack_int* ldb, lapack_int *info );
|
||
|
extern "C" void cheev_( char* jobz, char* uplo, lapack_int* n, lapack_complex_float* a, lapack_int* lda, float* w, lapack_complex_float* work, lapack_int* lwork, float* rwork, lapack_int *info );
|
||
|
extern "C" void zheev_( char* jobz, char* uplo, lapack_int* n, lapack_complex_double* a, lapack_int* lda, double* w, lapack_complex_double* work, lapack_int* lwork, double* rwork, lapack_int *info );
|
||
|
extern "C" void cheevd_( char* jobz, char* uplo, lapack_int* n, lapack_complex_float* a, lapack_int* lda, float* w, lapack_complex_float* work, lapack_int* lwork, float* rwork, lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, lapack_int *info );
|
||
|
extern "C" void zheevd_( char* jobz, char* uplo, lapack_int* n, lapack_complex_double* a, lapack_int* lda, double* w, lapack_complex_double* work, lapack_int* lwork, double* rwork, lapack_int* lrwork, lapack_int* iwork, lapack_int* liwork, lapack_int *info );
|
||
|
extern "C" void sgemm_(char * transa, char * transb, lapack_int * m, lapack_int * n, lapack_int * k, float* alpha, float * A, lapack_int * lda, float * B, lapack_int * ldb, float * beta, float *, lapack_int * ldc);
|
||
|
extern "C" void dgemm_(char * transa, char * transb, lapack_int * m, lapack_int * n, lapack_int * k, double * alpha, double * A, lapack_int * lda, double * B, lapack_int * ldb, double * beta, double *, lapack_int * ldc);
|
||
|
extern "C" void cgemm_(char*,char*,lapack_int*,lapack_int*,lapack_int*, lapack_complex_float*, lapack_complex_float*, lapack_int*, lapack_complex_float*,lapack_int*, lapack_complex_float*, lapack_complex_float*,lapack_int*);
|
||
|
extern "C" void zgemm_(char*, char*, lapack_int*, lapack_int*, lapack_int*, lapack_complex_double*, lapack_complex_double*,lapack_int*, lapack_complex_double*,lapack_int*, lapack_complex_double*,lapack_complex_double*,lapack_int*);
|
||
|
//#endif
|
||
|
|
||
|
|
||
|
#define Xgetri(TYPE,func_prefix,size_var) \
|
||
|
typedef TYPE TP; \
|
||
|
lapack_int n = static_cast<lapack_int>(_rows); \
|
||
|
lapack_int info = 0; \
|
||
|
lapack_int workspace_size = -1; \
|
||
|
lapack_int lda = std::max({1,n}); \
|
||
|
TP tmp_workspace_size = 0; \
|
||
|
std::unique_ptr<lapack_int[]> ipiv(new lapack_int[std::max({1,n})]); \
|
||
|
_CONCAT(func_prefix,getrf_(&n, &n, (TP*)&_matEls.front(), &lda, ipiv.get(), &info )); \
|
||
|
_CONCAT(func_prefix,getri_(&n, (TP*)&_matEls.front(), &lda, ipiv.get(), &tmp_workspace_size, &workspace_size, &info )); \
|
||
|
workspace_size = static_cast<lapack_int>(size_var); \
|
||
|
std::unique_ptr<TP[]> workspace(new TP[workspace_size]); \
|
||
|
_CONCAT(func_prefix,getri_(&n, (TP*)&_matEls.front(), &lda, ipiv.get(), workspace.get(), &workspace_size, &info )); \
|
||
|
if(info != 0) \
|
||
|
{ \
|
||
|
throw std::runtime_error("Unable to invert the matrix."); \
|
||
|
}
|
||
|
|
||
|
#endif // LAPACKADAPTER_H
|