1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDISTRSPARSE_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDISTRSPARSE_H
3#include "molpro/linalg/array/ArrayHandler.h"
4#include <molpro/linalg/array/util/gemm.h>
11template <
typename AL,
typename AR,
bool = has_mapped_type_v<AR>>
17template <
typename AL,
typename AR>
26 AL
copy(
const AR &source)
override {
27 throw std::logic_error(
"General construction of sparse from dense is ill-defined");
30 void copy(AL &x,
const AR &y)
override {
33 auto lb = x.local_buffer();
34 auto start = lb->start();
35 for (
const auto &v : y)
36 if (v.first >= start and v.first < start + lb->size())
37 (*lb)[v.first - start] = v.second;
40 void scal(
value_type alpha, AL &x)
override {
static_assert(
true,
"Use ArrayHandlerDistr for unary operations"); };
42 void fill(
value_type alpha, AL &x)
override {
static_assert(
true,
"Use ArrayHandlerDistr for unary operations"); };
57 gemm_outer_distr_sparse(alphas, xx, yy);
62 return gemm_inner_distr_sparse(xx, yy);
65 std::map<size_t, value_type_abs>
select_max_dot(
size_t n,
const AL &x,
const AR &y)
override {
66 return x.select_max_dot(n, y);
69 std::map<size_t, value_type_abs>
select(
size_t n,
const AL &x,
bool max =
false,
bool ignore_sign =
false)
override {
70 return x.select(n, max, ignore_sign);
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition: ArrayHandlerDistrSparse.h:73
void fill(value_type alpha, AL &x) override
Definition: ArrayHandlerDistrSparse.h:42
void scal(value_type alpha, AL &x) override
Definition: ArrayHandlerDistrSparse.h:40
void copy(AL &x, const AR &y) override
Copy content of y into x.
Definition: ArrayHandlerDistrSparse.h:30
value_type dot(const AL &x, const AR &y) override
Definition: ArrayHandlerDistrSparse.h:50
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition: ArrayHandlerDistrSparse.h:55
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: ArrayHandlerDistrSparse.h:65
void axpy(value_type alpha, const AR &x, AL &y) override
Definition: ArrayHandlerDistrSparse.h:45
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition: ArrayHandlerDistrSparse.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: ArrayHandlerDistrSparse.h:69
AL copy(const AR &source) override
Definition: ArrayHandlerDistrSparse.h:26
Definition: ArrayHandlerDistrSparse.h:12
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
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