Skip to content

Commit

Permalink
fix for large n_permu
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Aug 3, 2024
1 parent 67607c8 commit 81daa2e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion inst/include/pmt/impl_rcbd_pmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NumericVector impl_rcbd_pmt(
R_len_t i = 0;
R_len_t n_block = data.ncol();
if (n_permu == 0) {
R_xlen_t total = 1;
double total = 1.0;
for (R_len_t j = 0; j < n_block; j++) {
std::sort(data.column(j).begin(), data.column(j).end());
total *= n_permutation(data.column(j));
Expand Down
11 changes: 8 additions & 3 deletions inst/include/pmt/progress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PermuBarHide {
_statistic_buffer = NumericVector(0);
}

void init_statistic_permu(const R_xlen_t n_permu)
void init_statistic_permu(const double n_permu)
{
_init_statistic_buffer(n_permu, _statistic_size);
}
Expand All @@ -76,9 +76,14 @@ class PermuBarHide {

NumericVector _statistic_buffer;

void _init_statistic_buffer(const R_xlen_t n, const R_len_t size)
void _init_statistic_buffer(const double n, const R_len_t size)
{
_statistic_buffer = std::move(NumericVector(no_init(n * size)));
double total = n * size;
if (total <= 0 || total > R_XLEN_T_MAX) {
stop("Too many permutations");
}

_statistic_buffer = std::move(NumericVector(no_init(static_cast<R_xlen_t>(total))));

_buffer_i = 0;
_buffer_size = _statistic_buffer.size();
Expand Down
4 changes: 2 additions & 2 deletions inst/include/pmt/reorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool next_permutation(T v)
}

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

Expand All @@ -44,5 +44,5 @@ R_xlen_t n_permutation(T v)
current = v[i];
}

return static_cast<R_xlen_t>(A);
return A;
}

0 comments on commit 81daa2e

Please sign in to comment.