iterative-solver 0.0
helper.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITERATIVESOLVER_HELPER_H_
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITERATIVESOLVER_HELPER_H_
3#include <complex>
4#include <cstddef>
5#include <list>
6#include <molpro/iostream.h>
7#include <molpro/linalg/array/Span.h>
8#include <vector>
9#include <span>
10
12template <typename T>
13struct is_complex : std::false_type {};
14
15template <typename T>
16struct is_complex<std::complex<T>> : std::true_type {};
17
19template <typename T>
20struct SVD {
21 using value_type = T;
23 std::vector<value_type> u;
24 std::vector<value_type> v;
25};
26
27int eigensolver_lapacke_dsyev(std::span<const double> matrix, std::span<double> eigenvectors,
28 std::span<double> eigenvalues, const size_t dimension);
29
30std::list<SVD<double>> eigensolver_lapacke_dsyev(size_t dimension, std::span<const double> matrix);
31
32template <typename value_type>
33size_t get_rank(std::vector<value_type> eigenvalues, value_type threshold);
34
35template <typename value_type>
36size_t get_rank(std::list<SVD<value_type>> svd_system, value_type threshold);
37
47template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
48std::list<SVD<value_type>> svd_system(size_t nrows, size_t ncols, const array::Span<value_type>& m, double threshold,
49 bool hermitian = false, bool reduce_to_rank = false);
50template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
51std::list<SVD<value_type>> svd_system(size_t nrows, size_t ncols, const array::Span<value_type>& m, double threshold,
52 bool hermitian = false, bool reduce_to_rank = false);
53
54template <typename value_type>
55void printMatrix(const std::vector<value_type>&, size_t rows, size_t cols, std::string title = "",
56 std::ostream& s = molpro::cout);
57
58template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
59void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
60 const std::vector<value_type>& matrix, const std::vector<value_type>& metric, size_t dimension,
61 bool hermitian, double svdThreshold, int verbosity, bool condone_complex);
62
63template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
64void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
65 const std::vector<value_type>& matrix, const std::vector<value_type>& metric, size_t dimension,
66 bool hermitian, double svdThreshold, int verbosity, bool condone_complex);
67
68template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
69void solve_LinearEquations(std::vector<value_type>& solution, std::vector<value_type>& eigenvalues,
70 const std::vector<value_type>& matrix, const std::vector<value_type>& metric,
71 const std::vector<value_type>& rhs, size_t dimension, size_t nroot, double augmented_hessian,
72 double svdThreshold, int verbosity);
73
74template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
75void solve_LinearEquations(std::vector<value_type>& solution, std::vector<value_type>& eigenvalues,
76 const std::vector<value_type>& matrix, const std::vector<value_type>& metric,
77 const std::vector<value_type>& rhs, size_t dimension, size_t nroot, double augmented_hessian,
78 double svdThreshold, int verbosity);
79
80template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
81void solve_DIIS(std::vector<value_type>& solution, const std::vector<value_type>& matrix, size_t dimension,
82 double svdThreshold, int verbosity = 0);
83template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
84void solve_DIIS(std::vector<value_type>& solution, const std::vector<value_type>& matrix, size_t dimension,
85 double svdThreshold, int verbosity = 0);
86
87/*
88 * Explicit instantiation of double type
89 */
90
91extern template void printMatrix<double>(const std::vector<double>&, size_t rows, size_t cols, std::string title,
92 std::ostream& s);
93
94extern template std::list<SVD<double>> svd_system(size_t nrows, size_t ncols, const array::Span<double>& m,
95 double threshold, bool hermitian, bool reduce_to_rank);
96
97extern template void eigenproblem<double>(std::vector<double>& eigenvectors, std::vector<double>& eigenvalues,
98 const std::vector<double>& matrix, const std::vector<double>& metric,
99 const size_t dimension, bool hermitian, double svdThreshold, int verbosity,
100 bool condone_complex);
101
102extern template void solve_LinearEquations<double>(std::vector<double>& solution, std::vector<double>& eigenvalues,
103 const std::vector<double>& matrix, const std::vector<double>& metric,
104 const std::vector<double>& rhs, size_t dimension, size_t nroot,
105 double augmented_hessian, double svdThreshold, int verbosity);
106
107extern template void solve_DIIS<double>(std::vector<double>& solution, const std::vector<double>& matrix,
108 const size_t dimension, double svdThreshold, int verbosity);
109
110/*
111 * Explicit instantiation of std::complex<double> type
112 */
113extern template void printMatrix<std::complex<double>>(const std::vector<std::complex<double>>&, size_t rows,
114 size_t cols, std::string title, std::ostream& s);
115
116extern template std::list<SVD<std::complex<double>>> svd_system(size_t nrows, size_t ncols,
117 const array::Span<std::complex<double>>& m,
118 double threshold, bool hermitian, bool reduce_to_rank);
119
120extern template void eigenproblem<std::complex<double>>(std::vector<std::complex<double>>& eigenvectors,
121 std::vector<std::complex<double>>& eigenvalues,
122 const std::vector<std::complex<double>>& matrix,
123 const std::vector<std::complex<double>>& metric,
124 const size_t dimension, bool hermitian, double svdThreshold,
125 int verbosity, bool condone_complex);
126
127extern template void solve_LinearEquations<std::complex<double>>(
128 std::vector<std::complex<double>>& solution, std::vector<std::complex<double>>& eigenvalues,
129 const std::vector<std::complex<double>>& matrix, const std::vector<std::complex<double>>& metric,
130 const std::vector<std::complex<double>>& rhs, size_t dimension, size_t nroot, double augmented_hessian,
131 double svdThreshold, int verbosity);
132
133extern template void solve_DIIS<std::complex<double>>(std::vector<std::complex<double>>& solution,
134 const std::vector<std::complex<double>>& matrix,
135 const size_t dimension, double svdThreshold, int verbosity);
136} // namespace molpro::linalg::itsolv
137#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ITERATIVESOLVER_HELPER_H_
Non-owning container taking a pointer to the data buffer and its size and exposing routines for itera...
Definition: Span.h:31
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition: helper.h:11
template void printMatrix< double >(const std::vector< double > &, size_t rows, size_t cols, std::string title, std::ostream &s)
template void eigenproblem< double >(std::vector< double > &eigenvectors, std::vector< double > &eigenvalues, const std::vector< double > &matrix, const std::vector< double > &metric, const size_t dimension, bool hermitian, double svdThreshold, int verbosity, bool condone_complex)
template void solve_DIIS< double >(std::vector< double > &solution, const std::vector< double > &matrix, const size_t dimension, double svdThreshold, int verbosity)
int eigensolver_lapacke_dsyev(std::span< const double > matrix, std::span< double > eigenvectors, std::span< double > eigenvalues, const size_t dimension)
Definition: helper-implementation.h:143
std::list< SVD< value_type > > svd_system(size_t nrows, size_t ncols, const array::Span< value_type > &m, double threshold, bool hermitian=false, bool reduce_to_rank=false)
Performs singular value decomposition and returns SVD objects for singular values less than threshold...
Definition: helper-implementation.h:268
void solve_LinearEquations(std::vector< value_type > &solution, std::vector< value_type > &eigenvalues, const std::vector< value_type > &matrix, const std::vector< value_type > &metric, const std::vector< value_type > &rhs, size_t dimension, size_t nroot, double augmented_hessian, double svdThreshold, int verbosity)
Definition: helper-implementation.h:486
size_t get_rank(std::vector< value_type > eigenvalues, value_type threshold)
template void solve_LinearEquations< double >(std::vector< double > &solution, std::vector< double > &eigenvalues, const std::vector< double > &matrix, const std::vector< double > &metric, const std::vector< double > &rhs, size_t dimension, size_t nroot, double augmented_hessian, double svdThreshold, int verbosity)
void solve_DIIS(std::vector< value_type > &solution, const std::vector< value_type > &matrix, size_t dimension, double svdThreshold, int verbosity=0)
Definition: helper-implementation.h:560
void eigenproblem(std::vector< value_type > &eigenvectors, std::vector< value_type > &eigenvalues, const std::vector< value_type > &matrix, const std::vector< value_type > &metric, size_t dimension, bool hermitian, double svdThreshold, int verbosity, bool condone_complex)
Definition: helper-implementation.h:316
void printMatrix(const std::vector< value_type > &, size_t rows, size_t cols, std::string title="", std::ostream &s=molpro::cout)
Definition: helper-implementation.h:310
Stores a singular value and corresponding left and right singular vectors.
Definition: helper.h:20
std::vector< value_type > v
right singular vector
Definition: helper.h:24
T value_type
Definition: helper.h:21
value_type value
Definition: helper.h:22
std::vector< value_type > u
left singular vector
Definition: helper.h:23
Definition: helper.h:13