32 #ifndef __VMML__VMMLIB_LAPACK_SYM_EIGS__HPP__
33 #define __VMML__VMMLIB_LAPACK_SYM_EIGS__HPP__
35 #include <vmmlib/matrix.hpp>
36 #include <vmmlib/vector.hpp>
37 #include <vmmlib/exception.hpp>
39 #include <vmmlib/lapack_types.hpp>
40 #include <vmmlib/lapack_includes.hpp>
83 template<
typename float_t >
107 friend std::ostream& operator << ( std::ostream& os,
111 <<
" (1)\tjobz " << p.jobz << std::endl
112 <<
" (2)\trange " << p.range << std::endl
113 <<
" (3)\tuplo " << p.uplo << std::endl
114 <<
" (4)\tn " << p.n << std::endl
115 <<
" (5)\ta " << *p.a << std::endl
116 <<
" (6)\tlda " << p.lda << std::endl
117 <<
" (7)\tvl " << p.vl << std::endl
118 <<
" (8)\tvu " << p.vu << std::endl
119 <<
" (9)\til " << p.il << std::endl
120 <<
" (10)\tiu " << p.iu << std::endl
121 <<
" (11)\tabstol " << p.abstol << std::endl
122 <<
" (12)\tm " << p.m << std::endl
123 <<
" (13)\tw " << p.w << std::endl
124 <<
" (14)\tz " << p.z << std::endl
125 <<
" (15)\tldz " << p.ldz << std::endl
126 <<
" (16)\twork " << *p.work << std::endl
127 <<
" (17)\tlwork " << p.lwork << std::endl
128 <<
" (18)\tiwork " << *p.iwork << std::endl
129 <<
" (19)\tifail " << *p.ifail << std::endl
130 <<
" (20)\tinfo " << p.info
141 int dsyevx_(
char *jobz,
char *range,
char *uplo, integer *n, doublereal *a, integer *lda, doublereal *vl,
142 doublereal *vu, integer *il, integer *iu, doublereal *abstol, integer *m, doublereal *w, doublereal *z,
143 integer *ldz, doublereal *work, integer* lwork, integer* iwork, integer* ifail, integer* info );
148 template<
typename float_t >
152 VMMLIB_ERROR(
"not implemented for this type.", VMMLIB_HERE );
158 sym_eigs_call( eigs_params< float >& p )
189 sym_eigs_call( eigs_params< double >& p )
220 template<
size_t N,
typename float_t >
229 typedef typename evalues_type::iterator evalue_iterator;
230 typedef typename evalues_type::const_iterator evalue_const_iterator;
232 typedef std::pair< float_t, size_t > eigv_pair_type;
262 inline bool test_success( lapack::lapack_int info );
271 inline bool operator()(
const eigv_pair_type& a,
const eigv_pair_type& b )
273 return fabs( a.first ) > fabs( b.first );
280 template<
size_t N,
typename float_t >
298 p.work =
new float_t;
300 p.iwork =
new lapack::lapack_int[5*N];
301 p.ifail =
new lapack::lapack_int[N];
305 lapack::sym_eigs_call( p );
307 p.lwork =
static_cast< lapack::lapack_int
>( p.work[0] );
310 p.work =
new float_t[ p.lwork ];
316 template<
size_t N,
typename float_t >
317 lapack_sym_eigs< N, float_t >::~lapack_sym_eigs()
324 template<
size_t N,
typename float_t >
326 lapack_sym_eigs< N, float_t >::compute_all(
327 const m_input_type& A,
328 evectors_type& eigvectors_,
329 evalues_type& eigvalues_
333 m_input_type* AA =
new m_input_type( A );
338 p.w = eigvalues_.array;
339 p.z = eigvectors_.array;
343 lapack::sym_eigs_call< float_t >( p );
351 template<
size_t N,
typename float_t >
354 lapack_sym_eigs< N, float_t >::compute_x(
355 const m_input_type& A,
356 matrix< N, X, float_t >& eigvectors_,
357 vector< X, float_t >& eigvalues_
361 evectors_type* all_eigvectors =
new evectors_type;
362 evalues_type* all_eigvalues =
new evalues_type;
363 compute_all( A, *all_eigvectors, *all_eigvalues );
367 std::vector< eigv_pair_type >* eig_permutations =
new std::vector< eigv_pair_type >;
369 evalue_const_iterator it = all_eigvalues->begin(), it_end = all_eigvalues->end();
371 for( ; it != it_end; ++it, ++counter )
373 eig_permutations->push_back( eigv_pair_type( *it, counter ) );
377 eig_permutations->begin(),
378 eig_permutations->end(),
382 delete all_eigvalues;
385 evectors_type* sorted_eigvectors =
new evectors_type;
386 evalues_type* sorted_eigvalues =
new evalues_type;
387 typename std::vector< eigv_pair_type >::const_iterator it2 = eig_permutations->begin(), it2_end = eig_permutations->end();
388 evalue_iterator evalues_it = sorted_eigvalues->begin();
390 for( counter = 0; it2 != it2_end; ++it2, ++evalues_it, ++counter )
392 *evalues_it = it2->first;
393 sorted_eigvectors->set_column( counter, all_eigvectors->get_column( it2->second ));
395 delete all_eigvectors;
396 delete eig_permutations;
399 typename vector< X, float_t >::iterator it3 = eigvalues_.begin(), it3_end = eigvalues_.end();
400 evalues_it = sorted_eigvalues->begin();
401 for( ; it3 != it3_end; ++it3, ++evalues_it )
406 sorted_eigvectors->get_sub_matrix( eigvectors_ );
408 delete sorted_eigvectors;
409 delete sorted_eigvalues;
414 template<
size_t N,
typename float_t >
416 lapack_sym_eigs< N, float_t >::compute_1st(
417 const m_input_type& A,
418 evector_type& eigvector_,
423 evectors_type* all_eigvectors =
new evectors_type;
424 evalues_type* all_eigvalues =
new evalues_type;
425 compute_all( A, *all_eigvectors, *all_eigvalues );
429 std::vector< eigv_pair_type >* eig_permutations =
new std::vector< eigv_pair_type >;
431 evalue_const_iterator it = all_eigvalues->begin(), it_end = all_eigvalues->end();
433 for( ; it != it_end; ++it, ++counter )
435 eig_permutations->push_back( eigv_pair_type( *it, counter ) );
439 eig_permutations->begin(),
440 eig_permutations->end(),
445 typename std::vector< eigv_pair_type >::const_iterator it2 = eig_permutations->begin();
447 eigvalue_ = it2->first;
448 all_eigvectors->get_column( it2->second, eigvector_ );
450 delete eig_permutations;
451 delete all_eigvalues;
452 delete all_eigvectors;