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