1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_UTIL_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_UTIL_H
4#include <molpro/linalg/itsolv/ArrayHandlers.h>
5#include <molpro/linalg/itsolv/subspace/Matrix.h>
6#include <molpro/linalg/itsolv/wrap.h>
12template <
typename T1,
typename T2,
typename... Ts>
17template <
typename T1,
typename T2>
19 static constexpr bool value = std::is_same<T1, T2>::value;
23 bool = std::is_same<R, Z>::value,
bool = std::is_same<W, Q>::value>
26template <
class R,
class Q,
class Z,
class W>
27struct Overlap<R, Q, Z, W, true, true, true> {
34template <
class R,
class Q,
class Z,
class W>
35struct Overlap<R, Q, Z, W, true, false, false> {
45template <
class R,
class Q,
class Z,
class W>
50template <
class R,
class Q,
class Z,
class W>
52 -> std::enable_if_t<detail::Z_and_W_are_one_of_R_and_Q<R, Q, Z, W>,
62 for (
size_t i = 0; i < m.rows(); ++i)
63 for (
size_t j = 0; j <= i; ++j)
64 m(i, j) = m(j, i) = handler.
dot(params[i], params[j]);
70 assert(mat.
rows() == mat.
cols() &&
"must be a square matrix");
71 for (
size_t i = 0; i < mat.
rows(); ++i)
72 for (
size_t j = 0; j < i; ++j)
73 mat(i, j) = mat(j, i) = T(0.5) * (mat(i, j) + mat(j, i));
80 auto max_el = std::numeric_limits<T>::lowest();
84 if (mat(i, j) > max_el) {
106template <
typename Slice>
108 auto dim = mat.dimensions();
109 auto rows = std::list<size_t>{};
110 auto cols = std::list<size_t>{};
111 for (
size_t i = 0; i < dim.first; ++i) {
112 rows.emplace_back(i);
113 cols.emplace_back(i);
115 auto order = std::vector<size_t>(dim.first);
117 while (!rows.empty() && !cols.empty()) {
120 auto it_row = std::find(begin(rows), end(rows), i);
121 auto it_col = std::find(begin(cols), end(cols), j);
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition: ArrayHandler.h:162
virtual value_type dot(const AL &x, const AR &y)=0
decltype(value_type_L{} *value_type_R{}) value_type
Definition: ArrayHandler.h:181
virtual Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy)=0
std::pair< size_t, size_t > coord_type
Definition: Matrix.h:38
index_type rows() const
Definition: Matrix.h:167
index_type cols() const
Definition: Matrix.h:168
constexpr bool Z_and_W_are_one_of_R_and_Q
Definition: util.h:46
Definition: gram_schmidt.h:8
Matrix< T >::coord_type max_element_index(const std::list< size_t > &rows, const std::list< size_t > &cols, const Matrix< T > &mat)
Return maximum element in a matrix along specified rows and columns.
Definition: util.h:78
std::vector< size_t > eye_order(const Slice &mat)
Returns order of rows in a matrix slice that brings it closest to identity.
Definition: util.h:107
auto overlap(const CVecRef< R > &left, const CVecRef< Q > &right, array::ArrayHandler< Z, W > &handler) -> std::enable_if_t< detail::Z_and_W_are_one_of_R_and_Q< R, Q, Z, W >, Matrix< typename array::ArrayHandler< Z, W >::value_type > >
Calculates overlap matrix between left and right vectors.
Definition: util.h:51
void matrix_symmetrize(Matrix< T > &mat)
Definition: util.h:69
void transpose_copy(ML &&ml, const MR &mr)
Definition: Matrix.h:283
std::vector< std::reference_wrapper< const A > > CVecRef
Definition: wrap.h:14
typename array::ArrayHandler< Z, W >::value_type value_type
Definition: util.h:28
static Matrix< value_type > _(const CVecRef< R > &left, const CVecRef< Q > &right, array::ArrayHandler< Z, W > &handler)
Definition: util.h:29
typename array::ArrayHandler< Z, W >::value_type value_type
Definition: util.h:36
static Matrix< value_type > _(const CVecRef< R > &left, const CVecRef< Q > &right, array::ArrayHandler< Z, W > &handler)
Definition: util.h:37
Checks that type T1 is same as one of T2, Ts ...
Definition: util.h:13
static constexpr bool value
Definition: util.h:14