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>>();
68 for (
size_t i = 0; i < n; ++i, ++iy) {
69 if (iy->first < x.size())
70 selection.emplace(abs(x[iy->first] * iy->second), iy->first);
72 for (
auto jy = iy; jy !=
end(y); ++jy) {
73 if (jy->first < x.size()) {
74 selection.emplace(abs(x[jy->first] * jy->second), jy->first);
78 auto selection_map = std::map<size_t, value_type_abs>();
79 auto m = selection.size();
80 for (
size_t i = 0; i < m; ++i) {
81 selection_map.emplace(selection.top().second, selection.top().first);
99template <
class X,
class Y,
typename value_type,
typename value_type_abs>
105 using select_pair = std::pair<value_type_abs, size_t>;
106 auto selection = std::priority_queue<select_pair, std::vector<select_pair>, greater<select_pair>>();
109 while (selection.size() < n && ix !=
end(x)) {
110 iy = y.find(ix->first);
112 selection.emplace(abs(ix->second * iy->second), ix->first);
115 while (ix !=
end(x)) {
116 iy = y.find(ix->first);
118 selection.emplace(abs(ix->second * iy->second), ix->first);
123 auto selection_map = std::map<size_t, value_type_abs>();
124 auto m = selection.size();
125 for (
size_t i = 0; i < m; ++i) {
126 selection_map.emplace(selection.top().second, selection.top().first);
129 return selection_map;
auto begin(Span< T > &x)
Definition: Span.h:84
auto end(Span< T > &x)
Definition: Span.h:94
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:100