Skip to content

Commit

Permalink
Updated cpp_sset_range to use 'R_xlen_t' throughout and updated docum…
Browse files Browse the repository at this point in the history
…entation.
  • Loading branch information
NicChr committed Apr 5, 2024
1 parent dcb3322 commit 8a13a51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 8 additions & 1 deletion R/sset.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' `sset` will fall back on using `[` when no suitable method is found.
#'
#' To get into more detail, using `sset()` on a data frame, a new
#' list is always allocated through `cheapr:::cpp_new_list()`.
#' list is always allocated through `new_list()`.
#'
#' ### Difference to base R
#'
Expand All @@ -25,6 +25,13 @@
#' is not recycled, so it is good practice to make sure the logical vector
#' matches the length of x. To return `NA` values, use `x[NA_integer_]`.
#'
#' ### ALTREP range subsetting
#'
#' When `i` is an ALTREP compact integer sequence which can be commonly created
#' using e.g. `1:10` or using `seq_len`, `seq_along` and `seq.int`,
#' `sset` internally uses a range-based subsetting which is faster and doesn't
#' allocate `i` into memory.
#'
#' @examples
#' library(cheapr)
#' library(bench)
Expand Down
10 changes: 9 additions & 1 deletion man/sset.Rd

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

6 changes: 3 additions & 3 deletions src/sset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ SEXP cpp_sset_range(SEXP x, R_xlen_t from, R_xlen_t to, R_xlen_t by){
}
// We first switch them
if (istart < iend){
int iend_temp = iend;
R_xlen_t iend_temp = iend;
iend = istart;
istart = iend_temp;
}
Expand Down Expand Up @@ -393,7 +393,7 @@ case REALSXP: {
} else {
if (by > 0){
#pragma omp parallel for simd num_threads(n_cores) if (do_parallel)
for (int i = istart - 1; i < iend; ++i){
for (R_xlen_t i = istart - 1; i < iend; ++i){
p_out[i - istart + 1] = i < n ? p_x[i] : NA_REAL;
}
} else {
Expand All @@ -415,7 +415,7 @@ case STRSXP: {
SET_STRING_ELT(out, k++, i < n ? p_x[i] : NA_STRING);
}
#pragma omp for simd
for (int j = istart2 - 1; j < iend2; ++j){
for (R_xlen_t j = istart2 - 1; j < iend2; ++j){
SET_STRING_ELT(out, k++, j < n ? p_x[j] : NA_STRING);
}
} else {
Expand Down

0 comments on commit 8a13a51

Please sign in to comment.