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
11template <typename T>
12struct is_complex : std::false_type {};
13
14template <typename T>
15struct is_complex<std::complex<T>> : std::true_type {};
16
18template <typename T>
19struct SVD {
20 using value_type = T;
22 std::vector<value_type> u;
23 std::vector<value_type> v;
24};
25
26int eigensolver_lapacke_dsyev(const std::vector<double>& matrix, std::vector<double>& eigenvectors,
27 std::vector<double>& eigenvalues, const size_t dimension);
28
29std::list<SVD<double>> eigensolver_lapacke_dsyev(size_t dimension, std::vector<double>& matrix);
30
31std::list<SVD<double>> eigensolver_lapacke_dsyev(size_t dimension,
33
34template <typename value_type>
35size_t get_rank(std::vector<value_type> eigenvalues, value_type threshold);
36
37template <typename value_type>
38size_t get_rank(std::list<SVD<value_type>> svd_system, value_type threshold);
39
49template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
50std::list<SVD<value_type>> svd_system(size_t nrows, size_t ncols, const array::Span<value_type>& m, double threshold,
51 bool hermitian = false, bool reduce_to_rank = false);
52template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
53std::list<SVD<value_type>> svd_system(size_t nrows, size_t ncols, const array::Span<value_type>& m, double threshold,
54 bool hermitian = false, bool reduce_to_rank = false);
55
56template <typename value_type>
57void printMatrix(const std::vector<value_type>&, size_t rows, size_t cols, std::string title = "",
58 std::ostream& s = molpro::cout);
59
60template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
61void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
62 const std::vector<value_type>& matrix, const std::vector<value_type>& metric, size_t dimension,
63 bool hermitian, double svdThreshold, int verbosity, bool condone_complex);
64
65template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
66void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
67 const std::vector<value_type>& matrix, const std::vector<value_type>& metric, size_t dimension,
68 bool hermitian, double svdThreshold, int verbosity, bool condone_complex);
69
70template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
71void solve_LinearEquations(std::vector<value_type>& solution, std::vector<value_type>& eigenvalues,
72 const std::vector<value_type>& matrix, const std::vector<value_type>& metric,
73 const std::vector<value_type>& rhs, size_t dimension, size_t nroot, double augmented_hessian,
74 double svdThreshold, int verbosity);
75
76template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
77void solve_LinearEquations(std::vector<value_type>& solution, std::vector<value_type>& eigenvalues,
78 const std::vector<value_type>& matrix, const std::vector<value_type>& metric,
79 const std::vector<value_type>& rhs, size_t dimension, size_t nroot, double augmented_hessian,
80 double svdThreshold, int verbosity);
81
82template <typename value_type, typename std::enable_if_t<is_complex<value_type>{}, int> = 0>
83void solve_DIIS(std::vector<value_type>& solution, const std::vector<value_type>& matrix, size_t dimension,
84 double svdThreshold, int verbosity = 0);
85template <typename value_type, typename std::enable_if_t<!is_complex<value_type>{}, std::nullptr_t> = nullptr>
86void solve_DIIS(std::vector<value_type>& solution, const std::vector<value_type>& matrix, size_t dimension,
87 double svdThreshold, int verbosity = 0);
88
89/*
90 * Explicit instantiation of double type
91 */
92
93extern template void printMatrix<double>(const std::vector<double>&, size_t rows, size_t cols, std::string title,
94 std::ostream& s);
95
96extern template std::list<SVD<double>> svd_system(size_t nrows, size_t ncols, const array::Span<double>& m,
97 double threshold, bool hermitian, bool reduce_to_rank);
98
99extern template void eigenproblem<double>(std::vector<double>& eigenvectors, std::vector<double>& eigenvalues,
100 const std::vector<double>& matrix, const std::vector<double>& metric,
101 const size_t dimension, bool hermitian, double svdThreshold, int verbosity,
102 bool condone_complex);
103
104extern template void eigenproblem<double>(std::vector<double>& eigenvectors, std::vector<double>& eigenvalues,
105 const std::vector<double>& matrix, const std::vector<double>& metric,
106 const size_t dimension, bool hermitian, double svdThreshold, int verbosity,
107 bool condone_complex);
108
109extern template void solve_LinearEquations<double>(std::vector<double>& solution, std::vector<double>& eigenvalues,
110 const std::vector<double>& matrix, const std::vector<double>& metric,
111 const std::vector<double>& rhs, size_t dimension, size_t nroot,
112 double augmented_hessian, double svdThreshold, int verbosity);
113
114extern template void solve_LinearEquations<double>(std::vector<double>& solution, std::vector<double>& eigenvalues,
115 const std::vector<double>& matrix, const std::vector<double>& metric,
116 const std::vector<double>& rhs, size_t dimension, size_t nroot,
117 double augmented_hessian, double svdThreshold, int verbosity);
118
119extern template void solve_DIIS<double>(std::vector<double>& solution, const std::vector<double>& matrix,
120 const size_t dimension, double svdThreshold, int verbosity);
121
122/*
123 * Explicit instantiation of std::complex<double> type
124 */
125extern template void printMatrix<std::complex<double>>(const std::vector<std::complex<double>>&, size_t rows,
126 size_t cols, std::string title, std::ostream& s);
127
128extern template std::list<SVD<std::complex<double>>> svd_system(size_t nrows, size_t ncols,
129 const array::Span<std::complex<double>>& m,
130 double threshold, bool hermitian, bool reduce_to_rank);
131
132extern template void eigenproblem<std::complex<double>>(std::vector<std::complex<double>>& eigenvectors,
133 std::vector<std::complex<double>>& eigenvalues,
134 const std::vector<std::complex<double>>& matrix,
135 const std::vector<std::complex<double>>& metric,
136 const size_t dimension, bool hermitian, double svdThreshold,
137 int verbosity, bool condone_complex);
138
139extern template void eigenproblem<std::complex<double>>(std::vector<std::complex<double>>& eigenvectors,
140 std::vector<std::complex<double>>& eigenvalues,
141 const std::vector<std::complex<double>>& matrix,
142 const std::vector<std::complex<double>>& metric,
143 const size_t dimension, bool hermitian, double svdThreshold,
144 int verbosity, bool condone_complex);
145
146extern template void solve_LinearEquations<std::complex<double>>(
147 std::vector<std::complex<double>>& solution, std::vector<std::complex<double>>& eigenvalues,
148 const std::vector<std::complex<double>>& matrix, const std::vector<std::complex<double>>& metric,
149 const std::vector<std::complex<double>>& rhs, size_t dimension, size_t nroot, double augmented_hessian,
150 double svdThreshold, int verbosity);
151
152extern template void solve_LinearEquations<std::complex<double>>(
153 std::vector<std::complex<double>>& solution, std::vector<std::complex<double>>& eigenvalues,
154 const std::vector<std::complex<double>>& matrix, const std::vector<std::complex<double>>& metric,
155 const std::vector<std::complex<double>>& rhs, size_t dimension, size_t nroot, double augmented_hessian,
156 double svdThreshold, int verbosity);
157
158extern template void solve_DIIS<std::complex<double>>(std::vector<std::complex<double>>& solution,
159 const std::vector<std::complex<double>>& matrix,
160 const size_t dimension, double svdThreshold, int verbosity);
161} // namespace molpro::linalg::itsolv
162#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:28
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition: helper.h:10
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)
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:264
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:546
size_t get_rank(std::vector< value_type > eigenvalues, value_type threshold)
Definition: helper-implementation.h:222
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:620
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:312
int eigensolver_lapacke_dsyev(const std::vector< double > &matrix, std::vector< double > &eigenvectors, std::vector< double > &eigenvalues, const size_t dimension)
Definition: helper-implementation.h:122
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:306
Stores a singular value and corresponding left and right singular vectors.
Definition: helper.h:19
std::vector< value_type > v
right singular vector
Definition: helper.h:23
T value_type
Definition: helper.h:20
value_type value
Definition: helper.h:21
std::vector< value_type > u
left singular vector
Definition: helper.h:22
Definition: helper.h:12