lambda-lanczos 2.0.0
Loading...
Searching...
No Matches
eigenpair_manager.hpp
Go to the documentation of this file.
1#ifndef LAMBDA_LANCZOS_EIGENPAIR_MANAGER_H_
2#define LAMBDA_LANCZOS_EIGENPAIR_MANAGER_H_
3
4#include <vector>
5#include <functional>
6
8
9
10namespace lambda_lanczos { namespace eigenpair_manager {
11
12
22template <typename T>
24private:
25 template <typename n_type>
27
28 const bool find_maximum;
29 const size_t num_eigs;
30
31 std::multimap<real_t<T>, std::vector<T>, std::function<bool (real_t<T>, real_t<T>)>> eigenpairs;
32 // This super long definition is required because the default comparator type is std::less<?>.
33
34public:
37 std::function<bool (real_t<T>,real_t<T>)> comp;
38 if(find_maximum) {
39 comp = std::greater<real_t<T>>();
40 } else {
41 comp =std::less<real_t<T>>();
42 }
43
44 std::vector<std::pair<real_t<T>, std::vector<T>>> dummy;
45 this->eigenpairs =
46 std::multimap<real_t<T>, std::vector<T>, std::function<bool (real_t<T>, real_t<T>)>>(dummy.begin(), dummy.end(), comp);
47 // This super long definition is required because the default comparator type is std::less<?>.
48 }
49
50 size_t size() const {
51 return eigenpairs.size();
52 }
53
54 bool insertEigenpairs(std::vector<real_t<T>>& eigenvalues,
55 std::vector<std::vector<T>>& eigenvectors) {
56 assert(eigenvalues.size() == eigenvectors.size());
57
58 bool nothing_added = true;
59 for(size_t i = 0; i < eigenvalues.size(); ++i) {
60 auto inserted = eigenpairs.emplace(std::move(eigenvalues[i]), std::move(eigenvectors[i]));
61 auto last = eigenpairs.end();
62 last--;
63 if(eigenpairs.size() > num_eigs) {
64 if(inserted != last) { // If the eigenpair is not inserted to the tail
65 nothing_added = false;
66 }
67 eigenpairs.erase(last);
68 } else {
69 nothing_added = false;
70 }
71 }
72
73 return nothing_added;
74 }
75
78 }
79
81 return eigenpairs;
82 };
83};
84
85}}
86#endif /* LAMBDA_LANCZOS_EIGENPAIR_MANAGER_H_ */
Class to manage calculated eigenpairs.
Definition: eigenpair_manager.hpp:23
EigenPairManager(bool find_maximum, size_t num_eigs)
Definition: eigenpair_manager.hpp:35
size_t size() const
Definition: eigenpair_manager.hpp:50
const size_t num_eigs
Definition: eigenpair_manager.hpp:29
const bool find_maximum
Definition: eigenpair_manager.hpp:28
std::multimap< real_t< T >, std::vector< T >, std::function< bool(real_t< T >, real_t< T >)> > eigenpairs
Definition: eigenpair_manager.hpp:31
decltype(eigenpairs) & getEigenpairs()
Definition: eigenpair_manager.hpp:80
lambda_lanczos::util::MapValueIterable< decltype(eigenpairs)> getEigenvectors() const
Definition: eigenpair_manager.hpp:76
bool insertEigenpairs(std::vector< real_t< T > > &eigenvalues, std::vector< std::vector< T > > &eigenvectors)
Definition: eigenpair_manager.hpp:54
util::real_t< n_type > real_t
Definition: eigenpair_manager.hpp:26
Definition: lambda_lanczos_util.hpp:59
typename realTypeMap< T >::type real_t
Type mapper from T to real type of T.
Definition: lambda_lanczos_util.hpp:103
Definition: eigenpair_manager.hpp:10