Skip to content

Commit

Permalink
improved association_pmt & table_pmt
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Dec 9, 2024
1 parent 0fbcb65 commit 1d9d36d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 6 additions & 3 deletions inst/include/pmt/impl_association_pmt.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
template <typename T, typename U>
NumericVector impl_association_pmt(
const NumericVector x,
NumericVector x,
NumericVector y,
const U& statistic_func,
const double n_permu)
Expand All @@ -16,13 +16,16 @@ NumericVector impl_association_pmt(

if (!std::isnan(n_permu)) {
if (n_permu == 0) {
std::sort(x.begin(), x.end());
std::sort(y.begin(), y.end());

bar.init_statistic_permu(n_permutation(y));
NumericVector y_ = (n_permutation(x) < n_permutation(y)) ? x : y;

bar.init_statistic_permu(n_permutation(y_));

do {
association_update();
} while (next_permutation(y));
} while (next_permutation(y_));
} else {
bar.init_statistic_permu(n_permu);

Expand Down
10 changes: 7 additions & 3 deletions inst/include/pmt/impl_table_pmt.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
template <typename T, typename U>
NumericVector impl_table_pmt(
const IntegerVector row,
IntegerVector row,
IntegerVector col,
const U& statistic_func,
const double n_permu)
Expand Down Expand Up @@ -28,11 +28,15 @@ NumericVector impl_table_pmt(

if (!std::isnan(n_permu)) {
if (n_permu == 0) {
bar.init_statistic_permu(n_permutation(col));
std::sort(row.begin(), row.end());

IntegerVector col_ = (n_permutation(row) < n_permutation(col)) ? row : col;

bar.init_statistic_permu(n_permutation(col_));

do {
table_update();
} while (next_permutation(col));
} while (next_permutation(col_));
} else {
bar.init_statistic_permu(n_permu);

Expand Down
10 changes: 5 additions & 5 deletions src/pmt_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ SEXP association_pmt(
const bool progress)
{
return progress ?
impl_association_pmt<PermuBarShow, StatFunc<true>>(x, clone(y), statistic_func, n_permu) :
impl_association_pmt<PermuBarHide, StatFunc<true>>(x, clone(y), statistic_func, n_permu);
impl_association_pmt<PermuBarShow, StatFunc<true>>(clone(x), clone(y), statistic_func, n_permu) :
impl_association_pmt<PermuBarHide, StatFunc<true>>(clone(x), clone(y), statistic_func, n_permu);
}

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

0 comments on commit 1d9d36d

Please sign in to comment.