1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITERATIVESOLVER_HELPER_H_
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITERATIVESOLVER_HELPER_H_
7#include <molpro/iostream.h>
8#include <molpro/linalg/array/Span.h>
9#include <molpro/linalg/scalar_traits.h>
27 std::vector<value_type>
u;
28 std::vector<value_type>
v;
39 std::span<double> eigenvalues,
const size_t dimension);
44template <
typename value_type>
45size_t get_rank(std::span<const value_type> eigenvalues, value_type threshold);
47template <
typename value_type>
51template <
typename value_type>
52size_t get_rank(
const std::vector<value_type>& eigenvalues, value_type threshold) {
53 return get_rank<value_type>(std::span<const value_type>{eigenvalues.data(), eigenvalues.size()}, threshold);
65template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
68 bool reduce_to_rank =
false);
69template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
72 bool reduce_to_rank =
false);
74template <
typename value_type>
75void printMatrix(
const std::vector<value_type>&,
size_t rows,
size_t cols, std::string title =
"",
76 std::ostream& s = molpro::cout);
78template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
79void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
80 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
size_t dimension,
83template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
84void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
85 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
size_t dimension,
87 std::vector<std::pair<std::size_t, value_type>> *imag_eval_parts =
nullptr);
89template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
91 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
92 const std::vector<value_type>& rhs,
size_t dimension,
size_t nroot,
96template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
98 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
99 const std::vector<value_type>& rhs,
size_t dimension,
size_t nroot,
103template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
104void solve_DIIS(std::vector<value_type>& solution,
const std::vector<value_type>& matrix,
size_t dimension,
106template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
107void solve_DIIS(std::vector<value_type>& solution,
const std::vector<value_type>& matrix,
size_t dimension,
114extern template void printMatrix<double>(
const std::vector<double>&,
size_t rows,
size_t cols, std::string title,
117extern template size_t get_rank<double>(std::span<const double> eigenvalues,
double threshold);
120 double threshold,
bool hermitian,
bool reduce_to_rank);
123 const std::vector<double>& matrix,
const std::vector<double>& metric,
124 const size_t dimension,
bool hermitian,
double svdThreshold,
int verbosity,
125 std::vector<std::pair<std::size_t, double>> *imag_eval_parts);
128 const std::vector<double>& matrix,
const std::vector<double>& metric,
129 const std::vector<double>& rhs,
size_t dimension,
size_t nroot,
130 double augmented_hessian,
double svdThreshold,
int verbosity);
132extern template void solve_DIIS<double>(std::vector<double>& solution,
const std::vector<double>& matrix,
133 const size_t dimension,
double svdThreshold,
int verbosity);
142 std::string title, std::ostream& s);
147 long double threshold,
bool hermitian,
bool reduce_to_rank);
150 std::vector<long double>& eigenvalues,
151 const std::vector<long double>& matrix,
152 const std::vector<long double>& metric,
const size_t dimension,
153 bool hermitian,
long double svdThreshold,
int verbosity,
154 std::vector<std::pair<std::size_t, long double>> *imag_eval_parts);
157 std::vector<long double>& solution, std::vector<long double>& eigenvalues,
const std::vector<long double>& matrix,
158 const std::vector<long double>& metric,
const std::vector<long double>& rhs,
size_t dimension,
size_t nroot,
159 long double augmented_hessian,
long double svdThreshold,
int verbosity);
162 const size_t dimension,
long double svdThreshold,
int verbosity);
167extern template void printMatrix<std::complex<double>>(
const std::vector<std::complex<double>>&,
size_t rows,
168 size_t cols, std::string title, std::ostream& s);
170extern template std::list<SVD<std::complex<double>>>
svd_system(
size_t nrows,
size_t ncols,
172 double threshold,
bool hermitian,
bool reduce_to_rank);
174extern template void eigenproblem<std::complex<double>>(std::vector<std::complex<double>>& eigenvectors,
175 std::vector<std::complex<double>>& eigenvalues,
176 const std::vector<std::complex<double>>& matrix,
177 const std::vector<std::complex<double>>& metric,
178 const size_t dimension,
bool hermitian,
double svdThreshold,
181extern template void solve_LinearEquations<std::complex<double>>(
182 std::vector<std::complex<double>>& solution, std::vector<std::complex<double>>& eigenvalues,
183 const std::vector<std::complex<double>>& matrix,
const std::vector<std::complex<double>>& metric,
184 const std::vector<std::complex<double>>& rhs,
size_t dimension,
size_t nroot,
double augmented_hessian,
185 double svdThreshold,
int verbosity);
187extern template void solve_DIIS<std::complex<double>>(std::vector<std::complex<double>>& solution,
188 const std::vector<std::complex<double>>& matrix,
189 const size_t dimension,
double svdThreshold,
int verbosity);
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:14
template void eigenproblem< long double >(std::vector< long double > &eigenvectors, std::vector< long double > &eigenvalues, const std::vector< long double > &matrix, const std::vector< long double > &metric, const size_t dimension, bool hermitian, long double svdThreshold, int verbosity, std::vector< std::pair< std::size_t, long double > > *imag_eval_parts)
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, std::vector< std::pair< std::size_t, double > > *imag_eval_parts)
template void printMatrix< double >(const std::vector< double > &, size_t rows, size_t cols, std::string title, std::ostream &s)
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, real_type_t< value_type > augmented_hessian, real_type_t< value_type > svdThreshold, int verbosity)
Definition: helper-implementation.h:477
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, real_type_t< value_type > svdThreshold, int verbosity)
Definition: helper-implementation.h:260
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)
Eigen-decomposition of a real symmetric matrix in double precision.
Definition: helper-implementation.h:153
template size_t get_rank< value_type >(std::span< const value_type > eigenvalues, value_type threshold)
void solve_DIIS(std::vector< value_type > &solution, const std::vector< value_type > &matrix, size_t dimension, real_type_t< value_type > svdThreshold, int verbosity=0)
Definition: helper-implementation.h:554
template size_t get_rank< long double >(std::span< const long double > eigenvalues, long double 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)
template void printMatrix< long double >(const std::vector< long double > &, size_t rows, size_t cols, std::string title, std::ostream &s)
std::list< SVD< value_type > > svd_system(size_t nrows, size_t ncols, const array::Span< value_type > &m, real_type_t< value_type > 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:213
template void solve_DIIS< long double >(std::vector< long double > &solution, const std::vector< long double > &matrix, const size_t dimension, long double svdThreshold, int verbosity)
template void solve_LinearEquations< long double >(std::vector< long double > &solution, std::vector< long double > &eigenvalues, const std::vector< long double > &matrix, const std::vector< long double > &metric, const std::vector< long double > &rhs, size_t dimension, size_t nroot, long double augmented_hessian, long double svdThreshold, int verbosity)
size_t get_rank(std::span< const value_type > eigenvalues, value_type threshold)
Definition: helper-implementation.h:171
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:254
template size_t get_rank< double >(std::span< const double > eigenvalues, double threshold)
typename real_type< T >::type real_type_t
The real type underlying T, i.e. T itself for a real type and U for std::complex<U>.
Definition: scalar_traits.h:43
real_type_t< value_type > precision_scaled(double tolerance_for_double)
Rescale a tolerance that was calibrated for IEEE double precision to the working precision.
Definition: scalar_traits.h:54
Definition: scalar_traits.h:19
Stores a singular value and corresponding left and right singular vectors.
Definition: helper.h:24
std::vector< value_type > v
right singular vector
Definition: helper.h:28
T value_type
Definition: helper.h:25
value_type value
Definition: helper.h:26
std::vector< value_type > u
left singular vector
Definition: helper.h:27
The real type underlying a (possibly complex) scalar type.
Definition: scalar_traits.h:26