R Under development (unstable) (2024-09-02 r87090 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("matrixStats") > > ## Always allow testing of the 'center' argument (as long as it's not defunct) > options(matrixStats.center.onUse = "ignore") > > ## Create isFALSE() if running on an old version of R > if (!exists("isFALSE", mode="function")) { + isFALSE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && !x + } > > rowSds_R <- function(x, na.rm = FALSE, center = NULL, ..., useNames = NA) { + suppressWarnings({ + sigma <- apply(x, MARGIN = 1L, FUN = sd, na.rm = na.rm) + }) + stopifnot(!any(is.infinite(sigma))) + + # Keep naming support consistency same as rowSds() + if (is.null(center) || ncol(x) <= 1L) { + if (is.na(useNames) || isFALSE(useNames)) names(sigma) <- NULL + } + else if (isFALSE(useNames)) names(sigma) <- NULL + sigma + } > > colSds_R <- function(x, na.rm = FALSE, center = NULL, ..., useNames = NA) { + suppressWarnings({ + sigma <- apply(x, MARGIN = 2L, FUN = sd, na.rm = na.rm) + }) + stopifnot(!any(is.infinite(sigma))) + + # Keep naming support consistency same as colSds() + if (is.null(center) || nrow(x) <= 1L) { + if (is.na(useNames) || isFALSE(useNames)) names(sigma) <- NULL + } + else if (isFALSE(useNames)) names(sigma) <- NULL + sigma + } > > > rowSds_center <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, ..., useNames = NA) { + center <- rowWeightedMeans(x, cols = cols, na.rm = na.rm, useNames = FALSE) + sigma <- rowSds(x, rows = rows, cols = cols, center = center, na.rm = na.rm, useNames = useNames) + stopifnot(!any(is.infinite(sigma))) + sigma + } > > colSds_center <- function(x, rows = NULL, cols = NULL, na.rm = FALSE, ..., useNames = NA) { + center <- colWeightedMeans(x, rows = rows, na.rm = na.rm, useNames = FALSE) + sigma <- colSds(x, rows = rows, cols = cols, center = center, na.rm = na.rm, useNames = useNames) + stopifnot(!any(is.infinite(sigma))) + sigma + } > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Subsetted tests > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > source("utils/validateIndicesFramework.R") > x <- matrix(runif(6 * 6, min = -6, max = 6), nrow = 6, ncol = 6) > storage.mode(x) <- "integer" > > # To check names attribute > dimnames <- list(letters[1:6], LETTERS[1:6]) > > # Test with and without dimnames on x > for (setDimnames in c(TRUE, FALSE)) { + if (setDimnames) dimnames(x) <- dimnames + else dimnames(x) <- NULL + + count <- 0L + for (rows in index_cases) { + for (cols in index_cases) { + count <- count + 1L + na.rm <- c(TRUE, FALSE)[count %% 2 + 1] + useNames <- c(if (!matrixStats:::isUseNamesNADefunct()) NA, TRUE, FALSE) + useNames <- useNames[count %% length(useNames) + 1] + + validateIndicesTestMatrix(x, rows, cols, + ftest = rowSds, fsure = rowSds_R, + na.rm = na.rm, useNames = useNames) + validateIndicesTestMatrix(x, rows, cols, + ftest = rowSds_center, fsure = rowSds_R, + na.rm = na.rm, center = TRUE, useNames = useNames) + + validateIndicesTestMatrix(x, rows, cols, + fcoltest = colSds, fsure = rowSds_R, + na.rm = na.rm, useNames = useNames) + validateIndicesTestMatrix(x, rows, cols, + fcoltest = colSds_center, fsure = rowSds_R, + na.rm = na.rm, center = TRUE, useNames = useNames) + } + } + } > > proc.time() user system elapsed 1.28 0.10 1.34