iterative-solver 0.0
 
Loading...
Searching...
No Matches
ArrayHandlerIterableDDisk.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERITERABLEDDISK_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERITERABLEDDISK_H
3#include <algorithm>
4#include <iterator>
5#include <molpro/linalg/array/ArrayHandler.h>
6#include <molpro/linalg/array/Span.h>
7#include <molpro/linalg/array/util.h>
8#include <molpro/linalg/array/util/gemm.h>
9#include <molpro/linalg/array/util/select.h>
10#include <molpro/linalg/scalar_traits.h>
11
12namespace molpro::linalg::array {
13
26template <class AL, class AR>
28public:
34 static_assert(is_contiguous_v<AL>, "ArrayHandlerIterableDDisk: the left array must be contiguous");
35 static_assert(std::is_same_v<value_type, typename AR::value_type>,
36 "ArrayHandlerIterableDDisk: the arrays must have the same value type");
37
38 ProxyHandle lazy_handle() override { return this->lazy_handle(*this); };
39
40 using ArrayHandler<AL, AR>::lazy_handle;
41 using ArrayHandler<AL, AR>::error;
42
43 AL copy(const AR &source) override {
44 auto result = util::allocate_like<AL>(source.size());
45 copy(result, source);
46 return result;
47 };
48
49 void copy(AL &x, const AR &y) override {
50 this->m_counter->copy++;
51 y.copy_to(util::contiguous_span(x));
52 };
53
54 void scal(value_type alpha, AL &x) override {
55 this->m_counter->scal++;
56 for (auto &el : x)
57 el *= alpha;
58 }
59
60 void fill(value_type alpha, AL &x) override { std::fill(std::begin(x), std::end(x), alpha); }
61
62 void axpy(value_type alpha, const AR &x, AL &y) override {
63 this->m_counter->axpy++;
64 x.axpy_to(alpha, util::contiguous_span(y));
65 }
66
68 value_type dot(const AL &x, const AR &y) override {
69 this->m_counter->dot++;
71 }
72
73 void gemm_outer(const Matrix<value_type> alphas, const CVecRef<AR> &xx, const VecRef<AL> &yy) override {
74 this->m_counter->gemm_outer++;
76 }
77
78 Matrix<value_type> gemm_inner(const CVecRef<AL> &xx, const CVecRef<AR> &yy) override {
79 this->m_counter->gemm_inner++;
81 }
82
83 std::map<size_t, value_type_abs> select_max_dot(size_t n, const AL &x, const AR &y) override {
84 return y.select_max_dot(n, util::contiguous_span(x));
85 }
86
87 std::map<size_t, value_type> select(size_t n, const AL &x, bool max = false, bool ignore_sign = false) override {
88 if (n > std::size(x))
89 error("ArrayHandlerIterableDDisk::select() n is too large");
90 return util::select<AL, value_type>(n, x, max, ignore_sign);
91 }
92};
93
94} // namespace molpro::linalg::array
95
96#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERITERABLEDDISK_H
Array handler between a contiguous array (left), e.g. std::vector or Span, and a distributed array (r...
Definition ArrayHandlerIterableDDisk.h:27
void scal(value_type alpha, AL &x) override
Definition ArrayHandlerIterableDDisk.h:54
void axpy(value_type alpha, const AR &x, AL &y) override
Definition ArrayHandlerIterableDDisk.h:62
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition ArrayHandlerIterableDDisk.h:38
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition ArrayHandlerIterableDDisk.h:73
std::map< size_t, value_type_abs > select_max_dot(size_t n, const AL &x, const AR &y) override
Select n indices with largest by absolute value contributions to the dot product.
Definition ArrayHandlerIterableDDisk.h:83
std::map< size_t, value_type > select(size_t n, const AL &x, bool max=false, bool ignore_sign=false) override
Select n indices with largest (or smallest) actual (or absolute) value.
Definition ArrayHandlerIterableDDisk.h:87
AL copy(const AR &source) override
Definition ArrayHandlerIterableDDisk.h:43
void fill(value_type alpha, AL &x) override
Definition ArrayHandlerIterableDDisk.h:60
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition ArrayHandlerIterableDDisk.h:78
void copy(AL &x, const AR &y) override
Copy content of y into x.
Definition ArrayHandlerIterableDDisk.h:49
value_type dot(const AL &x, const AR &y) override
The hermitian inner product <x|y>, i.e. the conjugate of <y|x>
Definition ArrayHandlerIterableDDisk.h:68
A convenience wrapper around a pointer to the LazyHandle.
Definition ArrayHandler.h:392
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition ArrayHandler.h:163
std::unique_ptr< Counter > m_counter
Definition ArrayHandler.h:177
typename array::mapped_or_value_type_t< AR > value_type_R
Definition ArrayHandler.h:181
typename array::mapped_or_value_type_t< AL > value_type_L
Definition ArrayHandler.h:180
decltype(value_type_L{} *value_type_R{}) value_type
Definition ArrayHandler.h:182
decltype(check_abs< value_type >()) value_type_abs
Definition ArrayHandler.h:183
virtual void error(const std::string &message)
Throws an error.
Definition ArrayHandler.h:276
Matrix container that allows simple data access, slicing, copying and resizing without loosing data.
Definition Matrix.h:32
Matrix< typename AD::value_type > gemm_inner_contiguous_distr(const CVecRef< R > &rr, const CVecRef< AD > &qq)
The overlap matrix (rr.size(), qq.size()) between contiguous arrays rr and distributed arrays qq....
Definition gemm.h:370
auto contiguous_span(R &r)
A view of all the elements of a contiguous array.
Definition util.h:93
void gemm_outer_distr_contiguous(const Matrix< typename AD::value_type > &alphas, const CVecRef< AD > &qq, const VecRef< R > &rr)
rr += alphas^T qq for contiguous arrays rr and distributed arrays qq. Collective.
Definition gemm.h:389
Definition ArrayHandler.h:19
T conjugate(const T &x)
Complex conjugate, staying within the scalar type; the identity for a real type.
Definition scalar_traits.h:47