1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_SELECT_MAX_DOT_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_SELECT_MAX_DOT_H
21template <
class X,
class Y,
typename value_type,
typename value_type_abs>
27 using select_pair = std::pair<value_type_abs, size_t>;
28 auto selection = std::priority_queue<select_pair, std::vector<select_pair>, greater<select_pair>>();
31 for (
size_t i = 0; i < n; ++i, ++ix, ++iy) {
32 selection.emplace(abs((*ix) * (*iy)), i);
34 for (
size_t i = n; i < std::min(x.size(), y.size()); ++i, ++ix, ++iy) {
35 selection.emplace(abs((*ix) * (*iy)), i);
38 auto selection_map = std::map<size_t, value_type_abs>();
39 auto m = selection.size();
40 for (
size_t i = 0; i < m; ++i) {
41 selection_map.emplace(selection.top().second, selection.top().first);
59template <
class X,
class Y,
typename value_type,
typename value_type_abs>
65 using select_pair = std::pair<value_type_abs, size_t>;
66 auto selection = std::priority_queue<select_pair, std::vector<select_pair>, greater<select_pair>>();
67 for (
auto iy =
begin(y); iy !=
end(y); ++iy) {
68 if (iy->first >= x.size())
70 selection.emplace(abs(x[iy->first] * iy->second), iy->first);
71 if (selection.size() > n)
74 auto selection_map = std::map<size_t, value_type_abs>();
75 auto m = selection.size();
76 for (
size_t i = 0; i < m; ++i) {
77 selection_map.emplace(selection.top().second, selection.top().first);
95template <
class X,
class Y,
typename value_type,
typename value_type_abs>
101 using select_pair = std::pair<value_type_abs, size_t>;
102 auto selection = std::priority_queue<select_pair, std::vector<select_pair>, greater<select_pair>>();
103 for (
auto ix =
begin(x); ix !=
end(x); ++ix) {
104 auto iy = y.find(ix->first);
107 selection.emplace(abs(ix->second * iy->second), ix->first);
108 if (selection.size() > n)
111 auto selection_map = std::map<size_t, value_type_abs>();
112 auto m = selection.size();
113 for (
size_t i = 0; i < m; ++i) {
114 selection_map.emplace(selection.top().second, selection.top().first);
117 return selection_map;
auto begin(Span< T > &x)
Definition: Span.h:87
auto end(Span< T > &x)
Definition: Span.h:97
Definition: ArrayHandler.h:23
auto select_max_dot(size_t n, const X &x, const Y &y)
Select n indices with largest by absolute value contributions to the dot product.
Definition: select_max_dot.h:22
auto select_max_dot_iter_sparse(size_t n, const X &x, const Y &y)
Select n indices with largest by absolute value contributions to the dot product.
Definition: select_max_dot.h:60
auto select_max_dot_sparse(size_t n, const X &x, const Y &y)
Select n indices with largest by absolute value contributions to the dot product.
Definition: select_max_dot.h:96