Skip to content

Commit

Permalink
improved cpp code
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Nov 30, 2024
1 parent d2ac38a commit a0ca4be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions inst/include/pmt/reorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ T rand_int(T n)
}

template <typename T>
void random_shuffle(T v)
void random_shuffle(T&& v)
{
R_len_t n = v.size();

Expand All @@ -21,13 +21,13 @@ void random_shuffle(T v)
}

template <typename T>
bool next_permutation(T v)
bool next_permutation(T&& v)
{
return std::next_permutation(v.begin(), v.end());
}

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

Expand Down
34 changes: 17 additions & 17 deletions src/pmt_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename... Args>
auto operator()(Args&&... args) const
{
return [closure = Function(Function::operator()(std::forward<Args>(args)...))](auto&&... args) {
return as<double>(closure(std::forward<decltype(args)>(args)...));
return [r_closure = Function(Function::operator()(std::forward<Args>(args)...))](auto&&... args) {
return as<double>(r_closure(std::forward<decltype(args)>(args)...));
};
}
};
Expand All @@ -29,8 +29,8 @@ SEXP twosample_pmt(
const bool progress)
{
return progress ?
impl_twosample_pmt<PermuBarShow, ClosFunc>(clone(x), clone(y), statistic_func, n_permu) :
impl_twosample_pmt<PermuBarHide, ClosFunc>(clone(x), clone(y), statistic_func, n_permu);
impl_twosample_pmt<PermuBarShow, StatFunc>(clone(x), clone(y), statistic_func, n_permu) :
impl_twosample_pmt<PermuBarHide, StatFunc>(clone(x), clone(y), statistic_func, n_permu);
}

#include "pmt/impl_ksample_pmt.hpp"
Expand All @@ -44,8 +44,8 @@ SEXP ksample_pmt(
const bool progress)
{
return progress ?
impl_ksample_pmt<PermuBarShow, ClosFunc>(data, clone(group), statistic_func, n_permu) :
impl_ksample_pmt<PermuBarHide, ClosFunc>(data, clone(group), statistic_func, n_permu);
impl_ksample_pmt<PermuBarShow, StatFunc>(data, clone(group), statistic_func, n_permu) :
impl_ksample_pmt<PermuBarHide, StatFunc>(data, clone(group), statistic_func, n_permu);
}

#include "pmt/impl_multcomp_pmt.hpp"
Expand All @@ -61,8 +61,8 @@ SEXP multcomp_pmt(
const bool progress)
{
return progress ?
impl_multcomp_pmt<PermuBarShow, ClosFunc>(group_i, group_j, data, clone(group), statistic_func, n_permu) :
impl_multcomp_pmt<PermuBarHide, ClosFunc>(group_i, group_j, data, clone(group), statistic_func, n_permu);
impl_multcomp_pmt<PermuBarShow, StatFunc>(group_i, group_j, data, clone(group), statistic_func, n_permu) :
impl_multcomp_pmt<PermuBarHide, StatFunc>(group_i, group_j, data, clone(group), statistic_func, n_permu);
}

#include "pmt/impl_paired_pmt.hpp"
Expand All @@ -76,8 +76,8 @@ SEXP paired_pmt(
const bool progress)
{
return progress ?
impl_paired_pmt<PermuBarShow, ClosFunc>(clone(x), clone(y), statistic_func, n_permu) :
impl_paired_pmt<PermuBarHide, ClosFunc>(clone(x), clone(y), statistic_func, n_permu);
impl_paired_pmt<PermuBarShow, StatFunc>(clone(x), clone(y), statistic_func, n_permu) :
impl_paired_pmt<PermuBarHide, StatFunc>(clone(x), clone(y), statistic_func, n_permu);
}

#include "pmt/impl_rcbd_pmt.hpp"
Expand All @@ -90,8 +90,8 @@ SEXP rcbd_pmt(
const bool progress)
{
return progress ?
impl_rcbd_pmt<PermuBarShow, ClosFunc>(clone(data), statistic_func, n_permu) :
impl_rcbd_pmt<PermuBarHide, ClosFunc>(clone(data), statistic_func, n_permu);
impl_rcbd_pmt<PermuBarShow, StatFunc>(clone(data), statistic_func, n_permu) :
impl_rcbd_pmt<PermuBarHide, StatFunc>(clone(data), statistic_func, n_permu);
}

#include "pmt/impl_association_pmt.hpp"
Expand All @@ -105,8 +105,8 @@ SEXP association_pmt(
const bool progress)
{
return progress ?
impl_association_pmt<PermuBarShow, ClosFunc>(x, clone(y), statistic_func, n_permu) :
impl_association_pmt<PermuBarHide, ClosFunc>(x, clone(y), statistic_func, n_permu);
impl_association_pmt<PermuBarShow, StatFunc>(x, clone(y), statistic_func, n_permu) :
impl_association_pmt<PermuBarHide, StatFunc>(x, clone(y), statistic_func, n_permu);
}

#include "pmt/impl_table_pmt.hpp"
Expand All @@ -120,6 +120,6 @@ SEXP table_pmt(
const bool progress)
{
return progress ?
impl_table_pmt<PermuBarShow, ClosFunc>(row, clone(col), statistic_func, n_permu) :
impl_table_pmt<PermuBarHide, ClosFunc>(row, clone(col), statistic_func, n_permu);
impl_table_pmt<PermuBarShow, StatFunc>(row, clone(col), statistic_func, n_permu) :
impl_table_pmt<PermuBarHide, StatFunc>(row, clone(col), statistic_func, n_permu);
}

0 comments on commit a0ca4be

Please sign in to comment.