Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Dec 17, 2024
1 parent 532bc89 commit 316ffad
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion R/AnsariBradley.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ AnsariBradley <- R6Class(
private$.p_value <- get_p_continous(z, "norm", private$.side)
}
)
)
)
2 changes: 1 addition & 1 deletion R/Friedman.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ Friedman <- R6Class(
)
}
)
)
)
2 changes: 1 addition & 1 deletion R/KolmogorovSmirnov.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ KolmogorovSmirnov <- R6Class(
private$.side <- "r"
}
)
)
)
2 changes: 1 addition & 1 deletion R/Page.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ Page <- R6Class(
private$.p_value <- get_p_continous(z, "norm", private$.side)
}
)
)
)
3 changes: 1 addition & 2 deletions R/RCBDOneWay.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ RCBDOneWay <- R6Class(
)
}
)
)

)
2 changes: 1 addition & 1 deletion R/do_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ do_call <- function(func, default = list(), fixed = list(), ...) {
# All arguments will be evaluated within the `args` environment.
# https://stackoverflow.com/a/25371509/23137996
eval(as.call(c(func, lapply(`names<-`(...args, ...args), as.name))), args)
}
}
10 changes: 5 additions & 5 deletions R/pmt.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ pmts <- function(
#' rcpp <- define_pmt(
#' inherit = "twosample", n_permu = 1e5,
#' statistic = "[](const auto& x, const auto& y) {
#' auto m = x.size();
#' auto n = y.size();
#' auto m = x.length();
#' auto n = y.length();
#' return [=](const auto& x, const auto& y) {
#' return sum(x) / m - sum(y) / n;
#' };
Expand All @@ -176,9 +176,9 @@ pmts <- function(
#' # rcpp <- define_pmt(
#' # inherit = "twosample", n_permu = 1e5,
#' # statistic = "[](const NumericVector& x, const NumericVector& y) {
#' # R_xlen_t m = x.size();
#' # R_xlen_t n = y.size();
#' # return [=](const NumericVector& x, const NumericVector& y) -> double {
#' # R_xlen_t m = x.length();
#' # R_xlen_t n = y.length();
#' # return [m, n](const NumericVector& x, const NumericVector& y) -> double {
#' # return sum(x) / m - sum(y) / n;
#' # };
#' # }"
Expand Down
19 changes: 10 additions & 9 deletions inst/include/pmt/permutation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <algorithm>
#include <iterator>

template <typename T>
using diff_t = typename std::iterator_traits<T>::difference_type;

template <typename T>
T rand_int(T n)
{
Expand All @@ -12,12 +15,10 @@ T rand_int(T n)
template <typename T>
void random_shuffle(T first, T last)
{
using diff_t = typename std::iterator_traits<T>::difference_type;

diff_t n = std::distance(first, last);
diff_t<T> n = std::distance(first, last);

for (diff_t i = 0; i < n - 1; i++) {
diff_t j = i + rand_int(n - i);
for (diff_t<T> i = 0; i < n - 1; i++) {
diff_t<T> j = i + rand_int(n - i);
std::iter_swap(first + i, first + j);
}
}
Expand All @@ -33,7 +34,7 @@ double n_permutation(T first, T last)
{
double A = 1.0;

typename std::iterator_traits<T>::difference_type rep = 0;
diff_t<T> rep = 0;

auto val = *first;
for (auto it = first; it != last; it++) {
Expand All @@ -50,19 +51,19 @@ double n_permutation(T first, T last)
}

template <typename T>
auto random_shuffle(T& v)
auto random_shuffle(T&& v)
{
return random_shuffle(v.begin(), v.end());
}

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

template <typename T>
auto n_permutation(const T& v)
auto n_permutation(T&& v)
{
return n_permutation(v.begin(), v.end());
}
10 changes: 5 additions & 5 deletions man/pmt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 316ffad

Please sign in to comment.