From a0ca4bea46fa70f4cddae378c3864c0f7d0d704e Mon Sep 17 00:00:00 2001 From: qddyy Date: Sat, 30 Nov 2024 22:13:59 +0800 Subject: [PATCH] improved cpp code --- inst/include/pmt/reorder.hpp | 6 +++--- src/pmt_interface.cpp | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/inst/include/pmt/reorder.hpp b/inst/include/pmt/reorder.hpp index 3ca8f027..f6201ba4 100644 --- a/inst/include/pmt/reorder.hpp +++ b/inst/include/pmt/reorder.hpp @@ -9,7 +9,7 @@ T rand_int(T n) } template -void random_shuffle(T v) +void random_shuffle(T&& v) { R_len_t n = v.size(); @@ -21,13 +21,13 @@ void random_shuffle(T v) } template -bool next_permutation(T v) +bool next_permutation(T&& v) { return std::next_permutation(v.begin(), v.end()); } template -double n_permutation(T v) +double n_permutation(const T& v) { double A = 1; diff --git a/src/pmt_interface.cpp b/src/pmt_interface.cpp index 7ccf241e..924ec1d6 100644 --- a/src/pmt_interface.cpp +++ b/src/pmt_interface.cpp @@ -5,15 +5,15 @@ using namespace Rcpp; #include "pmt/progress.hpp" #include "pmt/reorder.hpp" -class ClosFunc : public Function { +class StatFunc : public Function { public: using Function::Function; template auto operator()(Args&&... args) const { - return [closure = Function(Function::operator()(std::forward(args)...))](auto&&... args) { - return as(closure(std::forward(args)...)); + return [r_closure = Function(Function::operator()(std::forward(args)...))](auto&&... args) { + return as(r_closure(std::forward(args)...)); }; } }; @@ -29,8 +29,8 @@ SEXP twosample_pmt( const bool progress) { return progress ? - impl_twosample_pmt(clone(x), clone(y), statistic_func, n_permu) : - impl_twosample_pmt(clone(x), clone(y), statistic_func, n_permu); + impl_twosample_pmt(clone(x), clone(y), statistic_func, n_permu) : + impl_twosample_pmt(clone(x), clone(y), statistic_func, n_permu); } #include "pmt/impl_ksample_pmt.hpp" @@ -44,8 +44,8 @@ SEXP ksample_pmt( const bool progress) { return progress ? - impl_ksample_pmt(data, clone(group), statistic_func, n_permu) : - impl_ksample_pmt(data, clone(group), statistic_func, n_permu); + impl_ksample_pmt(data, clone(group), statistic_func, n_permu) : + impl_ksample_pmt(data, clone(group), statistic_func, n_permu); } #include "pmt/impl_multcomp_pmt.hpp" @@ -61,8 +61,8 @@ SEXP multcomp_pmt( const bool progress) { return progress ? - impl_multcomp_pmt(group_i, group_j, data, clone(group), statistic_func, n_permu) : - impl_multcomp_pmt(group_i, group_j, data, clone(group), statistic_func, n_permu); + impl_multcomp_pmt(group_i, group_j, data, clone(group), statistic_func, n_permu) : + impl_multcomp_pmt(group_i, group_j, data, clone(group), statistic_func, n_permu); } #include "pmt/impl_paired_pmt.hpp" @@ -76,8 +76,8 @@ SEXP paired_pmt( const bool progress) { return progress ? - impl_paired_pmt(clone(x), clone(y), statistic_func, n_permu) : - impl_paired_pmt(clone(x), clone(y), statistic_func, n_permu); + impl_paired_pmt(clone(x), clone(y), statistic_func, n_permu) : + impl_paired_pmt(clone(x), clone(y), statistic_func, n_permu); } #include "pmt/impl_rcbd_pmt.hpp" @@ -90,8 +90,8 @@ SEXP rcbd_pmt( const bool progress) { return progress ? - impl_rcbd_pmt(clone(data), statistic_func, n_permu) : - impl_rcbd_pmt(clone(data), statistic_func, n_permu); + impl_rcbd_pmt(clone(data), statistic_func, n_permu) : + impl_rcbd_pmt(clone(data), statistic_func, n_permu); } #include "pmt/impl_association_pmt.hpp" @@ -105,8 +105,8 @@ SEXP association_pmt( const bool progress) { return progress ? - impl_association_pmt(x, clone(y), statistic_func, n_permu) : - impl_association_pmt(x, clone(y), statistic_func, n_permu); + impl_association_pmt(x, clone(y), statistic_func, n_permu) : + impl_association_pmt(x, clone(y), statistic_func, n_permu); } #include "pmt/impl_table_pmt.hpp" @@ -120,6 +120,6 @@ SEXP table_pmt( const bool progress) { return progress ? - impl_table_pmt(row, clone(col), statistic_func, n_permu) : - impl_table_pmt(row, clone(col), statistic_func, n_permu); + impl_table_pmt(row, clone(col), statistic_func, n_permu) : + impl_table_pmt(row, clone(col), statistic_func, n_permu); } \ No newline at end of file