-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_compile.cpp
More file actions
62 lines (52 loc) · 1.76 KB
/
test_compile.cpp
File metadata and controls
62 lines (52 loc) · 1.76 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Rcpp.h>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <vector>
// Simple test version of the function to verify compilation
// [[Rcpp::export]]
Rcpp::List test_multi_column_group_cpp(const Rcpp::List& data) {
int n_rows = 0;
int n_cols = data.size();
if (n_cols == 0) {
return Rcpp::List::create(
Rcpp::Named("group_ids") = Rcpp::IntegerVector(),
Rcpp::Named("n_groups") = 0
);
}
// Get number of rows from first column
if (data[0] != R_NilValue) {
Rcpp::RObject first_col = data[0];
if (first_col.isObject()) {
n_rows = Rf_length(first_col);
}
}
if (n_rows == 0) {
return Rcpp::List::create(
Rcpp::Named("group_ids") = Rcpp::IntegerVector(),
Rcpp::Named("n_groups") = 0
);
}
// Process first column only (simplified test)
Rcpp::RObject column = data[0];
if (column != R_NilValue && TYPEOF(column) == STRSXP) {
Rcpp::CharacterVector char_col = Rcpp::as<Rcpp::CharacterVector>(column);
int col_size = static_cast<int>(char_col.size());
int max_rows = (n_rows < col_size) ? n_rows : col_size;
// Simple grouping - just return sequential IDs
std::vector<int> group_ids(n_rows);
for (int i = 0; i < max_rows; i++) {
group_ids[i] = i + 1;
}
return Rcpp::List::create(
Rcpp::Named("group_ids") = group_ids,
Rcpp::Named("n_groups") = max_rows
);
}
// Default case
std::vector<int> group_ids(n_rows, 1);
return Rcpp::List::create(
Rcpp::Named("group_ids") = group_ids,
Rcpp::Named("n_groups") = 1
);
}