Skip to content

Commit

Permalink
use R_len_t & R_xlen_t
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Dec 25, 2023
1 parent d65df88 commit 2f6298b
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion R/ContingencyTableTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ContingencyTableTest <- R6Class(
row_loc = rep.int(seq_len(r), row_sum) - 1,
col_loc = rep.int(seq_len(c), col_sum) - 1,
statistic_func = private$.statistic_func,
n_permu = as.integer(private$.n_permu)
n_permu = private$.n_permu
)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/KSampleTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ KSampleTest <- R6Class(
data = unname(private$.data),
group = as.integer(names(private$.data)),
statistic_func = private$.statistic_func,
n_permu = as.integer(private$.n_permu)
n_permu = private$.n_permu
)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/MultipleComparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MultipleComparison <- R6Class(
data = unname(private$.data),
group = as.integer(names(private$.data)),
statistic_func = private$.statistic_func,
n_permu = as.integer(private$.n_permu)
n_permu = private$.n_permu
)
},

Expand Down
2 changes: 1 addition & 1 deletion R/RCBD.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RCBD <- R6Class(
private$.statistic_permu <- rcbd_pmt(
data = apply(private$.data, 2, sort),
statistic_func = private$.statistic_func,
n_permu = as.integer(private$.n_permu)
n_permu = private$.n_permu
)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/TwoSampleAssociationTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TwoSampleAssociationTest <- R6Class(
x = data_y_order$x,
y = data_y_order$y,
statistic_func = private$.statistic_func,
n_permu = as.integer(private$.n_permu)
n_permu = private$.n_permu
)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/TwoSamplePairedTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TwoSamplePairedTest <- R6Class(
private$.statistic_permu <- paired_pmt(
n = nrow(private$.data),
statistic_func = private$.statistic_func,
n_permu = as.integer(private$.n_permu)
n_permu = private$.n_permu
)
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/TwoSampleTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TwoSampleTest <- R6Class(
data = c(private$.data$x, private$.data$y),
where_y = rep.int(c(FALSE, TRUE), c(n_1, n_2)),
statistic_func = private$.statistic_func,
n_permu = as.integer(private$.n_permu)
n_permu = private$.n_permu
)
}
)
Expand Down
30 changes: 15 additions & 15 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// association_pmt
NumericVector association_pmt(const NumericVector x, NumericVector y, const Function statistic_func, const unsigned n_permu);
NumericVector association_pmt(const NumericVector x, NumericVector y, const Function statistic_func, const R_xlen_t n_permu);
RcppExport SEXP _LearnNonparam_association_pmt(SEXP xSEXP, SEXP ySEXP, SEXP statistic_funcSEXP, SEXP n_permuSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const NumericVector >::type x(xSEXP);
Rcpp::traits::input_parameter< NumericVector >::type y(ySEXP);
Rcpp::traits::input_parameter< const Function >::type statistic_func(statistic_funcSEXP);
Rcpp::traits::input_parameter< const unsigned >::type n_permu(n_permuSEXP);
Rcpp::traits::input_parameter< const R_xlen_t >::type n_permu(n_permuSEXP);
rcpp_result_gen = Rcpp::wrap(association_pmt(x, y, statistic_func, n_permu));
return rcpp_result_gen;
END_RCPP
}
// ksample_pmt
NumericVector ksample_pmt(const NumericVector data, IntegerVector group, const Function statistic_func, const unsigned n_permu);
NumericVector ksample_pmt(const NumericVector data, IntegerVector group, const Function statistic_func, const R_xlen_t n_permu);
RcppExport SEXP _LearnNonparam_ksample_pmt(SEXP dataSEXP, SEXP groupSEXP, SEXP statistic_funcSEXP, SEXP n_permuSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const NumericVector >::type data(dataSEXP);
Rcpp::traits::input_parameter< IntegerVector >::type group(groupSEXP);
Rcpp::traits::input_parameter< const Function >::type statistic_func(statistic_funcSEXP);
Rcpp::traits::input_parameter< const unsigned >::type n_permu(n_permuSEXP);
Rcpp::traits::input_parameter< const R_xlen_t >::type n_permu(n_permuSEXP);
rcpp_result_gen = Rcpp::wrap(ksample_pmt(data, group, statistic_func, n_permu));
return rcpp_result_gen;
END_RCPP
}
// multicomp_pmt
NumericVector multicomp_pmt(const IntegerVector group_i, const IntegerVector group_j, const NumericVector data, IntegerVector group, const Function statistic_func, const unsigned n_permu);
NumericVector multicomp_pmt(const IntegerVector group_i, const IntegerVector group_j, const NumericVector data, IntegerVector group, const Function statistic_func, const R_xlen_t n_permu);
RcppExport SEXP _LearnNonparam_multicomp_pmt(SEXP group_iSEXP, SEXP group_jSEXP, SEXP dataSEXP, SEXP groupSEXP, SEXP statistic_funcSEXP, SEXP n_permuSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Expand All @@ -49,61 +49,61 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< const NumericVector >::type data(dataSEXP);
Rcpp::traits::input_parameter< IntegerVector >::type group(groupSEXP);
Rcpp::traits::input_parameter< const Function >::type statistic_func(statistic_funcSEXP);
Rcpp::traits::input_parameter< const unsigned >::type n_permu(n_permuSEXP);
Rcpp::traits::input_parameter< const R_xlen_t >::type n_permu(n_permuSEXP);
rcpp_result_gen = Rcpp::wrap(multicomp_pmt(group_i, group_j, data, group, statistic_func, n_permu));
return rcpp_result_gen;
END_RCPP
}
// paired_pmt
NumericVector paired_pmt(const unsigned n, const Function statistic_func, const unsigned n_permu);
NumericVector paired_pmt(const R_len_t n, const Function statistic_func, const R_xlen_t n_permu);
RcppExport SEXP _LearnNonparam_paired_pmt(SEXP nSEXP, SEXP statistic_funcSEXP, SEXP n_permuSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const unsigned >::type n(nSEXP);
Rcpp::traits::input_parameter< const R_len_t >::type n(nSEXP);
Rcpp::traits::input_parameter< const Function >::type statistic_func(statistic_funcSEXP);
Rcpp::traits::input_parameter< const unsigned >::type n_permu(n_permuSEXP);
Rcpp::traits::input_parameter< const R_xlen_t >::type n_permu(n_permuSEXP);
rcpp_result_gen = Rcpp::wrap(paired_pmt(n, statistic_func, n_permu));
return rcpp_result_gen;
END_RCPP
}
// rcbd_pmt
NumericVector rcbd_pmt(NumericMatrix data, const Function statistic_func, const unsigned n_permu);
NumericVector rcbd_pmt(NumericMatrix data, const Function statistic_func, const R_xlen_t n_permu);
RcppExport SEXP _LearnNonparam_rcbd_pmt(SEXP dataSEXP, SEXP statistic_funcSEXP, SEXP n_permuSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericMatrix >::type data(dataSEXP);
Rcpp::traits::input_parameter< const Function >::type statistic_func(statistic_funcSEXP);
Rcpp::traits::input_parameter< const unsigned >::type n_permu(n_permuSEXP);
Rcpp::traits::input_parameter< const R_xlen_t >::type n_permu(n_permuSEXP);
rcpp_result_gen = Rcpp::wrap(rcbd_pmt(data, statistic_func, n_permu));
return rcpp_result_gen;
END_RCPP
}
// table_pmt
NumericVector table_pmt(IntegerVector row_loc, const IntegerVector col_loc, const Function statistic_func, const unsigned n_permu);
NumericVector table_pmt(IntegerVector row_loc, const IntegerVector col_loc, const Function statistic_func, const R_xlen_t n_permu);
RcppExport SEXP _LearnNonparam_table_pmt(SEXP row_locSEXP, SEXP col_locSEXP, SEXP statistic_funcSEXP, SEXP n_permuSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< IntegerVector >::type row_loc(row_locSEXP);
Rcpp::traits::input_parameter< const IntegerVector >::type col_loc(col_locSEXP);
Rcpp::traits::input_parameter< const Function >::type statistic_func(statistic_funcSEXP);
Rcpp::traits::input_parameter< const unsigned >::type n_permu(n_permuSEXP);
Rcpp::traits::input_parameter< const R_xlen_t >::type n_permu(n_permuSEXP);
rcpp_result_gen = Rcpp::wrap(table_pmt(row_loc, col_loc, statistic_func, n_permu));
return rcpp_result_gen;
END_RCPP
}
// twosample_pmt
NumericVector twosample_pmt(const NumericVector data, LogicalVector where_y, const Function statistic_func, const unsigned n_permu);
NumericVector twosample_pmt(const NumericVector data, LogicalVector where_y, const Function statistic_func, const R_xlen_t n_permu);
RcppExport SEXP _LearnNonparam_twosample_pmt(SEXP dataSEXP, SEXP where_ySEXP, SEXP statistic_funcSEXP, SEXP n_permuSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const NumericVector >::type data(dataSEXP);
Rcpp::traits::input_parameter< LogicalVector >::type where_y(where_ySEXP);
Rcpp::traits::input_parameter< const Function >::type statistic_func(statistic_funcSEXP);
Rcpp::traits::input_parameter< const unsigned >::type n_permu(n_permuSEXP);
Rcpp::traits::input_parameter< const R_xlen_t >::type n_permu(n_permuSEXP);
rcpp_result_gen = Rcpp::wrap(twosample_pmt(data, where_y, statistic_func, n_permu));
return rcpp_result_gen;
END_RCPP
Expand Down
2 changes: 1 addition & 1 deletion src/association_pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NumericVector association_pmt(
const NumericVector x,
NumericVector y,
const Function statistic_func,
const unsigned n_permu)
const R_xlen_t n_permu)
{
auto association_statistic = [&]() -> double {
return as<double>(statistic_func(x, y));
Expand Down
2 changes: 1 addition & 1 deletion src/ksample_pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NumericVector ksample_pmt(
const NumericVector data,
IntegerVector group,
const Function statistic_func,
const unsigned n_permu)
const R_xlen_t n_permu)
{
auto ksample_statistic = [&]() -> double {
return as<double>(statistic_func(data, group));
Expand Down
10 changes: 5 additions & 5 deletions src/multicomp_pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ NumericVector multicomp_pmt(
const NumericVector data,
IntegerVector group,
const Function statistic_func,
const unsigned n_permu)
const R_xlen_t n_permu)
{
unsigned n_group = group[group.size() - 1];
unsigned n_pair = n_group * (n_group - 1) / 2;
R_len_t n_group = group[group.size() - 1];
R_len_t n_pair = n_group * (n_group - 1) / 2;

List split(n_group);
auto do_split = [&]() {
for (unsigned i = 1; i <= n_group; i++) {
for (R_len_t i = 1; i <= n_group; i++) {
split[i - 1] = data[group == i];
}
};

unsigned j;
R_len_t j;

auto multicomp_statistic = [&]() -> double {
return as<double>(statistic_func(split[group_i[j]], split[group_j[j]], data, group));
Expand Down
11 changes: 5 additions & 6 deletions src/paired_pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ using namespace Rcpp;

// [[Rcpp::export]]
NumericVector paired_pmt(
const unsigned n,
const R_len_t n,
const Function statistic_func,
const unsigned n_permu)
const R_xlen_t n_permu)
{
LogicalVector swapped(n);

unsigned i = 0;
R_xlen_t i = 0;
R_xlen_t total = (1 << n);

auto paired_statistic = [&]() -> double {
for (unsigned j = 0; j < n; j++) {
for (R_len_t j = 0; j < n; j++) {
swapped[j] = ((i & (1 << j)) != 0);
}

return as<double>(statistic_func(swapped));
};

unsigned total = (1 << n);

if (n_permu == 0) {
PermuBar bar(total, true);

Expand Down
10 changes: 5 additions & 5 deletions src/rcbd_pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ using namespace Rcpp;
NumericVector rcbd_pmt(
NumericMatrix data,
const Function statistic_func,
const unsigned n_permu)
const R_xlen_t n_permu)
{
auto rcbd_statistic = [&]() -> double {
return as<double>(statistic_func(data));
};

unsigned i = 0;
unsigned n_col = data.ncol();
R_len_t i = 0;
R_len_t n_col = data.ncol();
if (n_permu == 0) {
unsigned total = 1;
for (unsigned j = 0; j < n_col; j++) {
R_xlen_t total = 1;
for (R_len_t j = 0; j < n_col; j++) {
total *= n_permutation(data.column(j));
}

Expand Down
6 changes: 3 additions & 3 deletions src/table_pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ NumericVector table_pmt(
IntegerVector row_loc,
const IntegerVector col_loc,
const Function statistic_func,
const unsigned n_permu)
const R_xlen_t n_permu)
{
unsigned n = row_loc.size();
R_len_t n = row_loc.size();

IntegerMatrix data(no_init(row_loc[n - 1] + 1, col_loc[n - 1] + 1));

auto table_statistic = [&]() -> double {
data.fill(0);
for (unsigned i = 0; i < n; i++) {
for (R_len_t i = 0; i < n; i++) {
data(row_loc[i], col_loc[i])++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/twosample_pmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NumericVector twosample_pmt(
const NumericVector data,
LogicalVector where_y,
const Function statistic_func,
const unsigned n_permu)
const R_xlen_t n_permu)
{
auto twosample_statistic = [&]() -> double {
return as<double>(statistic_func(data[!where_y], data[where_y]));
Expand Down
29 changes: 15 additions & 14 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using namespace Rcpp;

// runif(max = n) (tied to the same RNG which R uses)

inline unsigned rand_int(const unsigned& n)
template <typename T>
T rand_int(T n)
{
return floor(unif_rand() * n);
}
Expand All @@ -20,9 +21,9 @@ inline unsigned rand_int(const unsigned& n)
template <typename T>
void random_shuffle(T&& v)
{
unsigned j;
unsigned n = v.size();
for (unsigned i = 0; i < n - 1; i++) {
R_len_t j;
R_len_t n = v.size();
for (R_len_t i = 0; i < n - 1; i++) {
j = i + rand_int(n - i);
std::swap(v[i], v[j]);
}
Expand All @@ -31,14 +32,14 @@ void random_shuffle(T&& v)
// number of permutations

template <typename T>
unsigned n_permutation(T&& v)
R_xlen_t n_permutation(T&& v)
{
double A = 1;

unsigned n_i = 0;
unsigned n = v.size();
R_len_t n_i = 0;
R_len_t n = v.size();
double current = v[0];
for (unsigned i = 0; i < n; i++) {
for (R_len_t i = 0; i < n; i++) {
A *= (i + 1);
if (v[i] == current) {
n_i++;
Expand All @@ -49,17 +50,17 @@ unsigned n_permutation(T&& v)
current = v[i];
}

return (unsigned)A;
return (R_xlen_t)A;
}

// progress bar

class PermuBar {
private:
unsigned _total;
R_xlen_t _total;

unsigned _update_i = 0;
unsigned _update_every;
R_xlen_t _update_i = 0;
R_xlen_t _update_every;

NumericVector::iterator _iter;
NumericVector::iterator _end;
Expand All @@ -74,7 +75,7 @@ class PermuBar {

buffer << "\015";

unsigned percent = 100 - 100 * (_end - _iter) / _total;
unsigned percent = 100 - (unsigned)(100 * (_end - _iter) / _total);

buffer << "\033[31m" << percent << "%";

Expand Down Expand Up @@ -103,7 +104,7 @@ class PermuBar {
public:
NumericVector statistic_permu;

PermuBar(unsigned n_permu, bool exact, unsigned statistic_size = 1)
PermuBar(R_xlen_t n_permu, bool exact, R_len_t statistic_size = 1)
{
_total = n_permu * statistic_size;

Expand Down

0 comments on commit 2f6298b

Please sign in to comment.