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>
30 std::vector<value_type>
u;
31 std::vector<value_type>
v;
42 std::span<double> eigenvalues,
const size_t dimension);
47template <
typename value_type>
48size_t get_rank(std::span<const value_type> eigenvalues, value_type threshold);
50template <
typename value_type>
54template <
typename value_type>
55size_t get_rank(
const std::vector<value_type>& eigenvalues, value_type threshold) {
56 return get_rank<value_type>(std::span<const value_type>{eigenvalues.data(), eigenvalues.size()}, threshold);
68template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
71 bool reduce_to_rank =
false);
72template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
75 bool reduce_to_rank =
false);
77template <
typename value_type>
78void printMatrix(
const std::vector<value_type>&,
size_t rows,
size_t cols, std::string title =
"",
79 std::ostream& s = molpro::cout);
81template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
82void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
83 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
size_t dimension,
85 std::vector<std::pair<std::size_t, value_type>>* imag_eval_parts =
nullptr);
87template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
88void eigenproblem(std::vector<value_type>& eigenvectors, std::vector<value_type>& eigenvalues,
89 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
size_t dimension,
91 std::vector<std::pair<std::size_t, value_type>> *imag_eval_parts =
nullptr);
93template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
95 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
96 const std::vector<value_type>& rhs,
size_t dimension,
size_t nroot,
100template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
102 const std::vector<value_type>& matrix,
const std::vector<value_type>& metric,
103 const std::vector<value_type>& rhs,
size_t dimension,
size_t nroot,
107template <
typename value_type,
typename std::enable_if_t<is_complex<value_type>{},
int> = 0>
108void solve_DIIS(std::vector<value_type>& solution,
const std::vector<value_type>& matrix,
size_t dimension,
110template <
typename value_type,
typename std::enable_if_t<!is_complex<value_type>{}, std::
nullptr_t> =
nullptr>
111void solve_DIIS(std::vector<value_type>& solution,
const std::vector<value_type>& matrix,
size_t dimension,
118extern template void printMatrix<double>(
const std::vector<double>&,
size_t rows,
size_t cols, std::string title,
121extern template size_t get_rank<double>(std::span<const double> eigenvalues,
double threshold);
124 double threshold,
bool hermitian,
bool reduce_to_rank);
127 const std::vector<double>& matrix,
const std::vector<double>& metric,
128 const size_t dimension,
bool hermitian,
double svdThreshold,
int verbosity,
129 std::vector<std::pair<std::size_t, double>> *imag_eval_parts);
132 const std::vector<double>& matrix,
const std::vector<double>& metric,
133 const std::vector<double>& rhs,
size_t dimension,
size_t nroot,
134 double augmented_hessian,
double svdThreshold,
int verbosity);
136extern template void solve_DIIS<double>(std::vector<double>& solution,
const std::vector<double>& matrix,
137 const size_t dimension,
double svdThreshold,
int verbosity);
147 std::string title, std::ostream& s);
152 long double threshold,
bool hermitian,
bool reduce_to_rank);
155 std::vector<long double>& eigenvalues,
156 const std::vector<long double>& matrix,
157 const std::vector<long double>& metric,
const size_t dimension,
158 bool hermitian,
long double svdThreshold,
int verbosity,
159 std::vector<std::pair<std::size_t, long double>> *imag_eval_parts);
162 std::vector<long double>& solution, std::vector<long double>& eigenvalues,
const std::vector<long double>& matrix,
163 const std::vector<long double>& metric,
const std::vector<long double>& rhs,
size_t dimension,
size_t nroot,
164 long double augmented_hessian,
long double svdThreshold,
int verbosity);
167 const size_t dimension,
long double svdThreshold,
int verbosity);
172extern template void printMatrix<std::complex<double>>(
const std::vector<std::complex<double>>&,
size_t rows,
173 size_t cols, std::string title, std::ostream& s);
175extern template std::list<SVD<std::complex<double>>>
svd_system(
size_t nrows,
size_t ncols,
177 double threshold,
bool hermitian,
bool reduce_to_rank);
179extern template void eigenproblem<std::complex<double>>(
180 std::vector<std::complex<double>>& eigenvectors, std::vector<std::complex<double>>& eigenvalues,
181 const std::vector<std::complex<double>>& matrix,
const std::vector<std::complex<double>>& metric,
182 const size_t dimension,
bool hermitian,
double svdThreshold,
int verbosity,
183 std::vector<std::pair<std::size_t, std::complex<double>>>* imag_eval_parts);
185extern template void solve_LinearEquations<std::complex<double>>(
186 std::vector<std::complex<double>>& solution, std::vector<std::complex<double>>& eigenvalues,
187 const std::vector<std::complex<double>>& matrix,
const std::vector<std::complex<double>>& metric,
188 const std::vector<std::complex<double>>& rhs,
size_t dimension,
size_t nroot,
double augmented_hessian,
189 double svdThreshold,
int verbosity);
191extern template void solve_DIIS<std::complex<double>>(std::vector<std::complex<double>>& solution,
192 const std::vector<std::complex<double>>& matrix,
193 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)
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, std::vector< std::pair< std::size_t, value_type > > *imag_eval_parts=nullptr)
Definition: helper-implementation.h:377
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:727
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:813
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:262
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:274
template size_t get_rank< double >(std::span< const double > eigenvalues, double threshold)
real_type_t< T > real_part(const T &x)
The real part of a scalar; the value itself for a real type.
Definition: scalar_traits.h:58
T conjugate(const T &x)
Complex conjugate, staying within the scalar type; the identity for a real type.
Definition: scalar_traits.h:47
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< T > imaginary_part(const T &x)
The imaginary part of a scalar; zero for a real type.
Definition: scalar_traits.h:68
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:85
Definition: scalar_traits.h:19
Stores a singular value and corresponding left and right singular vectors.
Definition: helper.h:27
std::vector< value_type > v
right singular vector
Definition: helper.h:31
T value_type
Definition: helper.h:28
value_type value
Definition: helper.h:29
std::vector< value_type > u
left singular vector
Definition: helper.h:30
The real type underlying a (possibly complex) scalar type.
Definition: scalar_traits.h:26