14#ifndef ANASAZI_BASIC_SORT_HPP
15#define ANASAZI_BASIC_SORT_HPP
26#include "Teuchos_LAPACK.hpp"
27#include "Teuchos_ScalarTraits.hpp"
28#include "Teuchos_ParameterList.hpp"
32 template<
class MagnitudeType>
79 void sort(std::vector<MagnitudeType> &
evals, Teuchos::RCP<std::vector<int> >
perm = Teuchos::null,
int n = -1)
const;
100 std::vector<MagnitudeType> &
i_evals,
101 Teuchos::RCP<std::vector<int> >
perm = Teuchos::null,
115 template <
class LTorGT>
118 bool operator()(MagnitudeType, MagnitudeType);
120 template <
class First,
class Second>
121 bool operator()(std::pair<First,Second>, std::pair<First,Second>);
124 template <
class LTorGT>
127 bool operator()(std::pair<MagnitudeType,MagnitudeType>, std::pair<MagnitudeType,MagnitudeType>);
129 template <
class First,
class Second>
130 bool operator()(std::pair<First,Second>, std::pair<First,Second>);
133 template <
class LTorGT>
136 bool operator()(MagnitudeType, MagnitudeType);
137 template <
class First,
class Second>
138 bool operator()(std::pair<First,Second>, std::pair<First,Second>);
141 template <
typename pair_type>
144 const typename pair_type::first_type &operator()(
const pair_type &
v)
const;
147 template <
typename pair_type>
150 const typename pair_type::second_type &operator()(
const pair_type &
v)
const;
159 template<
class MagnitudeType>
162 std::string
which =
"LM";
167 template<
class MagnitudeType>
173 template<
class MagnitudeType>
177 template<
class MagnitudeType>
182 std::transform(
which.begin(),
which.end(),
whichlc.begin(),(
int(*)(
int)) std::toupper);
206 template<
class MagnitudeType>
214 std::invalid_argument,
"Anasazi::BasicSort::sort(r): eigenvalue vector size isn't consistent with n.");
215 if (
perm != Teuchos::null) {
217 std::invalid_argument,
"Anasazi::BasicSort::sort(r): permutation vector size isn't consistent with n.");
220 typedef std::greater<MagnitudeType>
greater_mt;
221 typedef std::less<MagnitudeType>
less_mt;
223 if (
perm == Teuchos::null) {
230 else if (which_ == SM) {
233 else if (which_ == LR) {
236 else if (which_ == SR) {
253 std::vector< std::pair<MagnitudeType,int> >
pairs(
n);
254 for (
int i=0;
i<
n;
i++) {
262 else if (which_ == SM) {
265 else if (which_ == LR) {
268 else if (which_ == SR) {
276 std::transform(
pairs.begin(),
pairs.end(),
evals.begin(),sel1st< std::pair<MagnitudeType,int> >());
277 std::transform(
pairs.begin(),
pairs.end(),
perm->begin(),sel2nd< std::pair<MagnitudeType,int> >());
282 template<
class T1,
class T2>
285 std::pair<T1,T2> operator()(
const T1 &
t1,
const T2 &
t2 )
286 {
return std::make_pair(
t1,
t2); }
290 template<
class MagnitudeType>
292 std::vector<MagnitudeType> &
i_evals,
293 Teuchos::RCP< std::vector<int> >
perm,
305 std::invalid_argument,
"Anasazi::BasicSort::sort(r,i): eigenvalue vector size isn't consistent with n.");
306 if (
perm != Teuchos::null) {
308 std::invalid_argument,
"Anasazi::BasicSort::sort(r,i): permutation vector size isn't consistent with n.");
311 typedef std::greater<MagnitudeType>
greater_mt;
312 typedef std::less<MagnitudeType>
less_mt;
317 if (
perm == Teuchos::null) {
321 std::vector< std::pair<MagnitudeType,MagnitudeType> >
pairs(
n);
325 if (which_ == LR || which_ == SR || which_ == LM || which_ == SM) {
338 if (which_ == LR || which_ == LI) {
341 else if (which_ == SR || which_ == SI) {
344 else if (which_ == LM) {
354 if (which_ == LR || which_ == SR || which_ == LM || which_ == SM) {
355 std::transform(
pairs.begin(),
pairs.end(),
r_evals.begin(),sel1st< std::pair<MagnitudeType,MagnitudeType> >());
356 std::transform(
pairs.begin(),
pairs.end(),
i_evals.begin(),sel2nd< std::pair<MagnitudeType,MagnitudeType> >());
359 std::transform(
pairs.begin(),
pairs.end(),
r_evals.begin(),sel2nd< std::pair<MagnitudeType,MagnitudeType> >());
360 std::transform(
pairs.begin(),
pairs.end(),
i_evals.begin(),sel1st< std::pair<MagnitudeType,MagnitudeType> >());
367 std::vector< std::pair< std::pair<MagnitudeType,MagnitudeType>,
int > >
pairs(
n);
371 if (which_ == LR || which_ == SR || which_ == LM || which_ == SM) {
372 for (
int i=0;
i<
n;
i++) {
377 for (
int i=0;
i<
n;
i++) {
382 if (which_ == LR || which_ == LI) {
385 else if (which_ == SR || which_ == SI) {
388 else if (which_ == LM) {
398 if (which_ == LR || which_ == SR || which_ == LM || which_ == SM) {
399 for (
int i=0;
i<
n;
i++) {
406 for (
int i=0;
i<
n;
i++) {
416 template<
class MagnitudeType>
417 template<
class LTorGT>
420 typedef Teuchos::ScalarTraits<MagnitudeType>
MTT;
422 return comp( MTT::magnitude(
v1), MTT::magnitude(
v2) );
425 template<
class MagnitudeType>
426 template<
class LTorGT>
427 bool BasicSort<MagnitudeType>::compMag2<LTorGT>::operator()(std::pair<MagnitudeType,MagnitudeType> v1, std::pair<MagnitudeType,MagnitudeType> v2)
429 MagnitudeType m1 = v1.first*v1.first + v1.second*v1.second;
430 MagnitudeType m2 = v2.first*v2.first + v2.second*v2.second;
432 return comp( m1, m2 );
435 template<
class MagnitudeType>
436 template<
class LTorGT>
437 bool BasicSort<MagnitudeType>::compAlg<LTorGT>::operator()(MagnitudeType v1, MagnitudeType v2)
440 return comp( v1, v2 );
443 template<
class MagnitudeType>
444 template<
class LTorGT>
445 template<
class First,
class Second>
446 bool BasicSort<MagnitudeType>::compMag<LTorGT>::operator()(std::pair<First,Second> v1, std::pair<First,Second> v2) {
447 return (*
this)(v1.first,v2.first);
450 template<
class MagnitudeType>
451 template<
class LTorGT>
452 template<
class First,
class Second>
453 bool BasicSort<MagnitudeType>::compMag2<LTorGT>::operator()(std::pair<First,Second> v1, std::pair<First,Second> v2) {
454 return (*
this)(v1.first,v2.first);
457 template<
class MagnitudeType>
458 template<
class LTorGT>
459 template<
class First,
class Second>
460 bool BasicSort<MagnitudeType>::compAlg<LTorGT>::operator()(std::pair<First,Second> v1, std::pair<First,Second> v2) {
461 return (*
this)(v1.first,v2.first);
464 template <
class MagnitudeType>
465 template <
typename pair_type>
466 const typename pair_type::first_type &
467 BasicSort<MagnitudeType>::sel1st<pair_type>::operator()(
const pair_type &v)
const
472 template <
class MagnitudeType>
473 template <
typename pair_type>
474 const typename pair_type::second_type &
475 BasicSort<MagnitudeType>::sel2nd<pair_type>::operator()(
const pair_type &v)
const
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Virtual base class which defines the interface between an eigensolver and a class whose job is the so...
An implementation of the Anasazi::SortManager that performs a collection of common sorting techniques...
virtual ~BasicSort()
Destructor.
BasicSort(Teuchos::ParameterList &pl)
Parameter list driven constructor.
void sort(std::vector< MagnitudeType > &evals, Teuchos::RCP< std::vector< int > > perm=Teuchos::null, int n=-1) const
Sort real eigenvalues, optionally returning the permutation vector.
void setSortType(const std::string &which)
Set sort type.
Anasazi's templated virtual class for constructing an operator that can interface with the OperatorTr...
Operator()
Default constructor.
SortManagerError is thrown when the Anasazi::SortManager is unable to sort the numbers,...
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.