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
11
12namespace molpro::linalg::array {
13template <typename AL, typename AR, bool = has_mapped_type_v<AR>>
14class ArrayHandlerDDiskSparse : public ArrayHandler<AL, AR> {};
15
19template <typename AL, typename AR>
20class ArrayHandlerDDiskSparse<AL, AR, true> : public ArrayHandler<AL, AR> {
21public:
27
28 AL copy(const AR &source) override { throw std::logic_error("General copy from sparse to dense is ill-defined"); };
29 void copy(AL &x, const AR &y) override { static_assert(true, "General copy from sparse to dense is ill-defined"); };
30
31 void scal(value_type alpha, AL &x) override { static_assert(true, "Use ArrayHandlerDistr for unary operations"); };
32
33 void fill(value_type alpha, AL &x) override { static_assert(true, "Use ArrayHandlerDistr for unary operations"); };
34
35 void axpy(value_type alpha, const AR &x, AL &y) override {
36 this->m_counter->axpy++;
37 y.axpy(alpha, x);
38 };
39
40 value_type dot(const AL &x, const AR &y) override {
41 this->m_counter->dot++;
42 return x.dot(y);
43 };
44
45 void gemm_outer(const Matrix<value_type> alphas, const CVecRef<AR> &xx, const VecRef<AL> &yy) override {
46 this->m_counter->gemm_outer++;
47 gemm_outer_distr_sparse(alphas, xx, yy);
48 }
49
50 Matrix<value_type> gemm_inner(const CVecRef<AL> &xx, const CVecRef<AR> &yy) override {
51 auto prof = molpro::Profiler::single()->push("ArrayHandlerDDiskSparse::gemm_inner");
52 this->m_counter->gemm_inner++;
53 return gemm_inner_distr_sparse(xx, yy);
54 }
55
56 std::map<size_t, value_type_abs> select_max_dot(size_t n, const AL &x, const AR &y) override {
57 return x.select_max_dot(n, y);
58 }
59
60 std::map<size_t, value_type_abs> select(size_t n, const AL &x, bool max = false, bool ignore_sign = false) override {
61 return x.select(n, max, ignore_sign);
62 }
63
64 ProxyHandle lazy_handle() override { return this->lazy_handle(*this); };
65
66protected:
67 using ArrayHandler<AL, AR>::error;
68 using ArrayHandler<AL, AR>::lazy_handle;
69 using ArrayHandler<AL, AR>::m_lazy_handles;
70};
71
72} // namespace molpro::linalg::array
73
74#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:60
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition: ArrayHandlerDDiskSparse.h:64
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:56
void scal(value_type alpha, AL &x) override
Definition: ArrayHandlerDDiskSparse.h:31
void copy(AL &x, const AR &y) override
Copy content of y into x.
Definition: ArrayHandlerDDiskSparse.h:29
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition: ArrayHandlerDDiskSparse.h:45
AL copy(const AR &source) override
Definition: ArrayHandlerDDiskSparse.h:28
void fill(value_type alpha, AL &x) override
Definition: ArrayHandlerDDiskSparse.h:33
value_type dot(const AL &x, const AR &y) override
Definition: ArrayHandlerDDiskSparse.h:40
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition: ArrayHandlerDDiskSparse.h:50
void axpy(value_type alpha, const AR &x, AL &y) override
Definition: ArrayHandlerDDiskSparse.h:35
Definition: ArrayHandlerDDiskSparse.h:14
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:28
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:22