Skip to content

Commit

Permalink
Merge pull request #59 from Dongcan-Jiang/feature/subsetting
Browse files Browse the repository at this point in the history
Fix & Speedup
  • Loading branch information
HenrikBengtsson committed Jul 21, 2015
2 parents 4ffbd31 + 6b921df commit df0b7ea
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/colOrderStats_TYPE-template.h
Expand Up @@ -60,9 +60,9 @@ RETURN_TYPE METHOD_NAME_ROWS_COLS(ARGUMENTS_LIST) {
values = (X_C_TYPE *) R_alloc(nrows, sizeof(X_C_TYPE));

for (jj=0; jj < ncols; jj++) {
offset = COL_INDEX(ccols,jj) * nrow;
offset = COL_INDEX_NONA(ccols,jj) * nrow;
for (ii=0; ii < nrows; ii++)
values[ii] = x[ROW_INDEX(crows,ii) + offset];
values[ii] = x[ROW_INDEX_NONA(crows,ii) + offset];

/* Sort vector of length 'nrows' up to position 'qq'.
"...partial sorting: they permute x so that x[qq] is in the
Expand Down
4 changes: 2 additions & 2 deletions src/rowOrderStats_TYPE-template.h
Expand Up @@ -63,10 +63,10 @@ RETURN_TYPE METHOD_NAME_ROWS_COLS(ARGUMENTS_LIST) {
/* Pre-calculate the column offsets */
colOffset = (R_xlen_t *) R_alloc(ncols, sizeof(R_xlen_t));
for (jj=0; jj < ncols; jj++)
colOffset[jj] = COL_INDEX(ccols,jj) * nrow;
colOffset[jj] = COL_INDEX_NONA(ccols,jj) * nrow;

for (ii=0; ii < nrows; ii++) {
rowIdx = ROW_INDEX(crows,ii);
rowIdx = ROW_INDEX_NONA(crows,ii);
for (jj=0; jj < ncols; jj++)
values[jj] = x[rowIdx + colOffset[jj]];

Expand Down
3 changes: 2 additions & 1 deletion tests/rowVarDiffs_mad,iqr_subset.R
Expand Up @@ -17,8 +17,9 @@ for (fcn in names(FUNs)) {

for (mode in c("numeric", "integer")) {
x <- matrix(runif(6*6, min=-6, max=6), nrow=6L, ncol=6L)
storage.mode(x) <- mode
trim <- runif(1, min=0, max=0.5)
if (mode == "numeric") x[0] <- Inf
if (mode == "numeric") x[1:2,3:4] <- Inf

for (diff in 1:2) {
for (rows in indexCases) {
Expand Down
3 changes: 2 additions & 1 deletion tests/rowVarDiffs_var,sd_subset.R
Expand Up @@ -17,8 +17,9 @@ for (fcn in names(FUNs)) {

for (mode in c("numeric", "integer")) {
x <- matrix(runif(6*6, min=-6, max=6), nrow=6L, ncol=6L)
storage.mode(x) <- mode
trim <- runif(1, min=0, max=0.5)
if (mode == "numeric") x[0] <- Inf
if (mode == "numeric") x[1:2,3:4] <- Inf

for (diff in 1:2) {
for (rows in indexCases) {
Expand Down
3 changes: 2 additions & 1 deletion tests/varDiff_etal_subset.R
Expand Up @@ -18,8 +18,9 @@ for (fcn in names(FUNs)) {

for (mode in c("numeric", "integer")) {
x <- runif(6, min=-6, max=6)
storage.mode(x) <- mode
trim <- runif(1, min=0, max=0.5)
if (mode == "numeric") x[0] <- Inf
if (mode == "numeric") x[1] <- Inf

for (diff in 1:2) {
for (idxs in indexCases) {
Expand Down

0 comments on commit df0b7ea

Please sign in to comment.