ARPACK-Eigen
SelectionRule.h
Go to the documentation of this file.
1 #ifndef SELECTION_RULE_H
2 #define SELECTION_RULE_H
3 
4 #include <cmath>
5 #include <complex>
6 #include <utility>
7 
13 
18 {
19 
21 
26 
28 
30 
33 
36 
38 
40 
42 };
44 
49 {
50  WHICH_LM = 0,
59 };
60 
62 
63 // Default comparator: an empty class without
64 // operator() definition, so it won't compile
65 // when operator() is called on this class
66 template <typename Scalar, int SelectionRule>
67 class EigenvalueComparator
68 {
69 public:
70  typedef std::pair<Scalar, int> SortPair;
71 };
72 
73 // Specialization for LARGEST_MAGN
74 // This covers [float, double, complex] x [LARGEST_MAGN]
75 template <typename Scalar>
76 class EigenvalueComparator<Scalar, LARGEST_MAGN>
77 {
78 public:
79  typedef std::pair<Scalar, int> SortPair;
80 
81  bool operator() (SortPair v1, SortPair v2)
82  {
83  return std::abs(v1.first) > std::abs(v2.first);
84  }
85 };
86 
87 // Specialization for LARGEST_REAL
88 // This covers [complex] x [LARGEST_REAL]
89 template <typename RealType>
90 class EigenvalueComparator<std::complex<RealType>, LARGEST_REAL>
91 {
92 public:
93  typedef std::pair<std::complex<RealType>, int> SortPair;
94 
95  bool operator() (SortPair v1, SortPair v2)
96  {
97  return v1.first.real() > v2.first.real();
98  }
99 };
100 
101 // Specialization for LARGEST_IMAG
102 // This covers [complex] x [LARGEST_IMAG]
103 template <typename RealType>
104 class EigenvalueComparator<std::complex<RealType>, LARGEST_IMAG>
105 {
106 public:
107  typedef std::pair<std::complex<RealType>, int> SortPair;
108 
109  bool operator() (SortPair v1, SortPair v2)
110  {
111  return std::abs(v1.first.imag()) > std::abs(v2.first.imag());
112  }
113 };
114 
115 // Specialization for LARGEST_ALGE
116 // This covers [float, double] x [LARGEST_ALGE]
117 template <typename Scalar>
118 class EigenvalueComparator<Scalar, LARGEST_ALGE>
119 {
120 public:
121  typedef std::pair<Scalar, int> SortPair;
122 
123  bool operator() (SortPair v1, SortPair v2)
124  {
125  return v1.first > v2.first;
126  }
127 };
128 
129 // Here BOTH_ENDS is the same as LARGEST_ALGE, but
130 // we need some additional steps, which are done in
131 // SymEigsSolver.h => retrieve_ritzpair().
132 // There we move the smallest values to the proper locations.
133 template <typename Scalar>
134 class EigenvalueComparator<Scalar, BOTH_ENDS>
135 {
136 public:
137  typedef std::pair<Scalar, int> SortPair;
138 
139  bool operator() (SortPair v1, SortPair v2)
140  {
141  return v1.first > v2.first;
142  }
143 };
144 
145 // Specialization for SMALLEST_MAGN
146 // This covers [float, double, complex] x [SMALLEST_MAGN]
147 template <typename Scalar>
148 class EigenvalueComparator<Scalar, SMALLEST_MAGN>
149 {
150 public:
151  typedef std::pair<Scalar, int> SortPair;
152 
153  bool operator() (SortPair v1, SortPair v2)
154  {
155  return std::abs(v1.first) <= std::abs(v2.first);
156  }
157 };
158 
159 // Specialization for SMALLEST_REAL
160 // This covers [complex] x [SMALLEST_REAL]
161 template <typename RealType>
162 class EigenvalueComparator<std::complex<RealType>, SMALLEST_REAL>
163 {
164 public:
165  typedef std::pair<std::complex<RealType>, int> SortPair;
166 
167  bool operator() (SortPair v1, SortPair v2)
168  {
169  return v1.first.real() <= v2.first.real();
170  }
171 };
172 
173 // Specialization for SMALLEST_IMAG
174 // This covers [complex] x [SMALLEST_IMAG]
175 template <typename RealType>
176 class EigenvalueComparator<std::complex<RealType>, SMALLEST_IMAG>
177 {
178 public:
179  typedef std::pair<std::complex<RealType>, int> SortPair;
180 
181  bool operator() (SortPair v1, SortPair v2)
182  {
183  return std::abs(v1.first.imag()) <= std::abs(v2.first.imag());
184  }
185 };
186 
187 // Specialization for SMALLEST_ALGE
188 // This covers [float, double] x [SMALLEST_ALGE]
189 template <typename Scalar>
190 class EigenvalueComparator<Scalar, SMALLEST_ALGE>
191 {
192 public:
193  typedef std::pair<Scalar, int> SortPair;
194 
195  bool operator() (SortPair v1, SortPair v2)
196  {
197  return v1.first <= v2.first;
198  }
199 };
200 
202 
203 #endif // SELECTION_RULE_H
Alias for LARGEST_ALGE
Definition: SelectionRule.h:53
Alias for LARGEST_REAL
Definition: SelectionRule.h:51
Alias for BOTH_ENDS
Definition: SelectionRule.h:58
Alias for SMALLEST_ALGE
Definition: SelectionRule.h:57
Select eigenvalues with smallest imaginary part (in magnitude). Only for general eigen solvers...
Definition: SelectionRule.h:37
Select eigenvalues with largest imaginary part (in magnitude). Only for general eigen solvers...
Definition: SelectionRule.h:27
Alias for SMALLEST_IMAG
Definition: SelectionRule.h:56
SELECT_EIGENVALUE
Definition: SelectionRule.h:17
Select eigenvalues with largest real part. Only for general eigen solvers.
Definition: SelectionRule.h:25
Alias for SMALLEST_MAGN
Definition: SelectionRule.h:54
Alias for SMALLEST_REAL
Definition: SelectionRule.h:55
Alias for LARGEST_MAGN
Definition: SelectionRule.h:50
SELECT_EIGENVALUE_ALIAS
Definition: SelectionRule.h:48
Select eigenvalues with smallest algebraic value. Only for symmetric eigen solvers.
Definition: SelectionRule.h:39
Select eigenvalues with smallest real part. Only for general eigen solvers.
Definition: SelectionRule.h:35
Alias for LARGEST_IMAG
Definition: SelectionRule.h:52