forked from benfred/implicit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopnc.cpp
More file actions
30 lines (26 loc) · 780 Bytes
/
topnc.cpp
File metadata and controls
30 lines (26 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <vector>
#include <limits>
#include <algorithm>
#include <iostream>
#include "topnc.h"
namespace {
struct target {
int index;
float value;
};
bool targets_compare(target t_i, target t_j) { return (t_i.value > t_j.value); }
}
void fargsort_c(float A[], int n_row, int m_row, int m_cols, int ktop, int B[]) {
std::vector<target> targets;
for ( int j = 0; j < m_cols; j++ ) {
target c;
c.index = j;
c.value = A[(n_row*m_cols) + j];
targets.push_back(c);
}
std::partial_sort(targets.begin(), targets.begin() + ktop, targets.end(), targets_compare);
std::sort(targets.begin(), targets.begin() + ktop, targets_compare);
for (int j = 0; j < ktop; j++) {
B[(m_row*ktop) + j] = targets[j].index;
}
}