1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERSPARSE_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERSPARSE_H
3#include <molpro/linalg/array/ArrayHandler.h>
4#include <molpro/linalg/array/util/gemm.h>
5#include <molpro/linalg/array/util/select.h>
6#include <molpro/linalg/array/util/select_max_dot.h>
15template <
typename AL,
typename AR = AL>
24 AL
copy(
const AR &source)
override {
return AL{source.begin(), source.end()}; };
26 void copy(AL &x,
const AR &y)
override {
30 std::copy(
begin(y),
end(y), std::inserter(x, x.begin()));
44 for (
const auto &ix : x) {
45 auto iy = y.find(ix.first);
47 iy->second += alpha * ix.second;
54 for (
const auto &ix : x) {
55 const auto iy = y.find(ix.first);
64 gemm_outer_default(*
this, alphas, xx, yy);
68 return gemm_inner_default(*
this, xx, yy);
71 std::map<size_t, value_type_abs>
select_max_dot(
size_t n,
const AL &x,
const AR &y)
override {
72 if (n > x.size() || n > y.size())
73 error(
"ArrayHandlerSparse::select_max_dot() n is too large");
74 return util::select_max_dot_sparse<AL, AR, value_type, value_type_abs>(n, x, y);
77 std::map<size_t, value_type>
select(
size_t n,
const AL &x,
bool max =
false,
bool ignore_sign =
false)
override {
79 error(
"ArrayHandlerSparse::select() n is too large");
80 return util::select_sparse<AL, value_type>(n, x, max, ignore_sign);
Array handler between two sparse arrays (e.g. std::map)
Definition: ArrayHandlerSparse.h:16
value_type dot(const AL &x, const AR &y) override
The hermitian inner product <x|y>, i.e. conjugate-linear in x and linear in y.
Definition: ArrayHandlerSparse.h:52
std::map< size_t, value_type > 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: ArrayHandlerSparse.h:77
void scal(value_type alpha, AL &x) override
Definition: ArrayHandlerSparse.h:33
void fill(value_type alpha, AL &x) override
Definition: ArrayHandlerSparse.h:38
void copy(AL &x, const AR &y) override
Definition: ArrayHandlerSparse.h:26
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition: ArrayHandlerSparse.h:63
void axpy(value_type alpha, const AR &x, AL &y) override
Definition: ArrayHandlerSparse.h:43
std::map< size_t, value_type_abs > select_max_dot(size_t n, const AL &x, const AR &y) override
Definition: ArrayHandlerSparse.h:71
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition: ArrayHandlerSparse.h:83
AL copy(const AR &source) override
Definition: ArrayHandlerSparse.h:24
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition: ArrayHandlerSparse.h:67
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition: ArrayHandler.h:163
decltype(value_type_L{} *value_type_R{}) value_type
Definition: ArrayHandler.h:182
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
auto begin(Span< T > &x)
Definition: Span.h:87
auto end(Span< T > &x)
Definition: Span.h:97
void gemm_outer_default(Handler &handler, const Matrix< typename Handler::value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy)
Definition: gemm.h:261
Matrix< typename Handler::value_type > gemm_inner_default(Handler &handler, const CVecRef< AL > &xx, const CVecRef< AR > &yy)
Definition: gemm.h:271
Definition: ArrayHandler.h:19
T conjugate(const T &x)
Complex conjugate, staying within the scalar type; the identity for a real type.
Definition: scalar_traits.h:47