iterative-solver 0.0
 
Loading...
Searching...
No Matches
ArrayHandlerDDiskDistr.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKDISTR_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKDISTR_H
3
4#include <map>
5#include <molpro/linalg/array/ArrayHandlerWithCopyFunc.h>
6#include <molpro/linalg/array/util/gemm.h>
7#include <string>
8
9namespace molpro::linalg::array {
12
13template <class AL, class AR = AL>
15public:
21
24 : ArrayHandlerWithCopyFunc<AL, AR>([](const AR &source) { return AL::CreateTempCopy(source); }) {}
25
27 explicit ArrayHandlerDDiskDistr(const std::string &directory)
29 [directory](const AR &source) { return AL::CreateTempCopy(source, directory); }) {}
30
32 ArrayHandlerDDiskDistr(std::function<AL(const AR &)> copy_func)
33 : ArrayHandlerWithCopyFunc<AL, AR>(std::move(copy_func)) {}
34
35 ProxyHandle lazy_handle() override { return this->lazy_handle(*this); };
36
37 using ArrayHandler<AL, AR>::lazy_handle;
38 using ArrayHandler<AL, AR>::error;
39
41
42 void copy(AL &x, const AR &y) override {
43 this->m_counter->copy++;
44 x.copy(y);
45 };
46
47 void scal(value_type alpha, AL &x) override {
48 this->m_counter->scal++;
49 x.scal(alpha);
50 }
51
52 void fill(value_type alpha, AL &x) override { x.fill(alpha); }
53
54 void axpy(value_type alpha, const AR &x, AL &y) override {
55 this->m_counter->axpy++;
56 y.axpy(alpha, x);
57 }
58
59 value_type dot(const AL &x, const AR &y) override {
60 this->m_counter->dot++;
61 return x.dot(y);
62 }
63
64 void gemm_outer(const Matrix<value_type> alphas, const CVecRef<AR> &xx, const VecRef<AL> &yy) override {
65 this->m_counter->gemm_outer++;
66 gemm_outer_distr_distr(alphas, xx, yy);
67 }
68
69 Matrix<value_type> gemm_inner(const CVecRef<AL> &xx, const CVecRef<AR> &yy) override {
70 auto prof = molpro::Profiler::single()->push("ArrayHandlerDDiskDistr::gemm_inner");
71 this->m_counter->gemm_inner++;
72 return gemm_inner_distr_distr(xx, yy);
73 }
74
75 std::map<size_t, value_type_abs> select_max_dot(size_t n, const AL &x, const AR &y) override {
76 return x.select_max_dot(n, y);
77 }
78
79 std::map<size_t, value_type_abs> select(size_t n, const AL &x, bool max = false, bool ignore_sign = false) override {
80 return x.select(n, max, ignore_sign);
81 }
82};
83
84} // namespace molpro::linalg::array
85
86#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKDISTR_H
Definition ArrayHandlerDDiskDistr.h:14
ArrayHandlerDDiskDistr()
New arrays are created by AL::CreateTempCopy(), with any file next to that of the source,...
Definition ArrayHandlerDDiskDistr.h:23
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition ArrayHandlerDDiskDistr.h:69
void axpy(value_type alpha, const AR &x, AL &y) override
Definition ArrayHandlerDDiskDistr.h:54
void scal(value_type alpha, AL &x) override
Definition ArrayHandlerDDiskDistr.h:47
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition ArrayHandlerDDiskDistr.h:64
void copy(AL &x, const AR &y) override
Copy content of y into x.
Definition ArrayHandlerDDiskDistr.h:42
std::map< size_t, value_type_abs > 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 ArrayHandlerDDiskDistr.h:79
void fill(value_type alpha, AL &x) override
Definition ArrayHandlerDDiskDistr.h:52
ArrayHandlerDDiskDistr(const std::string &directory)
New arrays are created by AL::CreateTempCopy(), with any file in directory.
Definition ArrayHandlerDDiskDistr.h:27
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 ArrayHandlerDDiskDistr.h:75
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition ArrayHandlerDDiskDistr.h:35
value_type dot(const AL &x, const AR &y) override
The hermitian inner product <x|y>: conjugate-linear in x, linear in y.
Definition ArrayHandlerDDiskDistr.h:59
ArrayHandlerDDiskDistr(std::function< AL(const AR &)> copy_func)
Constructor taking a copy function, which can e.g. specify the file underlying the new array.
Definition ArrayHandlerDDiskDistr.h:32
Base for handlers whose left arrays are created by a function given by the user.
Definition ArrayHandlerWithCopyFunc.h:16
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
static std::shared_ptr< Profiler > single()
Matrix< typename array::mapped_or_value_type_t< AL > > gemm_inner_distr_distr(const CVecRef< AL > &yy, const CVecRef< AD > &xx)
Definition gemm.h:338
void gemm_outer_distr_distr(const Matrix< typename array::mapped_or_value_type_t< AL > > alphas, const CVecRef< AD > &xx, const VecRef< AL > &yy)
Definition gemm.h:353
Definition ArrayHandler.h:19