Skip to content

Commit

Permalink
Use asLogicalNoNA(useNames) [#246]
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Dec 28, 2024
1 parent 7beead3 commit 70c356d
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: matrixStats
Version: 1.4.1-9005
Version: 1.4.1-9006
Depends:
R (>= 3.4.0)
Suggests:
Expand Down
4 changes: 2 additions & 2 deletions src/colCounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ SEXP colCounts(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP value, SEXP what, SE
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
SEXP namesVec = VECTOR_ELT(dimnames, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/colOrderStats.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SEXP colOrderStats(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP which, SEXP useN
R_xlen_t *ccols = validateIndicesCheckNA(cols, ncol, 0, &ncols, &colsHasna);

/* Argument 'useNames': */
int usenames = asLogical(useNames);
int usenames = asLogicalNoNA(useNames, "useNames");

// Check missing rows
if (rowsHasna && ncols > 0) {
Expand All @@ -62,7 +62,7 @@ SEXP colOrderStats(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP which, SEXP useN
if (isReal(x)) {
PROTECT(ans = allocVector(REALSXP, ncols));
colOrderStats_dbl(REAL(x), nrow, ncol, crows, nrows, ccols, ncols, qq, REAL(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
SEXP namesVec = VECTOR_ELT(dimnames, 1);
Expand All @@ -75,7 +75,7 @@ SEXP colOrderStats(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP which, SEXP useN
} else if (isInteger(x)) {
PROTECT(ans = allocVector(INTSXP, ncols));
colOrderStats_int(INTEGER(x), nrow, ncol, crows, nrows, ccols, ncols, qq, INTEGER(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
SEXP namesVec = VECTOR_ELT(dimnames, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/colRanges.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SEXP colRanges(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP what, SEXP naRm, SEX
R_xlen_t *ccols = validateIndicesCheckNA(cols, ncol, 0, &ncols, &colsHasNA);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

is_counted = (int *) R_alloc(ncols, sizeof(int));

Expand All @@ -61,7 +61,7 @@ SEXP colRanges(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP what, SEXP naRm, SEX
PROTECT(ans = allocVector(REALSXP, ncols));
}
colRanges_dbl(REAL(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, what2, narm, hasna, REAL(ans), is_counted);
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (what2 == 2) {
Expand Down Expand Up @@ -143,7 +143,7 @@ SEXP colRanges(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP what, SEXP naRm, SEX

ans = ans2;
}
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (what2 == 2) {
Expand Down
4 changes: 2 additions & 2 deletions src/diff2.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SEXP diff2(SEXP x, SEXP idxs, SEXP lag, SEXP differences, SEXP useNames) {
R_xlen_t nidxs;

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

int idxsHasNA;
R_xlen_t *cidxs = validateIndicesCheckNA(idxs, nx, 1, &nidxs, &idxsHasNA);
Expand All @@ -56,7 +56,7 @@ SEXP diff2(SEXP x, SEXP idxs, SEXP lag, SEXP differences, SEXP useNames) {
error("Argument 'x' must be numeric");
}

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP namesVec;
PROTECT(namesVec = getAttrib(x, R_NamesSymbol));
if (namesVec != R_NilValue) {
Expand Down
4 changes: 2 additions & 2 deletions src/rowCounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ SEXP rowCounts(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP value, SEXP what, SE
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
SEXP namesVec = VECTOR_ELT(dimnames, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/rowCummaxs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ SEXP rowCummaxs(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useName
byrow = asLogical(byRow);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

/* Double matrices are more common to use. */
if (isReal(x)) {
PROTECT(ans = allocMatrix(REALSXP, nrows, ncols));
rowCummaxs_dbl(REAL(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, REAL(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand All @@ -52,7 +52,7 @@ SEXP rowCummaxs(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useName
} else if (isInteger(x) | isLogical(x)) {
PROTECT(ans = allocMatrix(INTSXP, nrows, ncols));
rowCummaxs_int(INTEGER(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, INTEGER(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand Down
6 changes: 3 additions & 3 deletions src/rowCummins.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ SEXP rowCummins(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useName
byrow = asLogical(byRow);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

/* Double matrices are more common to use. */
if (isReal(x)) {
PROTECT(ans = allocMatrix(REALSXP, nrows, ncols));
rowCummins_dbl(REAL(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, REAL(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand All @@ -52,7 +52,7 @@ SEXP rowCummins(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useName
} else if (isInteger(x) | isLogical(x)) {
PROTECT(ans = allocMatrix(INTSXP, nrows, ncols));
rowCummins_int(INTEGER(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, INTEGER(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand Down
6 changes: 3 additions & 3 deletions src/rowCumprods.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ SEXP rowCumprods(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useNam
byrow = asLogical(byRow);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

/* Double matrices are more common to use. */
if (isReal(x)) {
PROTECT(ans = allocMatrix(REALSXP, nrows, ncols));
rowCumprods_dbl(REAL(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, REAL(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand All @@ -51,7 +51,7 @@ SEXP rowCumprods(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useNam
} else if (isInteger(x) | isLogical(x)) {
PROTECT(ans = allocMatrix(INTSXP, nrows, ncols));
rowCumprods_int(INTEGER(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, INTEGER(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand Down
6 changes: 3 additions & 3 deletions src/rowCumsums.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ SEXP rowCumsums(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useName
byrow = asLogical(byRow);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

/* Double matrices are more common to use. */
if (isReal(x)) {
PROTECT(ans = allocMatrix(REALSXP, nrows, ncols));
rowCumsums_dbl(REAL(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, rowsHasNA, byrow, REAL(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand All @@ -50,7 +50,7 @@ SEXP rowCumsums(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP byRow, SEXP useName
} else if (isInteger(x) | isLogical(x)) {
PROTECT(ans = allocMatrix(INTSXP, nrows, ncols));
rowCumsums_int(INTEGER(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, INTEGER(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand Down
6 changes: 3 additions & 3 deletions src/rowDiffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ SEXP rowDiffs(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP lag, SEXP differences
byrow = asLogical(byRow);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

/* Dimension of result matrix */
if (byrow) {
Expand All @@ -65,7 +65,7 @@ SEXP rowDiffs(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP lag, SEXP differences
if (isReal(x)) {
PROTECT(ans = allocMatrix(REALSXP, nrow_ans, ncol_ans));
rowDiffs_dbl(REAL(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, lagg, diff, REAL(ans), nrow_ans, ncol_ans);
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand All @@ -79,7 +79,7 @@ SEXP rowDiffs(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP lag, SEXP differences
} else if (isInteger(x)) {
PROTECT(ans = allocMatrix(INTSXP, nrow_ans, ncol_ans));
rowDiffs_int(INTEGER(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, byrow, lagg, diff, INTEGER(ans), nrow_ans, ncol_ans);
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand Down
4 changes: 2 additions & 2 deletions src/rowLogSumExp.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ SEXP rowLogSumExps(SEXP lx, SEXP dim, SEXP rows, SEXP cols, SEXP naRm, SEXP hasN
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames == NA_LOGICAL || usenames) {
if (usenames) {
SEXP dimnames = getAttrib(lx, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand Down
4 changes: 2 additions & 2 deletions src/rowMads.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ SEXP rowMads(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP constant, SEXP naRm, S
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand Down
4 changes: 2 additions & 2 deletions src/rowMeans2.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ SEXP rowMeans2(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP naRm, SEXP refine2,
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand Down
4 changes: 2 additions & 2 deletions src/rowMedians.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ SEXP rowMedians(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP naRm, SEXP hasNA, S
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand Down
6 changes: 3 additions & 3 deletions src/rowOrderStats.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SEXP rowOrderStats(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP which, SEXP useN
R_xlen_t *ccols = validateIndicesCheckNA(cols, ncol, 0, &ncols, &colsHasna);

/* Argument 'useNames': */
int usenames = asLogical(useNames);
int usenames = asLogicalNoNA(useNames, "useNames");

// Check missing rows
if (rowsHasna && ncols > 0) {
Expand All @@ -62,7 +62,7 @@ SEXP rowOrderStats(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP which, SEXP useN
if (isReal(x)) {
PROTECT(ans = allocVector(REALSXP, nrows));
rowOrderStats_dbl(REAL(x), nrow, ncol, crows, nrows, ccols, ncols, qq, REAL(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
SEXP namesVec = VECTOR_ELT(dimnames, 0);
Expand All @@ -75,7 +75,7 @@ SEXP rowOrderStats(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP which, SEXP useN
} else if (isInteger(x)) {
PROTECT(ans = allocVector(INTSXP, nrows));
rowOrderStats_int(INTEGER(x), nrow, ncol, crows, nrows, ccols, ncols, qq, INTEGER(ans));
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
SEXP namesVec = VECTOR_ELT(dimnames, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/rowRanges.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SEXP rowRanges(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP what, SEXP naRm, SEX
R_xlen_t *ccols = validateIndicesCheckNA(cols, ncol, 0, &ncols, &colsHasNA);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

is_counted = (int *) R_alloc(nrows, sizeof(int));

Expand All @@ -61,7 +61,7 @@ SEXP rowRanges(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP what, SEXP naRm, SEX
PROTECT(ans = allocVector(REALSXP, nrows));
}
rowRanges_dbl(REAL(x), nrow, ncol, crows, nrows, rowsHasNA, ccols, ncols, colsHasNA, what2, narm, hasna, REAL(ans), is_counted);
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (what2 == 2) {
Expand Down Expand Up @@ -142,7 +142,7 @@ SEXP rowRanges(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP what, SEXP naRm, SEX

ans = ans2;
}
if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (what2 == 2) {
Expand Down
4 changes: 2 additions & 2 deletions src/rowRanksWithTies.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SEXP rowRanksWithTies(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP tiesMethod, S
byrow = asLogical(byRow);

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

/* Double matrices are more common to use. */
if (isReal(x)) {
Expand Down Expand Up @@ -133,7 +133,7 @@ SEXP rowRanksWithTies(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP tiesMethod, S
} /* switch */
}

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
setDimnames(ans, dimnames, nrows, crows, ncols, ccols, FALSE);
Expand Down
4 changes: 2 additions & 2 deletions src/rowSums2.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ SEXP rowSums2(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP naRm, SEXP hasNA, SEX
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand Down
4 changes: 2 additions & 2 deletions src/rowVars.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ SEXP rowVars(SEXP x, SEXP dim, SEXP rows, SEXP cols, SEXP naRm, SEXP refine2, SE
}

/* Argument 'useNames': */
usenames = asLogical(useNames);
usenames = asLogicalNoNA(useNames, "useNames");

if (usenames != NA_LOGICAL && usenames) {
if (usenames) {
SEXP dimnames = getAttrib(x, R_DimNamesSymbol);
if (dimnames != R_NilValue) {
if (byrow) {
Expand Down

0 comments on commit 70c356d

Please sign in to comment.