iterative-solver 0.0
ArrayHandlerDDiskSparse.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKSPARSE_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKSPARSE_H
3#include <map>
4#include <molpro/Profiler.h>
5#include <molpro/linalg/array/ArrayHandler.h>
6#include <molpro/linalg/array/util/gemm.h>
7#include <stdexcept>
8
9namespace molpro::linalg::array {
12template <typename AL, typename AR, bool = has_mapped_type_v<AR>>
13class ArrayHandlerDDiskSparse : public ArrayHandler<AL, AR> {};
14
18template <typename AL, typename AR>
19class ArrayHandlerDDiskSparse<AL, AR, true> : public ArrayHandler<AL, AR> {
20public:
26
27 AL copy(const AR &source) override { throw std::logic_error("General copy from sparse to dense is ill-defined"); };
28 void copy(AL &x, const AR &y) override { static_assert(true, "General copy from sparse to dense is ill-defined"); };
29
30 void scal(value_type alpha, AL &x) override { static_assert(true, "Use ArrayHandlerDistr for unary operations"); };
31
32 void fill(value_type alpha, AL &x) override { static_assert(true, "Use ArrayHandlerDistr for unary operations"); };
33
34 void axpy(value_type alpha, const AR &x, AL &y) override {
35 this->m_counter->axpy++;
36 y.axpy(alpha, x);
37 };
38
39 value_type dot(const AL &x, const AR &y) override {
40 this->m_counter->dot++;
41 return x.dot(y);
42 };
43
44 void gemm_outer(const Matrix<value_type> alphas, const CVecRef<AR> &xx, const VecRef<AL> &yy) override {
45 this->m_counter->gemm_outer++;
46 gemm_outer_distr_sparse(alphas, xx, yy);
47 }
48
49 Matrix<value_type> gemm_inner(const CVecRef<AL> &xx, const CVecRef<AR> &yy) override {
50 auto prof = molpro::Profiler::single()->push("ArrayHandlerDDiskSparse::gemm_inner");
51 this->m_counter->gemm_inner++;
52 return gemm_inner_distr_sparse(xx, yy);
53 }
54
55 std::map<size_t, value_type_abs> select_max_dot(size_t n, const AL &x, const AR &y) override {
56 return x.select_max_dot(n, y);
57 }
58
59 std::map<size_t, value_type_abs> select(size_t n, const AL &x, bool max = false, bool ignore_sign = false) override {
60 return x.select(n, max, ignore_sign);
61 }
62
63 ProxyHandle lazy_handle() override { return this->lazy_handle(*this); };
64
65protected:
66 using ArrayHandler<AL, AR>::error;
67 using ArrayHandler<AL, AR>::lazy_handle;
68 using ArrayHandler<AL, AR>::m_lazy_handles;
69};
70
71} // namespace molpro::linalg::array
72
73#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKSPARSE_H
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: ArrayHandlerDDiskSparse.h:59
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition: ArrayHandlerDDiskSparse.h:63
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: ArrayHandlerDDiskSparse.h:55
void scal(value_type alpha, AL &x) override
Definition: ArrayHandlerDDiskSparse.h:30
void copy(AL &x, const AR &y) override
Copy content of y into x.
Definition: ArrayHandlerDDiskSparse.h:28
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition: ArrayHandlerDDiskSparse.h:44
AL copy(const AR &source) override
Definition: ArrayHandlerDDiskSparse.h:27
void fill(value_type alpha, AL &x) override
Definition: ArrayHandlerDDiskSparse.h:32
value_type dot(const AL &x, const AR &y) override
Definition: ArrayHandlerDDiskSparse.h:39
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition: ArrayHandlerDDiskSparse.h:49
void axpy(value_type alpha, const AR &x, AL &y) override
Definition: ArrayHandlerDDiskSparse.h:34
Definition: ArrayHandlerDDiskSparse.h:13
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition: ArrayHandler.h:162
std::unique_ptr< Counter > m_counter
Definition: ArrayHandler.h:176
std::vector< std::weak_ptr< LazyHandle > > m_lazy_handles
keeps track of all created lazy handles
Definition: ArrayHandler.h:416
decltype(value_type_L{} *value_type_R{}) value_type
Definition: ArrayHandler.h:181
virtual ProxyHandle lazy_handle()=0
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
virtual void error(const std::string &message)
Throws an error.
Definition: ArrayHandler.h:268
Matrix container that allows simple data access, slicing, copying and resizing without loosing data.
Definition: Matrix.h:30
static std::shared_ptr< Profiler > single()
Matrix< typename array::mapped_or_value_type_t< AL > > gemm_inner_distr_sparse(const CVecRef< AL > &xx, const CVecRef< AR > &yy)
Definition: gemm.h:227
void gemm_outer_distr_sparse(const Matrix< typename array::mapped_or_value_type_t< AL > > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy)
Definition: gemm.h:208
Definition: ArrayHandler.h:18