47 #ifndef __H__UG__MARTIN_ALGEBRA__LAPACK_INTERFACE_H__
48 #define __H__UG__MARTIN_ALGEBRA__LAPACK_INTERFACE_H__
50 #ifdef LAPACK_AVAILABLE
53 #include "../small_algebra.h"
61 void dgegv_(
char *cCalcLeftEV,
char *cCalcRightEV,
lapack_int *n,
72 char jobvl = calcLeftEV ?
'V' :
'N';
73 char jobvr = calcRightEV ?
'V' :
'N';
75 dgegv_(&jobvl, &jobvr, &n, pColMajorMatrixA, &leading_dim_a, pColMajorMatrixB, &leading_dim_b, alphar, alphai, beta, vl, &leading_dim_vl, vr, &leading_dim_vr, work, &worksize, &info);
96 template<
typename A_type,
typename B_type>
98 DenseVector<B_type> &lambda, DenseMatrix<A_type> &B,
bool bSortEigenvalues=
false)
100 size_t N = A.num_rows();
101 UG_ASSERT(N == A.num_cols() && N == B.num_rows() && N == B.num_cols(),
"");
103 B_type alphar; alphar.resize(N);
104 B_type alphai; alphai.resize(N);
105 B_type beta; beta.resize(N);
109 double dWorksize = 0;
114 info = gegv(
true,
false, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], &X(0,0), N, NULL, 0, &dWorksize, worksize);
116 info = gegv(
false,
true, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], NULL, N, &X(0,0), N, &dWorksize, worksize);
119 worksize = (int)dWorksize;
120 double *dwork =
new double[worksize];
122 info = gegv(
true,
false, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], &X(0,0), N, NULL, 0, dwork, worksize);
124 info = gegv(
false,
true, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], NULL, N, &X(0,0), N, dwork, worksize);
129 for(
size_t i=0; i<N; i++)
131 lambda[i] = alphar[i]/beta[i];
139 for(
int i=N-1; i>0; i--)
141 for(
int j=0; j<i; j++)
142 if(lambda[j] > lambda[j+1])
144 std::swap(lambda[j], lambda[j+1]);
145 for(
size_t r = 0; r<X.num_rows(); r++)
146 std::swap(X(r, j), X(r, j+1));
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double dabs(double a)
Definition: blocks.h:41
@ ColMajor
Definition: storage.h:49
@ RowMajor
Definition: storage.h:48
int GeneralizedEigenvalueProblem(A_type &A, A_type &X, B_type &lambda, A_type &B, bool bSortEigenvalues=false)
Definition: no_lapack.h:41
int lapack_int
Definition: solve_deficit.cpp:39
double lapack_double
Definition: solve_deficit.cpp:41
class SparseMatrix B_type