Running ‘allocArray.R’ [0s/1s]
  Running ‘allocMatrix.R’ [0s/1s]
  Running ‘allocVector.R’ [0s/1s]
  Running ‘anyMissing.R’ [0s/1s]
  Running ‘anyMissing_subset.R’ [0s/1s]
  Running ‘benchmark.R’ [14s/19s]
  Running ‘binCounts.R’ [0s/1s]
  Running ‘binCounts_subset.R’ [0s/1s]
  Running ‘binMeans,binCounts.R’ [0s/1s]
  Running ‘binMeans,binCounts_subset.R’ [0s/1s]
  Running ‘count.R’ [0s/1s]
  Running ‘count_subset.R’ [0s/1s]
  Running ‘diff2.R’ [0s/1s]
  Running ‘diff2_subset.R’ [0s/1s]
  Running ‘indexByRow.R’ [0s/1s]
  Running ‘logSumExp.R’ [0s/1s]
  Running ‘logSumExp_subset.R’ [0s/1s]
  Running ‘mean2.R’ [1s/1s]
  Running ‘mean2_subset.R’ [0s/1s]
  Running ‘product.R’ [0s/1s]
  Running ‘product_subset.R’ [0s/1s]
  Running ‘psortKM.R’ [0s/1s]
  Running ‘rowAllAnys.R’ [1s/1s]
  Running ‘rowAllAnys_subset.R’ [5s/6s]
  Running ‘rowAvgsPerColSet.R’ [0s/1s]
  Running ‘rowAvgsPerColSet_subset.R’ [1s/2s]
  Running ‘rowCollapse.R’ [0s/1s]
  Running ‘rowCollapse_subset.R’ [0s/1s]
  Running ‘rowCounts.R’ [1s/1s]
  Running ‘rowCounts_subset.R’ [2s/3s]
  Running ‘rowCumMinMaxs.R’ [1s/1s]
  Running ‘rowCumMinMaxs_subset.R’ [1s/2s]
  Running ‘rowCumprods.R’ [1s/1s]
  Running ‘rowCumprods_subset.R’ [1s/2s]
  Running ‘rowCumsums.R’ [1s/1s]
  Running ‘rowCumsums_subset.R’ [1s/2s]
  Running ‘rowDiffs.R’ [0s/1s]
  Running ‘rowDiffs_subset.R’ [3s/4s]
  Running ‘rowIQRs.R’ [0s/1s]
  Running ‘rowIQRs_subset.R’ [3s/3s]
  Running ‘rowLogSumExps.R’ [0s/1s]
  Running ‘rowLogSumExps_subset.R’ [1s/2s]
  Running ‘rowMads.R’ [1s/1s]
  Running ‘rowMads_subset.R’ [2s/4s]
  Running ‘rowMeans2.R’ [1s/1s]
  Running ‘rowMeans2_subset.R’ [1s/2s]
  Running ‘rowMedians.R’ [1s/2s]
  Running ‘rowMedians_subset.R’ [1s/2s]
  Running ‘rowOrderStats.R’ [1s/1s]
  Running ‘rowOrderStats_subset.R’ [1s/1s]
  Running ‘rowProds.R’ [0s/1s]
  Running ‘rowProds_subset.R’ [1s/2s]
  Running ‘rowQuantiles.R’ [1s/2s]
  Running ‘rowQuantiles_subset.R’ [3s/4s]
  Running ‘rowRanges.R’ [1s/2s]
  Running ‘rowRanges_subset.R’ [3s/5s]
  Running ‘rowRanks.R’ [1s/1s]
  Running ‘rowRanks_subset.R’ [1s/1s]
  Running ‘rowSds.R’ [1s/1s]
  Running ‘rowSds_subset.R’ [3s/6s]
  Running ‘rowSums2.R’ [1s/1s]
  Running ‘rowSums2_subset.R’ [1s/2s]
  Running ‘rowTabulates.R’ [0s/1s]
  Running ‘rowTabulates_subset.R’ [2s/3s]
  Running ‘rowVarDiffs.R’ [1s/1s]
  Running ‘rowVarDiffs_mad,iqr_subset.R’ [10s/13s]
  Running ‘rowVarDiffs_var,sd_subset.R’ [10s/13s]
  Running ‘rowVars.R’ [1s/1s]
  Running ‘rowVars_subset.R’ [3s/4s]
  Running ‘rowWeightedMeans.R’ [0s/1s]
  Running ‘rowWeightedMeans_subset.R’ [2s/3s]
  Running ‘rowWeightedMedians.R’ [0s/1s]
  Running ‘rowWeightedMedians_subset.R’ [2s/2s]
  Running ‘rowWeightedVars.R’ [0s/1s]
  Running ‘rowWeightedVars_subset.R’ [9s/12s]
  Running ‘signTabulate.R’ [0s/1s]
  Running ‘signTabulate_subset.R’ [0s/1s]
  Running ‘sum2.R’ [1s/1s]
Running the tests in ‘tests/sum2.R’ failed.
Complete output:
  > library("matrixStats")
  > options(warn = 1)
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Consistency checks
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > set.seed(1)
  > 
  > sum2_R <- function(x, na.rm = FALSE, idxs = NULL) {
  +   if (is.null(idxs)) {
  +     sum(x, na.rm = na.rm)
  +   } else {
  +     sum(x[idxs], na.rm = na.rm)
  +   }
  + } # sum2_R()
  > 
  > 
  > cat("Consistency checks:\n")
  Consistency checks:
  > for (kk in 1:20) {
  +   cat("Random test #", kk, "\n", sep = "")
  + 
  +   # Simulate data in a matrix of any shape
  +   n <- sample(1e3, size = 1L)
  +   x <- rnorm(n, sd = 100)
  + 
  +   # Add NAs?
  +   if ((kk %% 4) %in% c(3, 0)) {
  +     cat("Adding NAs\n")
  +     nna <- sample(n, size = 1L)
  +     na_values <- c(NA_real_, NaN)
  +     t <- sample(na_values, size = nna, replace = TRUE)
  +     x[sample(length(x), size = nna)] <- t
  +   }
  + 
  +   # Integer or double?
  +   if ((kk %% 4) %in% c(2, 0)) {
  +     cat("Coercing to integers\n")
  +     storage.mode(x) <- "integer"
  +   }
  + 
  +   na.rm <- sample(c(TRUE, FALSE), size = 1L)
  + 
  +   # Sum over all
  +   y0 <- sum2_R(x, na.rm = na.rm)
  +   y1 <- sum2(x, na.rm = na.rm)
  +   stopifnot(all.equal(y1, y0))
  + 
  +   # Sum over subset
  +   nidxs <- sample(n, size = 1L)
  +   idxs <- sample(n, size = nidxs)
  +   y0 <- sum2_R(x, na.rm = na.rm, idxs = idxs)
  +   y1 <- sum2(x, na.rm = na.rm, idxs = idxs)
  +   stopifnot(all.equal(y1, y0))
  + 
  +   if (storage.mode(x) == "integer") {
  +     storage.mode(x) <- "logical"
  +     
  +     y0 <- sum2_R(x, na.rm = na.rm)
  +     y1 <- sum2(x, na.rm = na.rm)
  +     stopifnot(all.equal(y1, y0))
  +     
  +     y0 <- sum2_R(x, na.rm = na.rm, idxs = idxs)
  +     y1 <- sum2(x, na.rm = na.rm, idxs = idxs)
  +     stopifnot(all.equal(y1, y0))
  +   }
  + } # for (kk ...)
  Random test #1
  Random test #2
  Coercing to integers
  Random test #3
  Adding NAs
  Random test #4
  Adding NAs
  Coercing to integers
  Random test #5
  Random test #6
  Coercing to integers
  Random test #7
  Adding NAs
  Random test #8
  Adding NAs
  Coercing to integers
  Random test #9
  Random test #10
  Coercing to integers
  Random test #11
  Adding NAs
  Random test #12
  Adding NAs
  Coercing to integers
  Random test #13
  Random test #14
  Coercing to integers
  Random test #15
  Adding NAs
  Random test #16
  Adding NAs
  Coercing to integers
  Random test #17
  Random test #18
  Coercing to integers
  Random test #19
  Adding NAs
  Random test #20
  Adding NAs
  Coercing to integers
  > 
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # All missing values
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > for (n in 0:2) {
  +   for (na.rm in c(FALSE, TRUE)) {
  +     x <- rep(NA_real_, times = n)
  +     y0 <- sum(x, na.rm = na.rm)
  +     y <- sum2(x, na.rm = na.rm)
  +     stopifnot(all.equal(y, y0))
  + 
  +     x <- rep(NA_integer_, times = n)
  +     y0 <- sum(x, na.rm = na.rm)
  +     y <- sum2(x, na.rm = na.rm)
  +     stopifnot(all.equal(y, y0))
  +     
  +     x <- rep(NA, times = n)
  +     y0 <- sum(x, na.rm = na.rm)
  +     y <- sum2(x, na.rm = na.rm)
  +     stopifnot(all.equal(y, y0))
  +   }
  + }
  > 
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Special cases
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > for (na.rm in c(FALSE, TRUE)) {
  +   # Summing over zero elements (integers)
  +   x <- integer(0)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   stopifnot(identical(s1, s2))
  + 
  +   x <- 1:10
  +   idxs <- integer(0)
  +   s1 <- sum(x[idxs], na.rm = na.rm)
  +   s2 <- sum2(x, idxs = idxs, na.rm = na.rm)
  +   stopifnot(identical(s1, s2))
  + 
  +   # Summing over NA_integer_:s
  +   x <- rep(NA_integer_, times = 10L)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   stopifnot(identical(s1, s2))
  + 
  +   x <- rep(NA_integer_, times = 10L)
  +   idxs <- 1:5
  +   s1 <- sum(x[idxs], na.rm = na.rm)
  +   s2 <- sum2(x, idxs = idxs, na.rm = na.rm)
  +   stopifnot(identical(s1, s2))
  + 
  + 
  +   # Summing over zero elements (doubles)
  +   x <- double(0)
  +   s1 <- sum(x)
  +   s2 <- sum2(x)
  +   stopifnot(
  +     identical(s1, 0),
  +     identical(s1, s2)
  +   )
  + 
  +   x <- as.double(1:10)
  +   idxs <- integer(0)
  +   s1 <- sum(x[idxs])
  +   s2 <- sum2(x, idxs = idxs)
  +   stopifnot(
  +     identical(s1, 0),
  +     identical(s1, s2)
  +   )
  + 
  +   # Summing over NA_real_:s
  +   x <- rep(NA_real_, times = 10L)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   stopifnot(
  +     !na.rm || s1 == 0,
  +     identical(s1, s2)
  +   )
  + 
  +   x <- rep(NA_real_, times = 10L)
  +   idxs <- 1:5
  +   s1 <- sum(x[idxs], na.rm = na.rm)
  +   s2 <- sum2(x, idxs = idxs, na.rm = na.rm)
  +   stopifnot(
  +     !na.rm || s1 == 0,
  +     identical(s1, s2)
  +   )
  + 
  +   # Summing over -Inf:s
  +   x <- rep(-Inf, times = 3L)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   stopifnot(
  +     is.infinite(s1) && s1 < 0,
  +     identical(s1, s2)
  +   )
  + 
  +   # Summing over +Inf:s
  +   x <- rep(+Inf, times = 3L)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   stopifnot(identical(s1, s2))
  +   stopifnot(
  +     is.infinite(s1) && s1 > 0,
  +     identical(s1, s2)
  +   )
  + 
  +   # Summing over mix of -Inf:s and +Inf:s
  +   x <- rep(c(-Inf, +Inf), times = 3L)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   stopifnot(
  +     is.nan(s1),
  +     identical(s1, s2)
  +   )
  + 
  +   # Summing over mix of -Inf:s and +Inf:s and numerics
  +   x <- rep(c(-Inf, +Inf, 3.14), times = 2L)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   stopifnot(
  +     is.nan(s1),
  +     identical(s1, s2)
  +   )
  + 
  +   # Summing over mix of NaN, NA, +Inf, and numerics
  +   x <- c(NaN, NA, +Inf, 3.14)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   if (na.rm) {
  +     stopifnot(
  +       is.infinite(s1) && s1 > 0,
  +       identical(s2, s1)
  +     )
  +   } else {
  +     stopifnot(is.na(s1), is.na(s2))
  +     ## NOTE, due to compiler optimization, it is not guaranteed that NA is
  +     ## returned here (as one would expect). NaN might very well be returned,
  +     ## when both NA and NaN are involved.  This is an accepted feature in R,
  +     ## which is documented in help("is.nan").  See also
  +     ## https://stat.ethz.ch/pipermail/r-devel/2017-April/074009.html.
  +     ## Thus, we cannot guarantee that s1 is identical to s0.
  +   }
  + 
  +   # Summing over mix of NaN, NA, +Inf, and numerics
  +   x <- c(NA, NaN, +Inf, 3.14)
  +   s1 <- sum(x, na.rm = na.rm)
  +   s2 <- sum2(x, na.rm = na.rm)
  +   if (na.rm) {
  +     stopifnot(
  +       is.infinite(s1) && s1 > 0,
  +       identical(s2, s1)
  +     )
  +   } else {
  +     stopifnot(is.na(s1), is.na(s2))
  +     ## NOTE, due to compiler optimization, it is not guaranteed that NA is
  +     ## returned here (as one would expect). NaN might very well be returned,
  +     ## when both NA and NaN are involved.  This is an accepted feature in R,
  +     ## which is documented in help("is.nan").  See also
  +     ## https://stat.ethz.ch/pipermail/r-devel/2017-April/074009.html.
  +     ## Thus, we cannot guarantee that s1 is identical to s0.
  +   }
  + }
  > 
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Summing of large integers
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > x <- c(.Machine$integer.max, 1L, -.Machine$integer.max)
  > 
  > # Total gives integer overflow
  > s1 <- sum(x[1:2])                        # NA_integer_ w/ warning
  > s2 <- sum2(x[1:2])                       # NA_integer_ w/ warning
  Warning in sum2(x[1:2]) :
    Integer overflow. Use sum2(..., mode="numeric") to avoid this.
  > stopifnot(
  +   identical(s1, NA_integer_),
  +   identical(s1, s2)
  + )
  Error: identical(s1, NA_integer_) is not TRUE
  Execution halted