iterative-solver 0.0
util.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_UTIL_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_UTIL_H
3#include <molpro/Profiler.h>
4#include <molpro/linalg/itsolv/ArrayHandlers.h>
5#include <molpro/linalg/itsolv/subspace/Matrix.h>
6#include <molpro/linalg/itsolv/wrap.h>
7
8#include <locale>
9#include <map>
10#include <string>
11
13
22template <typename value_type, typename value_type_abs>
23void remove_null_vectors(subspace::Matrix<value_type>& lin_trans, std::vector<value_type_abs>& norm, const size_t start,
24 const size_t end, const value_type_abs norm_thresh) {
25 for (size_t i = start, j = start; i < end; ++i) {
26 if (norm[j] < norm_thresh) {
27 norm.erase(begin(norm) + j);
28 lin_trans.remove_row(j);
29 } else
30 ++j;
31 }
32}
33
38template <class ForwardIt, class EndIterator, typename Int>
39bool is_iota(ForwardIt it_start, EndIterator it_end, Int value_start) {
40 bool result = true;
41 for (auto it = it_start; it != it_end && result; ++it, ++value_start)
42 result = (*it) == value_start;
43 return result;
44}
45
47template <class R, class Q>
49 auto q = handler.copy(param);
50 handler.fill(0, q);
51 return q;
52}
53
69template <class R, class Q, class P>
70void construct_solutions(const VecRef<R>& params, const std::vector<int>& roots,
71 const subspace::Matrix<double>& solutions, const CVecRef<P>& pparams,
72 const CVecRef<Q>& qparams, const CVecRef<Q>& dparams, size_t oP, size_t oQ, size_t oD,
74 array::ArrayHandler<R, Q>& handler_rq) {
75 auto prof = molpro::Profiler::single();
76 prof->start("itsolv::util::construct_solutions");
77 assert(params.size() >= roots.size());
78 for (size_t i = 0; i < roots.size(); ++i)
79 handler_rr.fill(0, params.at(i));
80 for (size_t i = 0; i < roots.size(); ++i) {
81 auto root = roots[i];
82 for (size_t j = 0; j < pparams.size(); ++j)
83 handler_rp.axpy(solutions(root, oP + j), pparams.at(j), params.at(i));
84 for (size_t j = 0; j < qparams.size(); ++j)
85 handler_rq.axpy(solutions(root, oQ + j), qparams.at(j), params.at(i));
86 for (size_t j = 0; j < dparams.size(); ++j)
87 handler_rq.axpy(solutions(root, oD + j), dparams.at(j), params.at(i));
88 }
89 prof->stop();
90}
91
97template <class Container>
98void delete_parameters(std::vector<int> indices, Container& params) {
99 std::sort(std::begin(indices), std::end(indices), std::greater<int>());
100 for (auto i : indices)
101 params.erase(begin(params) + i);
102}
103
106public:
107 std::string toupper(std::string in) const;
108 std::string tolower(std::string in) const;
109 bool tobool(const std::string& in) const;
110 static void crop_space(std::string& path);
111 static std::map<std::string, std::string> parse_keyval_string(std::string s);
112
113private:
114 const std::ctype<char>& facet = std::use_facet<std::ctype<char>>(std::locale());
115};
116
117} // namespace molpro::linalg::itsolv::util
118#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_UTIL_H
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition: ArrayHandler.h:162
virtual AL copy(const AR &source)=0
virtual void axpy(value_type alpha, const AR &x, AL &y)=0
virtual void fill(value_type alpha, AL &x)=0
void remove_row(index_type row)
removes a row from the matrix
Definition: Matrix.h:142
Wraps some useful string manipulation functions.
Definition: util.h:105
static std::map< std::string, std::string > parse_keyval_string(std::string s)
Definition: util.cpp:38
bool tobool(const std::string &in) const
Definition: util.cpp:14
std::string tolower(std::string in) const
Definition: util.cpp:9
std::string toupper(std::string in) const
Definition: util.cpp:4
static void crop_space(std::string &path)
Definition: util.cpp:28
static std::shared_ptr< Profiler > single()
Definition: ArrayHandlers.h:8
void remove_null_vectors(subspace::Matrix< value_type > &lin_trans, std::vector< value_type_abs > &norm, const size_t start, const size_t end, const value_type_abs norm_thresh)
Remove vectors considered null from the linear transformation matrix.
Definition: util.h:23
void construct_solutions(const VecRef< R > &params, const std::vector< int > &roots, const subspace::Matrix< double > &solutions, const CVecRef< P > &pparams, const CVecRef< Q > &qparams, const CVecRef< Q > &dparams, size_t oP, size_t oQ, size_t oD, array::ArrayHandler< R, R > &handler_rr, array::ArrayHandler< R, P > &handler_rp, array::ArrayHandler< R, Q > &handler_rq)
Construct solutions.
Definition: util.h:70
Q construct_zeroed_copy(const R &param, array::ArrayHandler< Q, R > &handler)
Copy R parameter to Q and zero it. This ensures same size and distribution of the copy.
Definition: util.h:48
bool is_iota(ForwardIt it_start, EndIterator it_end, Int value_start)
Returns true if iterator range contains integers starting with value_start and sequentially increment...
Definition: util.h:39
void delete_parameters(std::vector< int > indices, Container &params)
Removes parameters.
Definition: util.h:98
std::vector< std::reference_wrapper< const A > > CVecRef
Definition: wrap.h:14
std::vector< std::reference_wrapper< A > > VecRef
Definition: wrap.h:11