CRAN Package Check Results for Package Matrix

Last updated on 2021-12-02 23:51:12 CET.

Flavor Version Tinstall Tcheck Ttotal Status Flags
r-devel-linux-x86_64-debian-clang 1.3-4 175.27 343.70 518.97 OK
r-devel-linux-x86_64-debian-gcc 1.3-4 135.30 258.80 394.10 OK
r-devel-linux-x86_64-fedora-clang 1.3-4 701.23 OK
r-devel-linux-x86_64-fedora-gcc 1.3-4 677.44 OK
r-devel-windows-x86_64-new-UL 1.3-4 371.00 553.00 924.00 ERROR
r-devel-windows-x86_64-new-TK 1.3-4 ERROR
r-devel-windows-x86_64-old 1.3-4 246.00 335.00 581.00 ERROR
r-patched-linux-x86_64 1.3-4 160.82 335.92 496.74 OK
r-patched-solaris-x86 1.3-4 OK
r-release-linux-x86_64 1.3-4 154.47 337.10 491.57 OK
r-release-macos-arm64 1.3-4 OK
r-release-macos-x86_64 1.3-4 OK
r-release-windows-ix86+x86_64 1.3-4 362.00 630.00 992.00 OK
r-oldrel-macos-x86_64 1.3-4 OK
r-oldrel-windows-ix86+x86_64 1.3-4 324.00 606.00 930.00 OK

Check Details

Version: 1.3-4
Check: whether package can be installed
Result: WARN
    Found the following significant warnings:
     ../../SuiteSparse_config/SuiteSparse_config.h:67:29: warning: ISO C does not support the 'I' printf flag [-Wformat=]
Flavor: r-devel-windows-x86_64-new-UL

Version: 1.3-4
Check: tests
Result: ERROR
     Running 'Class+Meth.R' [4s]
     Running 'Simple.R' [4s]
     Running 'abIndex-tsts.R' [5s]
     Running 'base-matrix-fun.R' [3s]
     Running 'bind.R' [3s]
     Comparing 'bind.Rout' to 'bind.Rout.save' ... OK
     Running 'dg_Matrix.R' [4s]
     Running 'dpo-test.R' [6s]
     Running 'dtpMatrix.R' [3s]
     Running 'factorizing.R' [18s]
     Running 'group-methods.R' [5s]
     Running 'indexing.R' [17s]
     Comparing 'indexing.Rout' to 'indexing.Rout.save' ... OK
     Running 'matprod.R' [12s]
     Running 'matr-exp.R' [3s]
     Running 'other-pkgs.R' [2s]
     Running 'spModel.matrix.R' [4s]
     Running 'validObj.R' [7s]
     Running 'write-read.R' [3s]
    Running the tests in 'tests/Simple.R' failed.
    Complete output:
     > #### Currently a collection of simple tests
     > ## (since 'Matrix' takes long to load, rather have fewer source files!)
     >
     > ##-------- *BEFORE* attaching Matrix: --------------------------------
     > str(Matrix::Matrix)# -> load the namespace
     function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,
     sparse = NULL, doDiag = TRUE, forceCheck = FALSE)
     > T <- new("ngTMatrix", i=0L, j=2L, Dim = c(2L,6L))
     > T
     2 x 6 sparse Matrix of class "ngTMatrix"
    
     [1,] . . | . . .
     [2,] . . . . . .
     > as(T, "CsparseMatrix")
     2 x 6 sparse Matrix of class "ngCMatrix"
    
     [1,] . . | . . .
     [2,] . . . . . .
     > ## gave Error in asMethod(object) : could not find function ".M.classEnv"
     > ## from 0.999375-23 to *-25
     >
     > ## another even shorter version of this:
     > n <- new("dgCMatrix")
     > n
     0 x 0 sparse Matrix of class "dgCMatrix"
     <0 x 0 matrix>
     > ## this:
     > m <- Matrix::Matrix(cbind(1,0,diag(x=2:4)))
     > m
     3 x 5 sparse Matrix of class "dgCMatrix"
    
     [1,] 1 . 2 . .
     [2,] 1 . . 3 .
     [3,] 1 . . . 4
     > mt <- m + table(gl(3,5), gl(5,3))# failed in Matrix <= 1.2.9
     > mt
     3 x 5 sparse Matrix of class "dgCMatrix"
    
     1 2 3 4 5
     1 4 2 2 . .
     2 1 1 3 4 .
     3 1 . . 2 7
     > stopifnot(is(mt, "sparseMatrix"))
     >
     > ##--------------------------------------------------------------------
     >
     > library(Matrix)
     >
     > source(system.file("test-tools.R", package = "Matrix"))# identical3() etc
     Loading required package: tools
     > (doExtras <- doExtras && getRversion() >= "3.4") # so have withAutoprint(.)
     [1] FALSE
     >
     > if(interactive()) {
     + options(error = recover, Matrix.verbose = TRUE, warn = 1)
     + } else options( Matrix.verbose = TRUE, warn = 1)
     > # ^^^^^^ to show Matrix.msg()s
     >
     > ### Matrix() ''smartness''
     > (d40 <- Matrix( diag(4)))
     4 x 4 diagonal matrix of class "ddiMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 1 . . .
     [2,] . 1 . .
     [3,] . . 1 .
     [4,] . . . 1
     > (z4 <- Matrix(0*diag(4)))
     4 x 4 diagonal matrix of class "ddiMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 0 . . .
     [2,] . 0 . .
     [3,] . . 0 .
     [4,] . . . 0
     > (o4 <- Matrix(1+diag(4)))
     4 x 4 Matrix of class "dsyMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 2 1 1 1
     [2,] 1 2 1 1
     [3,] 1 1 2 1
     [4,] 1 1 1 2
     > (tr <- Matrix(cbind(1,0:1)))
     2 x 2 Matrix of class "dtrMatrix"
     [,1] [,2]
     [1,] 1 .
     [2,] 1 1
     > (M4 <- Matrix(m4 <- cbind(0,rbind(6*diag(3),0))))
     4 x 4 sparse Matrix of class "dtCMatrix"
    
     [1,] . 6 . .
     [2,] . . 6 .
     [3,] . . . 6
     [4,] . . . .
     > dM4 <- Matrix(M4, sparse = FALSE)
     > d4. <- diag(4); dimnames(d4.) <- dns <- rep(list(LETTERS[1:4]), 2)
     > d4a <- diag(4); dimnames(d4a) <- dna <- list(LETTERS[1:4], letters[1:4])# "a"symmetric
     > m1a <- matrix(0, dimnames=list("A","b"))# "a"symmetric
     > d4di<- as(d4., "diagonalMatrix")
     > d4da<- as(d4a, "diagonalMatrix")
     > d4d <- as(d4., "denseMatrix")
     > d4aS <- Matrix(d4a, sparse=TRUE, doDiag=FALSE)
     > d1aS <- Matrix(m1a, sparse=TRUE, doDiag=FALSE)
     > stopifnot(exprs = {
     + identical(d4di@x, numeric()) # was "named" unnecessarily
     + identical(dimnames(d4 <- Matrix(d4.)), dns)
     + identical4(d40, Matrix(diag(4)), unname(d4), unname(d4da))
     + identical3(d4, as(d4., "Matrix"), as(d4., "diagonalMatrix"))
     + is(d4aS, "dtCMatrix") # not "dsC*", as asymmetric dimnames
     + is(d4d, "denseMatrix")
     + identical(dimnames(d4T <- as(d4., "TsparseMatrix")), dns) # failed till 2019-09-xx
     + identical(d4T, as(d4., "dgTMatrix"))
     + })
     >
     > class(mN <- Matrix(NA, 3,4)) # NA *is* logical
     [1] "lgeMatrix"
     attr(,"package")
     [1] "Matrix"
     > validObject(Matrix(NA))
     [1] TRUE
     > bd4 <- bdiag(M4,dM4,M4)
     > stopifnotValid(o4, "dsyMatrix")
     > stopifnotValid(M4, "dtCMatrix")
     > stopifnot(validObject(dM4), validObject(mN),
     + identical(bdiag(M4), bdiag(dM4)),
     + identical(bd4@p, c(0L,0:3,3:6,6:9)),
     + identical(bd4@i, c(0:2, 4:6, 8:10)), bd4@x == 6
     + )
     > assert.EQ.mat(dM4, m4)
     > assert.EQ.mat(M4^M4, m4^m4)
     > assert.EQ.mat(mN, matrix(NA, 3,4))
     > assert.EQ.mat(bdiag(diag(4)), diag(4))
     > sL <- Matrix(, 3,4, sparse=TRUE)# -> "lgC"
     > trS <- Matrix(tr, sparse=TRUE)# failed in 0.9975-11
     > stopifnotValid(d4, "diagonalMatrix"); stopifnotValid(z4, "diagonalMatrix")
     > stopifnotValid(tr, "triangularMatrix"); stopifnotValid(trS, "triangularMatrix")
     > stopifnot(all(is.na(sL@x)), ## not yet: all(is.na(sL)),
     + !any(sL, na.rm=TRUE), all(!sL, na.rm=TRUE),
     + validObject(Matrix(c(NA,0), 4, 3, byrow = TRUE)),
     + validObject(Matrix(c(NA,0), 4, 4)))
     > stopifnotValid(Matrix(c(NA,0,0,0), 4, 4), "sparseMatrix")
     > I <- i1 <- I1 <- Diagonal(1)
     > ## TODO? stopifnot(identical(I, Matrix(1, sparse=TRUE))) # doDiag=TRUE default
     > I1[1,1] <- i1[1, ] <- I [ ,1] <- NA
     > stopifnot(identical3(I,i1,I1))
     > image(d4) # gave infinite recursion
     rectangle size 100.9 x 100.9 [pixels]; --> lwd :1
     >
     > ## Steve Walker, Mar 12, 2014:
     > n <- 7
     > (M <- triu(Matrix(seq_len(n^2), n, sparse=TRUE)))
     7 x 7 sparse Matrix of class "dtCMatrix"
    
     [1,] 1 8 15 22 29 36 43
     [2,] . 9 16 23 30 37 44
     [3,] . . 17 24 31 38 45
     [4,] . . . 25 32 39 46
     [5,] . . . . 33 40 47
     [6,] . . . . . 41 48
     [7,] . . . . . . 49
     > im <- image(M) # should be an n-by-n image plot, but is not
     > stopifnot(n == diff(sort(im$y.limits)))
     > ## ylimits were too small (by 1 on each side)
     >
     > assertError( Matrix(factor(letters)) )
     > n.lsec <- length(.leap.seconds)# 27 (2017-07)
     > mlp <- matrix(.leap.seconds)## 27 x 1 numeric matrix
     > Mlp <- Matrix(.leap.seconds)
     > stopifnot(identical(dim(Mlp), c(n.lsec, 1L)))
     > assert.EQ.mat(Mlp, mlp)
     > .Leap.seconds <- as.POSIXlt(.leap.seconds)
     > if(FALSE) { ## TODO -- once R itself does better ...
     + mLp <- matrix(.Leap.seconds)## 11 x 1 list of (Numeric,Int.,Char.) each of length 27 -- yuck!!!
     + MLp <- Matrix(.Leap.seconds)## --> error (for now)
     + }
     >
     > E <- rep(c(TRUE,NA,TRUE), length=8)
     > F <- new("nsparseVector", length = 8L, i = c(2L, 5L, 8L))
     > e <- as(E, "sparseVector"); f <- as(F,"lsparseVector")
     > Fv <- as.vector(F, "any") # failed in Matrix <= 1.2.0, and base::as.vector(.) failed too:
     > stopifnot(E | as.vector(F), identical(E | F, F | E),
     + all(e | f), all(E | F), # <- failed Ops.spv.spv
     + identical(Fv, base::as.vector(F)),
     + is.logical(Fv), which(Fv) == c(2,5,8))
     > F[-8:-1] # was partly "illegal" (length = 0 is ok; nnz '3' is not)
     sparse vector (nnz/length = 0/0) of class "nsparseVector"
     > F.ineg <- lapply(1:8, function(k) F[-8:-k])
     > F.pos <- lapply(1:8, function(k) F[seq_len(k-1)])
     > F.vec <- lapply(1:8, function(k) Fv[seq_len(k-1)])
     > str(F.vec, vec=8)
     List of 8
     $ : logi(0)
     $ : logi FALSE
     $ : logi [1:2] FALSE TRUE
     $ : logi [1:3] FALSE TRUE FALSE
     $ : logi [1:4] FALSE TRUE FALSE FALSE
     $ : logi [1:5] FALSE TRUE FALSE FALSE TRUE
     $ : logi [1:6] FALSE TRUE FALSE FALSE TRUE FALSE
     $ : logi [1:7] FALSE TRUE FALSE FALSE TRUE FALSE FALSE
     > (nT <- vapply(F.vec, sum, 1L)) # == 0 0 1 1 1 2 2 2
     [1] 0 0 1 1 1 2 2 2
     > str(whichT <- lapply(F.vec, which))
     List of 8
     $ : int(0)
     $ : int(0)
     $ : int 2
     $ : int 2
     $ : int 2
     $ : int [1:2] 2 5
     $ : int [1:2] 2 5
     $ : int [1:2] 2 5
     > i.lengths <- function(L) vapply(L, function(.) length(.@i), 1L)
     > stopifnot(identical(lengths(F.vec), 0:7)
     + ,
     + identical(lengths(F.ineg), 0:7)
     + ,
     + identical(lengths(F.pos), 0:7)
     + ,
     + identical(i.lengths(F.pos), nT)
     + ,
     + identical(i.lengths(F.ineg), nT) # failed before 2018-03-19
     + ,
     + identical(lapply(F.pos, slot, "i"), whichT)
     + ,
     + identical(lapply(F.ineg, slot, "i"), whichT) # failed before 2018-03-19
     + )
     > ## Here, sparseVector '[' is really wrong:
     > SV <- new("nsparseVector", length = 30L,
     + i = c(1L, 8L, 9L, 12L, 13L, 18L, 21L, 22L))
     > NI <- -c(1:5, 7:10, 12:16, 18:27, 29,30)
     > sv <- SV[1:14]; ni <- -(1:14)[-c(6,11)] # smaller example
     > selectMethod("[", c("nsparseVector","index","missing","missing"))# the culprit
     Method Definition:
    
     function (x, i, j, ..., drop = TRUE)
     {
     has.x <- .hasSlot(x, "x")
     n <- x@length
     if (extends(cl.i <- getClass(class(i)), "numeric") && any(i <
     0)) {
     if (any(i > 0))
     stop("you cannot mix negative and positive indices")
     if (any(z <- i == 0))
     i <- i[!z]
     i <- unique(sort(-i))
     nom <- is.na(m <- match(x@i, i))
     x@i <- x@i[nom]
     if (has.x)
     x@x <- x@x[nom]
     x@i <- x@i - findInterval(x@i, i)
     x@length <- n - length(i)
     }
     else {
     ii <- intIv(i, n, cl.i = cl.i)
     m <- match(x@i, ii, nomatch = 0)
     sel <- m > 0L
     x@length <- length(ii)
     x@i <- m[sel]
     if (any(iDup <- duplicated(ii))) {
     i.i <- match(ii[iDup], ii)
     jm <- lapply(i.i, function(.) which(. == m))
     if (has.x)
     sel <- c(which(sel), unlist(jm))
     x@i <- c(x@i, rep.int(which(iDup), lengths(jm)))
     }
     if (has.x)
     x@x <- x@x[sel]
     }
     x
     }
     <bytecode: 0x0000000011b39aa8>
     <environment: namespace:Matrix>
    
     Signatures:
     x i j drop
     target "nsparseVector" "index" "missing" "missing"
     defined "sparseVector" "index" "ANY" "ANY"
     > if(FALSE)
     + trace("[", browser, signature=c("nsparseVector","index","missing","missing"))
     > stopifnot(
     + SV[NI] == as.vector(SV)[NI] ## badly failed before 2018-03-19
     + ,
     + sv[ni] == as.vector(sv)[ni] ## ditto
     + )
     > if(FALSE)
     + untrace("[", signature=c("nsparseVector","index","missing","missing"))
     >
     > dT <- new("dgTMatrix",
     + i = c(1:2,1:2), j=rep(1:2, each=2), Dim = c(4L, 4L), x = c(1, 1, NA, 2))
     > dt <- new("dtTMatrix", i = 0:3, j = 0:3, Dim = c(4L, 4L), x = c(1,0,0,0),
     + uplo = "U", diag = "N")
     > c1 <- as(dT, "CsparseMatrix")
     > c2 <- as(dt, "CsparseMatrix")
     > isValid(lc <- c1 > c2,"lgCMatrix")
     [1] TRUE
     > isValid(lt <- dT > dt,"lgCMatrix")
     [1] TRUE
     > stopifnot(identical(lc,lt))
     >
     > ## Versions of Diagonal()
     > dD <- Diagonal(x = 5:1)
     > sD <- .symDiagonal(5, 5:1)
     > tD <- .trDiagonal (5, 5:1) # x=<integer> had failed for both
     > stopifnot(all(sD == dD)
     + , all(tD == dD)
     + , identical(sD, .symDiagonal(x = 5:1))
     + , identical(tD, .sparseDiagonal(x=5:1))
     + , identical(tD, .trDiagonal (x = 5:1)))# 'n' now has default
     >
     > M <- Diagonal(4); M[1,2] <- 2 ; M
     4 x 4 sparse Matrix of class "dtCMatrix" (unitriangular)
    
     [1,] I 2 . .
     [2,] . I . .
     [3,] . . I .
     [4,] . . . I
     > cM <- crossprod(M) # >> as_cholmod_l_triplet(): could not reallocate for internal diagU2N()
     > stopifnot(identical(cM, tcrossprod(t(M))))
     >
     > S.na <- spMatrix(3, 4, c(1,2,3), c(2,3,3), c(NA,1,0))
     > (S.na <- S.na - 2 * S.na)
     3 x 4 sparse Matrix of class "dgCMatrix"
    
     [1,] . NA . .
     [2,] . . -1 .
     [3,] . . 0 .
     > (L <- S.na != 0)
     3 x 4 sparse Matrix of class "lgCMatrix"
    
     [1,] . N . .
     [2,] . . | .
     [3,] . . : .
     >
     > (Ln0 <- S.na != rep(0, prod(dim(L))))
     3 x 4 sparse Matrix of class "lgCMatrix"
    
     [1,] . N . .
     [2,] . . | .
     [3,] . . . .
     > .Lm0 <- S.na != Matrix(0, 3, 4)
     > stopifnot(Q.eq(L, Ln0), identical(Ln0, .Lm0)); rm(Ln0, .Lm0)
     >
     >
     > ### Unit-diagonal and unitriangular {methods need diagU2N() or similar}
     > I <- Diagonal(3)
     > (T <- as(I,"TsparseMatrix")) # unitriangular
     3 x 3 sparse Matrix of class "dtTMatrix" (unitriangular)
    
     [1,] I . .
     [2,] . I .
     [3,] . . I
     > (C <- as(I,"CsparseMatrix")) # (ditto)
     3 x 3 sparse Matrix of class "dtCMatrix" (unitriangular)
    
     [1,] I . .
     [2,] . I .
     [3,] . . I
     > lT <- as(T,"lMatrix")
     > lC <- as(C,"lMatrix")
     > stopifnot(
     + identical((n0 <- I != 0), Diagonal(3, TRUE)), I@diag == "U",
     + identical(n0, I & TRUE), identical(n0, I | FALSE),
     + identical(n0, TRUE & I), identical(n0, FALSE | I),
     + all(n0 == !(I == 0)), all(I == n0), identical(n0 == I, I == n0)
     + ,
     + identical4(lT, as(Diagonal(3, x=TRUE),"TsparseMatrix"), T & TRUE, TRUE & T),
     + identical4(lC, as(Diagonal(3, x=TRUE),"CsparseMatrix"), C & TRUE, TRUE & C),
     + identical3(lT, T | FALSE, FALSE | T),
     + identical3(lC, C | FALSE, FALSE | C),
     + TRUE)
     > I[,1] <- NA; I[2,2] <- NA ; I[3,] <- NaN
     > stopifnotValid(I, "sparseMatrix")
     > I # gave error in printSpMatrix() - because of R bug in format.info()
     3 x 3 sparse Matrix of class "dtCMatrix"
    
     [1,] NA . .
     [2,] NA NA .
     [3,] NaN NaN NaN
     >
     > L <- spMatrix(9, 30, i = rep(1:9, 3), 1:27, (1:27) %% 4 != 1)
     > M <- drop0(crossprod(L))
     > diag(M) <- diag(M) + 5 # to make it pos.def.
     > M. <- M[1:12,1:12] # small ex
     > N3 <- as(Matrix(upper.tri(diag(3))), "nMatrix")
     > stopifnotValid(bdN <- bdiag(N3, N3),"nsparseMatrix")
     >
     > stopifnot(identical(L, L == TRUE), ## used to give infinite recursion
     + all(drop0((0 - L) != 0) == drop0(L)))
     > L[sample(length(L), 10)] <- NA
     diagnosing replTmat(x,i,j,v): nargs()= 3; missing (i,j) = (0,1)
     > ll <- as(L,"logical")
     > stopifnot(all.equal(mean(L, na.rm=TRUE),
     + mean(ll, na.rm=TRUE), tol= 1e-14),
     + all.equal(mean(L, na.rm=TRUE, trim=1/4),# <- with a warning
     + mean(ll, na.rm=TRUE, trim=1/4), tol= 1e-14))
     Warning in .local(x, ...) :
     trimmed mean of 'sparseVector' -- suboptimally using as.numeric(.)
     >
     >
     > ## Examples where is.na(.) was wrong:
     > validObject(sc <- new("dsCMatrix", i=as.integer(c(0,0:1,1:2,0:1,3)), Dim=c(4L,4L),
     + p = c(0L,1L,3L,5L,8L), x = c(0,NA,NA,0:1,0,NA,1)))
     [1] TRUE
     > validObject(gc <- as(sc, "generalMatrix"))
     [1] TRUE
     >
     > stopifnot(isSymmetric(M), isSymmetric(M.),
     + is(bdiag(M., M.),"symmetricMatrix"),
     + is(bdN, "triangularMatrix"),
     + all(sc == gc | (is.na(sc) & is.na(gc))),
     + all.equal(N3,N3),
     + tail(all.equal(N3, t(N3)), 1) == all.equal(1,-1),# ~= "Mean relative difference: 2"
     + all((bdN != t(bdN)) == (bdN + t(bdN))), # <nsparse> != <nsparse> failed to work...
     + !any((0+bdN) > bdN), # <dsparse> o <nsparse>
     + !any(bdN != (0+bdN)), # <nsparse> o <dsparse>
     + length(grep("Length", all.equal(M., (vM <- as.vector(M.))))) > 0,
     + identical(M., (M2 <- Matrix(vM, 12,12))),
     + all.equal(M., M2, tolerance =0)
     + )
     >
     > Filter(function(.) inherits(get(.), "symmetricMatrix"), ls())
     [1] "M" "M." "M2" "cM" "d4d" "o4" "sD" "sc"
     > ## [1] "cM" "M" "M." "M2" "o4" "sc"
     > tt <- as(kronecker(cM, Diagonal(x = c(10,1))), "symmetricMatrix")
     > dimnames(tt) <- list(NULL, cn <- letters[1:ncol(tt)])
     > stopifnotValid(tt, "dsTMatrix")
     > (cc <- as(tt, "CsparseMatrix")) # shows *symmetric* dimnames
     8 x 8 sparse Matrix of class "dsCMatrix"
     a b c d e f g h
     a 10 . 20 . . . . .
     b . 1 . 2 . . . .
     c 20 . 50 . . . . .
     d . 2 . 5 . . . .
     e . . . . 10 . . .
     f . . . . . 1 . .
     g . . . . . . 10 .
     h . . . . . . . 1
     > stopifnot(identical3( cc @Dimnames, tt @Dimnames, list(NULL, cn)),
     + identical3(t(cc)@Dimnames, t(tt)@Dimnames, list(cn, NULL)),
     + identical3(dimnames(cc), dimnames(tt), list(cn, cn)))# now symmetric !
     >
     > stopifnot(identical3(dimnames(cc),
     + dimnames(as(cc, "generalMatrix")), ## should fixup dimnames to *symmetric*
     + dimnames(as(tt, "generalMatrix"))))
     > ## --> .Call(Csparse_symmetric_to_general, from)
     >
     > mat <- as(cc, "matrix") ## --> should fixup dimnames to *symmetric*
     > mat # should print *symmetric* dimnames
     a b c d e f g h
     a 10 0 20 0 0 0 0 0
     b 0 1 0 2 0 0 0 0
     c 20 0 50 0 0 0 0 0
     d 0 2 0 5 0 0 0 0
     e 0 0 0 0 10 0 0 0
     f 0 0 0 0 0 1 0 0
     g 0 0 0 0 0 0 10 0
     h 0 0 0 0 0 0 0 1
     > stopifnot(identical3(dimnames(cc), dimnames(mat), dimnames(as(tt, "matrix"))))
     >
     > selectMethod(coerce, c("dsCMatrix", "denseMatrix"))
     Method Definition:
    
     function (from, to = "denseMatrix", strict = TRUE)
     .Call(Csparse_to_dense, from, 1L)
     <bytecode: 0x0000000013a486d0>
     <environment: namespace:Matrix>
    
     Signatures:
     from to
     target "dsCMatrix" "denseMatrix"
     defined "dsCMatrix" "denseMatrix"
     > dmat <- as(cc, "denseMatrix") ## --> gave Error (!!) in Matrix 1.1-5
     > stopifnot(identical3(tt@Dimnames, dmat@Dimnames, list(NULL, cn)))
     > dmat # should print *symmetric* dimnames (not modifying dmat as it did intermittently)
     8 x 8 Matrix of class "dsyMatrix"
     a b c d e f g h
     a 10 0 20 0 0 0 0 0
     b 0 1 0 2 0 0 0 0
     c 20 0 50 0 0 0 0 0
     d 0 2 0 5 0 0 0 0
     e 0 0 0 0 10 0 0 0
     f 0 0 0 0 0 1 0 0
     g 0 0 0 0 0 0 10 0
     h 0 0 0 0 0 0 0 1
     > stopifnot(identical(dmat@Dimnames, list(NULL, cn)))
     > ttdm <- as(tt, "denseMatrix")
     > stopifnot(all.equal(dmat, ttdm),
     + ## ^^^^^^ not identical(): 'x' slot differs, as only "U" is needed
     + identical(as(dmat, "dspMatrix"), as(ttdm, "dspMatrix")),
     + identical(dimnames(cc), dimnames(dmat)),
     + ## coercing back should give original :
     + identical(cc, as(dmat, "sparseMatrix")),
     + identical(uniqTsparse(tt), as(ttdm, "TsparseMatrix")))
     >
     > ## MM: now *if* cc is "truly symmetric", these dimnames should be, too:
     > d5 <- cn[1:5]; dnm5 <- list(d5,d5)
     > stopifnot(identical(dimnames( cc [1:5, 1:5]), dnm5),
     + identical(dimnames(t(cc)[1:5, 1:5]), dnm5))
     >
     >
     > ## large sparse ones: these now directly "go sparse":
     > str(m0 <- Matrix(0, nrow=100, ncol = 1000))
     Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
     ..@ i : int(0)
     ..@ p : int [1:1001] 0 0 0 0 0 0 0 0 0 0 ...
     ..@ Dim : int [1:2] 100 1000
     ..@ Dimnames:List of 2
     .. ..$ : NULL
     .. ..$ : NULL
     ..@ x : num(0)
     ..@ factors : list()
     > str(l0 <- Matrix(FALSE, nrow=100, ncol = 200))
     Formal class 'lgCMatrix' [package "Matrix"] with 6 slots
     ..@ i : int(0)
     ..@ p : int [1:201] 0 0 0 0 0 0 0 0 0 0 ...
     ..@ Dim : int [1:2] 100 200
     ..@ Dimnames:List of 2
     .. ..$ : NULL
     .. ..$ : NULL
     ..@ x : logi(0)
     ..@ factors : list()
     > stopifnot(all(!l0),
     + identical(FALSE, any(l0)))
     >
     > if(!interactive()) warnings()
     > ## really large {length(<dense equivalent>) is beyond R's limits}:
     > op <- options(warn = 2) # warnings (e.g. integer overflow!) become errors:
     > n <- 50000L
     > stopifnot(n^2 > .Machine$integer.max)
     > ## had integer overflow in index constructions:
     > x <- 1:n
     > D <- Diagonal(n, x=x[n:1])
     > summary(D)# special method
     50000 x 50000 diagonal Matrix of class "ddiMatrix"
     Min. 1st Qu. Median Mean 3rd Qu. Max.
     1 12501 25001 25001 37500 50000
     > summary(D != 0)
     50000 x 50000 diagonal Matrix of class "ldiMatrix"
     Mode TRUE
     logical 50000
     > stopifnot(identical(x*D, (Dx <- D*x)),
     + identical(D != 0, as(D, "lMatrix")),
     + identical(Dx, local({d <- D; d@x <- d@x * x; d})))
     >
     > Lrg <- new("dgTMatrix", Dim = c(n,n))
     > l0 <- as(as(Lrg, "lMatrix"), "lgCMatrix")
     > d0 <- as(l0, "dgCMatrix")
     >
     > if(FALSE) { #_____________________ FIXME: Should use cholmod_l_*() everywhere (?)____
     + ## problem in Csparse_to_dense :
     + dl0 <- as(l0, "denseMatrix")
     + dd0 <- as(d0, "denseMatrix")
     + ## currently, both give --- Error in asMethod(object) :
     + ## Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
     + ##--> And there it is 'Int_max' ==> ../src/CHOLMOD/Include/cholmod_internal.h
     + ## defines 'Int_max' and does that depending of "mode", and
     + ## MM thinks we should use the "DLONG" mode now -- for 64-bit integers!
     + ## ==> Then Int_max := SuiteSparse_long_max := LONG_MAX
     + ## (the latter from ../src/SuiteSparse_config/SuiteSparse_config.h )
     + ## ==> use cholmod_l_<foo> instead of cholmod_<foo> in *many places*
     + ##
     + ## check they are ok
     + stopifnot(identical(dim(dl0), c(n,n)), identical(dim(dd0), c(n,n)),
     + !any(dl0), all(dd0 == 0))
     + rm(dl0, dd0)# too large to keep in memory and pass to checkMatrix()
     + }
     >
     > diag(Lrg[2:9,1:8]) <- 1:8
     > ## ==: Lrg[2:9,1:8] <- `diag<-`(Lrg[2:9,1:8], 1:8)
     > e1 <- try(Lrg == Lrg) # ==> Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
     Error in asMethod(object) :
     Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 102
     > ## (error message almost ok)
     >
     > (memGB <- Sys.memGB("MemFree")) # from test-tools-1.R
     Error: (converted from warning) 'memory.limit()' is no longer supported
     Execution halted
Flavor: r-devel-windows-x86_64-new-UL

Version: 1.3-4
Check: tests
Result: ERROR
     Running 'Class+Meth.R'
     Running 'Simple.R'
    Running the tests in 'tests/Simple.R' failed.
    Complete output:
     > #### Currently a collection of simple tests
     > ## (since 'Matrix' takes long to load, rather have fewer source files!)
     >
     > ##-------- *BEFORE* attaching Matrix: --------------------------------
     > str(Matrix::Matrix)# -> load the namespace
     function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,
     sparse = NULL, doDiag = TRUE, forceCheck = FALSE)
     > T <- new("ngTMatrix", i=0L, j=2L, Dim = c(2L,6L))
     > T
     2 x 6 sparse Matrix of class "ngTMatrix"
    
     [1,] . . | . . .
     [2,] . . . . . .
     > as(T, "CsparseMatrix")
     2 x 6 sparse Matrix of class "ngCMatrix"
    
     [1,] . . | . . .
     [2,] . . . . . .
     > ## gave Error in asMethod(object) : could not find function ".M.classEnv"
     > ## from 0.999375-23 to *-25
     >
     > ## another even shorter version of this:
     > n <- new("dgCMatrix")
     > n
     0 x 0 sparse Matrix of class "dgCMatrix"
     <0 x 0 matrix>
     > ## this:
     > m <- Matrix::Matrix(cbind(1,0,diag(x=2:4)))
     > m
     3 x 5 sparse Matrix of class "dgCMatrix"
    
     [1,] 1 . 2 . .
     [2,] 1 . . 3 .
     [3,] 1 . . . 4
     > mt <- m + table(gl(3,5), gl(5,3))# failed in Matrix <= 1.2.9
     > mt
     3 x 5 sparse Matrix of class "dgCMatrix"
    
     1 2 3 4 5
     1 4 2 2 . .
     2 1 1 3 4 .
     3 1 . . 2 7
     > stopifnot(is(mt, "sparseMatrix"))
     >
     > ##--------------------------------------------------------------------
     >
     > library(Matrix)
     >
     > source(system.file("test-tools.R", package = "Matrix"))# identical3() etc
     Loading required package: tools
     > (doExtras <- doExtras && getRversion() >= "3.4") # so have withAutoprint(.)
     [1] FALSE
     >
     > if(interactive()) {
     + options(error = recover, Matrix.verbose = TRUE, warn = 1)
     + } else options( Matrix.verbose = TRUE, warn = 1)
     > # ^^^^^^ to show Matrix.msg()s
     >
     > ### Matrix() ''smartness''
     > (d40 <- Matrix( diag(4)))
     4 x 4 diagonal matrix of class "ddiMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 1 . . .
     [2,] . 1 . .
     [3,] . . 1 .
     [4,] . . . 1
     > (z4 <- Matrix(0*diag(4)))
     4 x 4 diagonal matrix of class "ddiMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 0 . . .
     [2,] . 0 . .
     [3,] . . 0 .
     [4,] . . . 0
     > (o4 <- Matrix(1+diag(4)))
     4 x 4 Matrix of class "dsyMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 2 1 1 1
     [2,] 1 2 1 1
     [3,] 1 1 2 1
     [4,] 1 1 1 2
     > (tr <- Matrix(cbind(1,0:1)))
     2 x 2 Matrix of class "dtrMatrix"
     [,1] [,2]
     [1,] 1 .
     [2,] 1 1
     > (M4 <- Matrix(m4 <- cbind(0,rbind(6*diag(3),0))))
     4 x 4 sparse Matrix of class "dtCMatrix"
    
     [1,] . 6 . .
     [2,] . . 6 .
     [3,] . . . 6
     [4,] . . . .
     > dM4 <- Matrix(M4, sparse = FALSE)
     > d4. <- diag(4); dimnames(d4.) <- dns <- rep(list(LETTERS[1:4]), 2)
     > d4a <- diag(4); dimnames(d4a) <- dna <- list(LETTERS[1:4], letters[1:4])# "a"symmetric
     > m1a <- matrix(0, dimnames=list("A","b"))# "a"symmetric
     > d4di<- as(d4., "diagonalMatrix")
     > d4da<- as(d4a, "diagonalMatrix")
     > d4d <- as(d4., "denseMatrix")
     > d4aS <- Matrix(d4a, sparse=TRUE, doDiag=FALSE)
     > d1aS <- Matrix(m1a, sparse=TRUE, doDiag=FALSE)
     > stopifnot(exprs = {
     + identical(d4di@x, numeric()) # was "named" unnecessarily
     + identical(dimnames(d4 <- Matrix(d4.)), dns)
     + identical4(d40, Matrix(diag(4)), unname(d4), unname(d4da))
     + identical3(d4, as(d4., "Matrix"), as(d4., "diagonalMatrix"))
     + is(d4aS, "dtCMatrix") # not "dsC*", as asymmetric dimnames
     + is(d4d, "denseMatrix")
     + identical(dimnames(d4T <- as(d4., "TsparseMatrix")), dns) # failed till 2019-09-xx
     + identical(d4T, as(d4., "dgTMatrix"))
     + })
     >
     > class(mN <- Matrix(NA, 3,4)) # NA *is* logical
     [1] "lgeMatrix"
     attr(,"package")
     [1] "Matrix"
     > validObject(Matrix(NA))
     [1] TRUE
     > bd4 <- bdiag(M4,dM4,M4)
     > stopifnotValid(o4, "dsyMatrix")
     > stopifnotValid(M4, "dtCMatrix")
     > stopifnot(validObject(dM4), validObject(mN),
     + identical(bdiag(M4), bdiag(dM4)),
     + identical(bd4@p, c(0L,0:3,3:6,6:9)),
     + identical(bd4@i, c(0:2, 4:6, 8:10)), bd4@x == 6
     + )
     > assert.EQ.mat(dM4, m4)
     > assert.EQ.mat(M4^M4, m4^m4)
     > assert.EQ.mat(mN, matrix(NA, 3,4))
     > assert.EQ.mat(bdiag(diag(4)), diag(4))
     > sL <- Matrix(, 3,4, sparse=TRUE)# -> "lgC"
     > trS <- Matrix(tr, sparse=TRUE)# failed in 0.9975-11
     > stopifnotValid(d4, "diagonalMatrix"); stopifnotValid(z4, "diagonalMatrix")
     > stopifnotValid(tr, "triangularMatrix"); stopifnotValid(trS, "triangularMatrix")
     > stopifnot(all(is.na(sL@x)), ## not yet: all(is.na(sL)),
     + !any(sL, na.rm=TRUE), all(!sL, na.rm=TRUE),
     + validObject(Matrix(c(NA,0), 4, 3, byrow = TRUE)),
     + validObject(Matrix(c(NA,0), 4, 4)))
     > stopifnotValid(Matrix(c(NA,0,0,0), 4, 4), "sparseMatrix")
     > I <- i1 <- I1 <- Diagonal(1)
     > ## TODO? stopifnot(identical(I, Matrix(1, sparse=TRUE))) # doDiag=TRUE default
     > I1[1,1] <- i1[1, ] <- I [ ,1] <- NA
     > stopifnot(identical3(I,i1,I1))
     > image(d4) # gave infinite recursion
     rectangle size 100.9 x 100.9 [pixels]; --> lwd :1
     >
     > ## Steve Walker, Mar 12, 2014:
     > n <- 7
     > (M <- triu(Matrix(seq_len(n^2), n, sparse=TRUE)))
     7 x 7 sparse Matrix of class "dtCMatrix"
    
     [1,] 1 8 15 22 29 36 43
     [2,] . 9 16 23 30 37 44
     [3,] . . 17 24 31 38 45
     [4,] . . . 25 32 39 46
     [5,] . . . . 33 40 47
     [6,] . . . . . 41 48
     [7,] . . . . . . 49
     > im <- image(M) # should be an n-by-n image plot, but is not
     > stopifnot(n == diff(sort(im$y.limits)))
     > ## ylimits were too small (by 1 on each side)
     >
     > assertError( Matrix(factor(letters)) )
     > n.lsec <- length(.leap.seconds)# 27 (2017-07)
     > mlp <- matrix(.leap.seconds)## 27 x 1 numeric matrix
     > Mlp <- Matrix(.leap.seconds)
     > stopifnot(identical(dim(Mlp), c(n.lsec, 1L)))
     > assert.EQ.mat(Mlp, mlp)
     > .Leap.seconds <- as.POSIXlt(.leap.seconds)
     > if(FALSE) { ## TODO -- once R itself does better ...
     + mLp <- matrix(.Leap.seconds)## 11 x 1 list of (Numeric,Int.,Char.) each of length 27 -- yuck!!!
     + MLp <- Matrix(.Leap.seconds)## --> error (for now)
     + }
     >
     > E <- rep(c(TRUE,NA,TRUE), length=8)
     > F <- new("nsparseVector", length = 8L, i = c(2L, 5L, 8L))
     > e <- as(E, "sparseVector"); f <- as(F,"lsparseVector")
     > Fv <- as.vector(F, "any") # failed in Matrix <= 1.2.0, and base::as.vector(.) failed too:
     > stopifnot(E | as.vector(F), identical(E | F, F | E),
     + all(e | f), all(E | F), # <- failed Ops.spv.spv
     + identical(Fv, base::as.vector(F)),
     + is.logical(Fv), which(Fv) == c(2,5,8))
     > F[-8:-1] # was partly "illegal" (length = 0 is ok; nnz '3' is not)
     sparse vector (nnz/length = 0/0) of class "nsparseVector"
     > F.ineg <- lapply(1:8, function(k) F[-8:-k])
     > F.pos <- lapply(1:8, function(k) F[seq_len(k-1)])
     > F.vec <- lapply(1:8, function(k) Fv[seq_len(k-1)])
     > str(F.vec, vec=8)
     List of 8
     $ : logi(0)
     $ : logi FALSE
     $ : logi [1:2] FALSE TRUE
     $ : logi [1:3] FALSE TRUE FALSE
     $ : logi [1:4] FALSE TRUE FALSE FALSE
     $ : logi [1:5] FALSE TRUE FALSE FALSE TRUE
     $ : logi [1:6] FALSE TRUE FALSE FALSE TRUE FALSE
     $ : logi [1:7] FALSE TRUE FALSE FALSE TRUE FALSE FALSE
     > (nT <- vapply(F.vec, sum, 1L)) # == 0 0 1 1 1 2 2 2
     [1] 0 0 1 1 1 2 2 2
     > str(whichT <- lapply(F.vec, which))
     List of 8
     $ : int(0)
     $ : int(0)
     $ : int 2
     $ : int 2
     $ : int 2
     $ : int [1:2] 2 5
     $ : int [1:2] 2 5
     $ : int [1:2] 2 5
     > i.lengths <- function(L) vapply(L, function(.) length(.@i), 1L)
     > stopifnot(identical(lengths(F.vec), 0:7)
     + ,
     + identical(lengths(F.ineg), 0:7)
     + ,
     + identical(lengths(F.pos), 0:7)
     + ,
     + identical(i.lengths(F.pos), nT)
     + ,
     + identical(i.lengths(F.ineg), nT) # failed before 2018-03-19
     + ,
     + identical(lapply(F.pos, slot, "i"), whichT)
     + ,
     + identical(lapply(F.ineg, slot, "i"), whichT) # failed before 2018-03-19
     + )
     > ## Here, sparseVector '[' is really wrong:
     > SV <- new("nsparseVector", length = 30L,
     + i = c(1L, 8L, 9L, 12L, 13L, 18L, 21L, 22L))
     > NI <- -c(1:5, 7:10, 12:16, 18:27, 29,30)
     > sv <- SV[1:14]; ni <- -(1:14)[-c(6,11)] # smaller example
     > selectMethod("[", c("nsparseVector","index","missing","missing"))# the culprit
     Method Definition:
    
     function (x, i, j, ..., drop = TRUE)
     {
     has.x <- .hasSlot(x, "x")
     n <- x@length
     if (extends(cl.i <- getClass(class(i)), "numeric") && any(i <
     0)) {
     if (any(i > 0))
     stop("you cannot mix negative and positive indices")
     if (any(z <- i == 0))
     i <- i[!z]
     i <- unique(sort(-i))
     nom <- is.na(m <- match(x@i, i))
     x@i <- x@i[nom]
     if (has.x)
     x@x <- x@x[nom]
     x@i <- x@i - findInterval(x@i, i)
     x@length <- n - length(i)
     }
     else {
     ii <- intIv(i, n, cl.i = cl.i)
     m <- match(x@i, ii, nomatch = 0)
     sel <- m > 0L
     x@length <- length(ii)
     x@i <- m[sel]
     if (any(iDup <- duplicated(ii))) {
     i.i <- match(ii[iDup], ii)
     jm <- lapply(i.i, function(.) which(. == m))
     if (has.x)
     sel <- c(which(sel), unlist(jm))
     x@i <- c(x@i, rep.int(which(iDup), lengths(jm)))
     }
     if (has.x)
     x@x <- x@x[sel]
     }
     x
     }
     <bytecode: 0x000000001436eb58>
     <environment: namespace:Matrix>
    
     Signatures:
     x i j drop
     target "nsparseVector" "index" "missing" "missing"
     defined "sparseVector" "index" "ANY" "ANY"
     > if(FALSE)
     + trace("[", browser, signature=c("nsparseVector","index","missing","missing"))
     > stopifnot(
     + SV[NI] == as.vector(SV)[NI] ## badly failed before 2018-03-19
     + ,
     + sv[ni] == as.vector(sv)[ni] ## ditto
     + )
     > if(FALSE)
     + untrace("[", signature=c("nsparseVector","index","missing","missing"))
     >
     > dT <- new("dgTMatrix",
     + i = c(1:2,1:2), j=rep(1:2, each=2), Dim = c(4L, 4L), x = c(1, 1, NA, 2))
     > dt <- new("dtTMatrix", i = 0:3, j = 0:3, Dim = c(4L, 4L), x = c(1,0,0,0),
     + uplo = "U", diag = "N")
     > c1 <- as(dT, "CsparseMatrix")
     > c2 <- as(dt, "CsparseMatrix")
     > isValid(lc <- c1 > c2,"lgCMatrix")
     [1] TRUE
     > isValid(lt <- dT > dt,"lgCMatrix")
     [1] TRUE
     > stopifnot(identical(lc,lt))
     >
     > ## Versions of Diagonal()
     > dD <- Diagonal(x = 5:1)
     > sD <- .symDiagonal(5, 5:1)
     > tD <- .trDiagonal (5, 5:1) # x=<integer> had failed for both
     > stopifnot(all(sD == dD)
     + , all(tD == dD)
     + , identical(sD, .symDiagonal(x = 5:1))
     + , identical(tD, .sparseDiagonal(x=5:1))
     + , identical(tD, .trDiagonal (x = 5:1)))# 'n' now has default
     >
     > M <- Diagonal(4); M[1,2] <- 2 ; M
     4 x 4 sparse Matrix of class "dtCMatrix" (unitriangular)
    
     [1,] I 2 . .
     [2,] . I . .
     [3,] . . I .
     [4,] . . . I
     > cM <- crossprod(M) # >> as_cholmod_l_triplet(): could not reallocate for internal diagU2N()
     > stopifnot(identical(cM, tcrossprod(t(M))))
     >
     > S.na <- spMatrix(3, 4, c(1,2,3), c(2,3,3), c(NA,1,0))
     > (S.na <- S.na - 2 * S.na)
     3 x 4 sparse Matrix of class "dgCMatrix"
    
     [1,] . NA . .
     [2,] . . -1 .
     [3,] . . 0 .
     > (L <- S.na != 0)
     3 x 4 sparse Matrix of class "lgCMatrix"
    
     [1,] . N . .
     [2,] . . | .
     [3,] . . : .
     >
     > (Ln0 <- S.na != rep(0, prod(dim(L))))
     3 x 4 sparse Matrix of class "lgCMatrix"
    
     [1,] . N . .
     [2,] . . | .
     [3,] . . . .
     > .Lm0 <- S.na != Matrix(0, 3, 4)
     > stopifnot(Q.eq(L, Ln0), identical(Ln0, .Lm0)); rm(Ln0, .Lm0)
     >
     >
     > ### Unit-diagonal and unitriangular {methods need diagU2N() or similar}
     > I <- Diagonal(3)
     > (T <- as(I,"TsparseMatrix")) # unitriangular
     3 x 3 sparse Matrix of class "dtTMatrix" (unitriangular)
    
     [1,] I . .
     [2,] . I .
     [3,] . . I
     > (C <- as(I,"CsparseMatrix")) # (ditto)
     3 x 3 sparse Matrix of class "dtCMatrix" (unitriangular)
    
     [1,] I . .
     [2,] . I .
     [3,] . . I
     > lT <- as(T,"lMatrix")
     > lC <- as(C,"lMatrix")
     > stopifnot(
     + identical((n0 <- I != 0), Diagonal(3, TRUE)), I@diag == "U",
     + identical(n0, I & TRUE), identical(n0, I | FALSE),
     + identical(n0, TRUE & I), identical(n0, FALSE | I),
     + all(n0 == !(I == 0)), all(I == n0), identical(n0 == I, I == n0)
     + ,
     + identical4(lT, as(Diagonal(3, x=TRUE),"TsparseMatrix"), T & TRUE, TRUE & T),
     + identical4(lC, as(Diagonal(3, x=TRUE),"CsparseMatrix"), C & TRUE, TRUE & C),
     + identical3(lT, T | FALSE, FALSE | T),
     + identical3(lC, C | FALSE, FALSE | C),
     + TRUE)
     > I[,1] <- NA; I[2,2] <- NA ; I[3,] <- NaN
     > stopifnotValid(I, "sparseMatrix")
     > I # gave error in printSpMatrix() - because of R bug in format.info()
     3 x 3 sparse Matrix of class "dtCMatrix"
    
     [1,] NA . .
     [2,] NA NA .
     [3,] NaN NaN NaN
     >
     > L <- spMatrix(9, 30, i = rep(1:9, 3), 1:27, (1:27) %% 4 != 1)
     > M <- drop0(crossprod(L))
     > diag(M) <- diag(M) + 5 # to make it pos.def.
     > M. <- M[1:12,1:12] # small ex
     > N3 <- as(Matrix(upper.tri(diag(3))), "nMatrix")
     > stopifnotValid(bdN <- bdiag(N3, N3),"nsparseMatrix")
     >
     > stopifnot(identical(L, L == TRUE), ## used to give infinite recursion
     + all(drop0((0 - L) != 0) == drop0(L)))
     > L[sample(length(L), 10)] <- NA
     diagnosing replTmat(x,i,j,v): nargs()= 3; missing (i,j) = (0,1)
     > ll <- as(L,"logical")
     > stopifnot(all.equal(mean(L, na.rm=TRUE),
     + mean(ll, na.rm=TRUE), tol= 1e-14),
     + all.equal(mean(L, na.rm=TRUE, trim=1/4),# <- with a warning
     + mean(ll, na.rm=TRUE, trim=1/4), tol= 1e-14))
     Warning in .local(x, ...) :
     trimmed mean of 'sparseVector' -- suboptimally using as.numeric(.)
     >
     >
     > ## Examples where is.na(.) was wrong:
     > validObject(sc <- new("dsCMatrix", i=as.integer(c(0,0:1,1:2,0:1,3)), Dim=c(4L,4L),
     + p = c(0L,1L,3L,5L,8L), x = c(0,NA,NA,0:1,0,NA,1)))
     [1] TRUE
     > validObject(gc <- as(sc, "generalMatrix"))
     [1] TRUE
     >
     > stopifnot(isSymmetric(M), isSymmetric(M.),
     + is(bdiag(M., M.),"symmetricMatrix"),
     + is(bdN, "triangularMatrix"),
     + all(sc == gc | (is.na(sc) & is.na(gc))),
     + all.equal(N3,N3),
     + tail(all.equal(N3, t(N3)), 1) == all.equal(1,-1),# ~= "Mean relative difference: 2"
     + all((bdN != t(bdN)) == (bdN + t(bdN))), # <nsparse> != <nsparse> failed to work...
     + !any((0+bdN) > bdN), # <dsparse> o <nsparse>
     + !any(bdN != (0+bdN)), # <nsparse> o <dsparse>
     + length(grep("Length", all.equal(M., (vM <- as.vector(M.))))) > 0,
     + identical(M., (M2 <- Matrix(vM, 12,12))),
     + all.equal(M., M2, tolerance =0)
     + )
     >
     > Filter(function(.) inherits(get(.), "symmetricMatrix"), ls())
     [1] "M" "M." "M2" "cM" "d4d" "o4" "sD" "sc"
     > ## [1] "cM" "M" "M." "M2" "o4" "sc"
     > tt <- as(kronecker(cM, Diagonal(x = c(10,1))), "symmetricMatrix")
     > dimnames(tt) <- list(NULL, cn <- letters[1:ncol(tt)])
     > stopifnotValid(tt, "dsTMatrix")
     > (cc <- as(tt, "CsparseMatrix")) # shows *symmetric* dimnames
     8 x 8 sparse Matrix of class "dsCMatrix"
     a b c d e f g h
     a 10 . 20 . . . . .
     b . 1 . 2 . . . .
     c 20 . 50 . . . . .
     d . 2 . 5 . . . .
     e . . . . 10 . . .
     f . . . . . 1 . .
     g . . . . . . 10 .
     h . . . . . . . 1
     > stopifnot(identical3( cc @Dimnames, tt @Dimnames, list(NULL, cn)),
     + identical3(t(cc)@Dimnames, t(tt)@Dimnames, list(cn, NULL)),
     + identical3(dimnames(cc), dimnames(tt), list(cn, cn)))# now symmetric !
     >
     > stopifnot(identical3(dimnames(cc),
     + dimnames(as(cc, "generalMatrix")), ## should fixup dimnames to *symmetric*
     + dimnames(as(tt, "generalMatrix"))))
     > ## --> .Call(Csparse_symmetric_to_general, from)
     >
     > mat <- as(cc, "matrix") ## --> should fixup dimnames to *symmetric*
     > mat # should print *symmetric* dimnames
     a b c d e f g h
     a 10 0 20 0 0 0 0 0
     b 0 1 0 2 0 0 0 0
     c 20 0 50 0 0 0 0 0
     d 0 2 0 5 0 0 0 0
     e 0 0 0 0 10 0 0 0
     f 0 0 0 0 0 1 0 0
     g 0 0 0 0 0 0 10 0
     h 0 0 0 0 0 0 0 1
     > stopifnot(identical3(dimnames(cc), dimnames(mat), dimnames(as(tt, "matrix"))))
     >
     > selectMethod(coerce, c("dsCMatrix", "denseMatrix"))
     Method Definition:
    
     function (from, to = "denseMatrix", strict = TRUE)
     .Call(Csparse_to_dense, from, 1L)
     <bytecode: 0x000000001633c610>
     <environment: namespace:Matrix>
    
     Signatures:
     from to
     target "dsCMatrix" "denseMatrix"
     defined "dsCMatrix" "denseMatrix"
     > dmat <- as(cc, "denseMatrix") ## --> gave Error (!!) in Matrix 1.1-5
     > stopifnot(identical3(tt@Dimnames, dmat@Dimnames, list(NULL, cn)))
     > dmat # should print *symmetric* dimnames (not modifying dmat as it did intermittently)
     8 x 8 Matrix of class "dsyMatrix"
     a b c d e f g h
     a 10 0 20 0 0 0 0 0
     b 0 1 0 2 0 0 0 0
     c 20 0 50 0 0 0 0 0
     d 0 2 0 5 0 0 0 0
     e 0 0 0 0 10 0 0 0
     f 0 0 0 0 0 1 0 0
     g 0 0 0 0 0 0 10 0
     h 0 0 0 0 0 0 0 1
     > stopifnot(identical(dmat@Dimnames, list(NULL, cn)))
     > ttdm <- as(tt, "denseMatrix")
     > stopifnot(all.equal(dmat, ttdm),
     + ## ^^^^^^ not identical(): 'x' slot differs, as only "U" is needed
     + identical(as(dmat, "dspMatrix"), as(ttdm, "dspMatrix")),
     + identical(dimnames(cc), dimnames(dmat)),
     + ## coercing back should give original :
     + identical(cc, as(dmat, "sparseMatrix")),
     + identical(uniqTsparse(tt), as(ttdm, "TsparseMatrix")))
     >
     > ## MM: now *if* cc is "truly symmetric", these dimnames should be, too:
     > d5 <- cn[1:5]; dnm5 <- list(d5,d5)
     > stopifnot(identical(dimnames( cc [1:5, 1:5]), dnm5),
     + identical(dimnames(t(cc)[1:5, 1:5]), dnm5))
     >
     >
     > ## large sparse ones: these now directly "go sparse":
     > str(m0 <- Matrix(0, nrow=100, ncol = 1000))
     Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
     ..@ i : int(0)
     ..@ p : int [1:1001] 0 0 0 0 0 0 0 0 0 0 ...
     ..@ Dim : int [1:2] 100 1000
     ..@ Dimnames:List of 2
     .. ..$ : NULL
     .. ..$ : NULL
     ..@ x : num(0)
     ..@ factors : list()
     > str(l0 <- Matrix(FALSE, nrow=100, ncol = 200))
     Formal class 'lgCMatrix' [package "Matrix"] with 6 slots
     ..@ i : int(0)
     ..@ p : int [1:201] 0 0 0 0 0 0 0 0 0 0 ...
     ..@ Dim : int [1:2] 100 200
     ..@ Dimnames:List of 2
     .. ..$ : NULL
     .. ..$ : NULL
     ..@ x : logi(0)
     ..@ factors : list()
     > stopifnot(all(!l0),
     + identical(FALSE, any(l0)))
     >
     > if(!interactive()) warnings()
     > ## really large {length(<dense equivalent>) is beyond R's limits}:
     > op <- options(warn = 2) # warnings (e.g. integer overflow!) become errors:
     > n <- 50000L
     > stopifnot(n^2 > .Machine$integer.max)
     > ## had integer overflow in index constructions:
     > x <- 1:n
     > D <- Diagonal(n, x=x[n:1])
     > summary(D)# special method
     50000 x 50000 diagonal Matrix of class "ddiMatrix"
     Min. 1st Qu. Median Mean 3rd Qu. Max.
     1 12501 25001 25001 37500 50000
     > summary(D != 0)
     50000 x 50000 diagonal Matrix of class "ldiMatrix"
     Mode TRUE
     logical 50000
     > stopifnot(identical(x*D, (Dx <- D*x)),
     + identical(D != 0, as(D, "lMatrix")),
     + identical(Dx, local({d <- D; d@x <- d@x * x; d})))
     >
     > Lrg <- new("dgTMatrix", Dim = c(n,n))
     > l0 <- as(as(Lrg, "lMatrix"), "lgCMatrix")
     > d0 <- as(l0, "dgCMatrix")
     >
     > if(FALSE) { #_____________________ FIXME: Should use cholmod_l_*() everywhere (?)____
     + ## problem in Csparse_to_dense :
     + dl0 <- as(l0, "denseMatrix")
     + dd0 <- as(d0, "denseMatrix")
     + ## currently, both give --- Error in asMethod(object) :
     + ## Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
     + ##--> And there it is 'Int_max' ==> ../src/CHOLMOD/Include/cholmod_internal.h
     + ## defines 'Int_max' and does that depending of "mode", and
     + ## MM thinks we should use the "DLONG" mode now -- for 64-bit integers!
     + ## ==> Then Int_max := SuiteSparse_long_max := LONG_MAX
     + ## (the latter from ../src/SuiteSparse_config/SuiteSparse_config.h )
     + ## ==> use cholmod_l_<foo> instead of cholmod_<foo> in *many places*
     + ##
     + ## check they are ok
     + stopifnot(identical(dim(dl0), c(n,n)), identical(dim(dd0), c(n,n)),
     + !any(dl0), all(dd0 == 0))
     + rm(dl0, dd0)# too large to keep in memory and pass to checkMatrix()
     + }
     >
     > diag(Lrg[2:9,1:8]) <- 1:8
     > ## ==: Lrg[2:9,1:8] <- `diag<-`(Lrg[2:9,1:8], 1:8)
     > e1 <- try(Lrg == Lrg) # ==> Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
     Error in asMethod(object) :
     Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 102
     > ## (error message almost ok)
     >
     > (memGB <- Sys.memGB("MemFree")) # from test-tools-1.R
     Error: (converted from warning) 'memory.limit()' is no longer supported
     Execution halted
Flavor: r-devel-windows-x86_64-new-TK

Version: 1.3-4
Check: tests
Result: ERROR
     Running 'Class+Meth.R' [2s]
     Running 'Simple.R' [3s]
     Running 'abIndex-tsts.R' [3s]
     Running 'base-matrix-fun.R' [2s]
     Running 'bind.R' [3s]
     Comparing 'bind.Rout' to 'bind.Rout.save' ... OK
     Running 'dg_Matrix.R' [3s]
     Running 'dpo-test.R' [5s]
     Running 'dtpMatrix.R' [2s]
     Running 'factorizing.R' [14s]
     Running 'group-methods.R' [4s]
     Running 'indexing.R' [13s]
     Comparing 'indexing.Rout' to 'indexing.Rout.save' ... OK
     Running 'matprod.R' [9s]
     Running 'matr-exp.R' [2s]
     Running 'other-pkgs.R' [2s]
     Running 'spModel.matrix.R' [3s]
     Running 'validObj.R' [5s]
     Running 'write-read.R' [2s]
    Running the tests in 'tests/Simple.R' failed.
    Complete output:
     > #### Currently a collection of simple tests
     > ## (since 'Matrix' takes long to load, rather have fewer source files!)
     >
     > ##-------- *BEFORE* attaching Matrix: --------------------------------
     > str(Matrix::Matrix)# -> load the namespace
     function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,
     sparse = NULL, doDiag = TRUE, forceCheck = FALSE)
     > T <- new("ngTMatrix", i=0L, j=2L, Dim = c(2L,6L))
     > T
     2 x 6 sparse Matrix of class "ngTMatrix"
    
     [1,] . . | . . .
     [2,] . . . . . .
     > as(T, "CsparseMatrix")
     2 x 6 sparse Matrix of class "ngCMatrix"
    
     [1,] . . | . . .
     [2,] . . . . . .
     > ## gave Error in asMethod(object) : could not find function ".M.classEnv"
     > ## from 0.999375-23 to *-25
     >
     > ## another even shorter version of this:
     > n <- new("dgCMatrix")
     > n
     0 x 0 sparse Matrix of class "dgCMatrix"
     <0 x 0 matrix>
     > ## this:
     > m <- Matrix::Matrix(cbind(1,0,diag(x=2:4)))
     > m
     3 x 5 sparse Matrix of class "dgCMatrix"
    
     [1,] 1 . 2 . .
     [2,] 1 . . 3 .
     [3,] 1 . . . 4
     > mt <- m + table(gl(3,5), gl(5,3))# failed in Matrix <= 1.2.9
     > mt
     3 x 5 sparse Matrix of class "dgCMatrix"
    
     1 2 3 4 5
     1 4 2 2 . .
     2 1 1 3 4 .
     3 1 . . 2 7
     > stopifnot(is(mt, "sparseMatrix"))
     >
     > ##--------------------------------------------------------------------
     >
     > library(Matrix)
     >
     > source(system.file("test-tools.R", package = "Matrix"))# identical3() etc
     Loading required package: tools
     > (doExtras <- doExtras && getRversion() >= "3.4") # so have withAutoprint(.)
     [1] FALSE
     >
     > if(interactive()) {
     + options(error = recover, Matrix.verbose = TRUE, warn = 1)
     + } else options( Matrix.verbose = TRUE, warn = 1)
     > # ^^^^^^ to show Matrix.msg()s
     >
     > ### Matrix() ''smartness''
     > (d40 <- Matrix( diag(4)))
     4 x 4 diagonal matrix of class "ddiMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 1 . . .
     [2,] . 1 . .
     [3,] . . 1 .
     [4,] . . . 1
     > (z4 <- Matrix(0*diag(4)))
     4 x 4 diagonal matrix of class "ddiMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 0 . . .
     [2,] . 0 . .
     [3,] . . 0 .
     [4,] . . . 0
     > (o4 <- Matrix(1+diag(4)))
     4 x 4 Matrix of class "dsyMatrix"
     [,1] [,2] [,3] [,4]
     [1,] 2 1 1 1
     [2,] 1 2 1 1
     [3,] 1 1 2 1
     [4,] 1 1 1 2
     > (tr <- Matrix(cbind(1,0:1)))
     2 x 2 Matrix of class "dtrMatrix"
     [,1] [,2]
     [1,] 1 .
     [2,] 1 1
     > (M4 <- Matrix(m4 <- cbind(0,rbind(6*diag(3),0))))
     4 x 4 sparse Matrix of class "dtCMatrix"
    
     [1,] . 6 . .
     [2,] . . 6 .
     [3,] . . . 6
     [4,] . . . .
     > dM4 <- Matrix(M4, sparse = FALSE)
     > d4. <- diag(4); dimnames(d4.) <- dns <- rep(list(LETTERS[1:4]), 2)
     > d4a <- diag(4); dimnames(d4a) <- dna <- list(LETTERS[1:4], letters[1:4])# "a"symmetric
     > m1a <- matrix(0, dimnames=list("A","b"))# "a"symmetric
     > d4di<- as(d4., "diagonalMatrix")
     > d4da<- as(d4a, "diagonalMatrix")
     > d4d <- as(d4., "denseMatrix")
     > d4aS <- Matrix(d4a, sparse=TRUE, doDiag=FALSE)
     > d1aS <- Matrix(m1a, sparse=TRUE, doDiag=FALSE)
     > stopifnot(exprs = {
     + identical(d4di@x, numeric()) # was "named" unnecessarily
     + identical(dimnames(d4 <- Matrix(d4.)), dns)
     + identical4(d40, Matrix(diag(4)), unname(d4), unname(d4da))
     + identical3(d4, as(d4., "Matrix"), as(d4., "diagonalMatrix"))
     + is(d4aS, "dtCMatrix") # not "dsC*", as asymmetric dimnames
     + is(d4d, "denseMatrix")
     + identical(dimnames(d4T <- as(d4., "TsparseMatrix")), dns) # failed till 2019-09-xx
     + identical(d4T, as(d4., "dgTMatrix"))
     + })
     >
     > class(mN <- Matrix(NA, 3,4)) # NA *is* logical
     [1] "lgeMatrix"
     attr(,"package")
     [1] "Matrix"
     > validObject(Matrix(NA))
     [1] TRUE
     > bd4 <- bdiag(M4,dM4,M4)
     > stopifnotValid(o4, "dsyMatrix")
     > stopifnotValid(M4, "dtCMatrix")
     > stopifnot(validObject(dM4), validObject(mN),
     + identical(bdiag(M4), bdiag(dM4)),
     + identical(bd4@p, c(0L,0:3,3:6,6:9)),
     + identical(bd4@i, c(0:2, 4:6, 8:10)), bd4@x == 6
     + )
     > assert.EQ.mat(dM4, m4)
     > assert.EQ.mat(M4^M4, m4^m4)
     > assert.EQ.mat(mN, matrix(NA, 3,4))
     > assert.EQ.mat(bdiag(diag(4)), diag(4))
     > sL <- Matrix(, 3,4, sparse=TRUE)# -> "lgC"
     > trS <- Matrix(tr, sparse=TRUE)# failed in 0.9975-11
     > stopifnotValid(d4, "diagonalMatrix"); stopifnotValid(z4, "diagonalMatrix")
     > stopifnotValid(tr, "triangularMatrix"); stopifnotValid(trS, "triangularMatrix")
     > stopifnot(all(is.na(sL@x)), ## not yet: all(is.na(sL)),
     + !any(sL, na.rm=TRUE), all(!sL, na.rm=TRUE),
     + validObject(Matrix(c(NA,0), 4, 3, byrow = TRUE)),
     + validObject(Matrix(c(NA,0), 4, 4)))
     > stopifnotValid(Matrix(c(NA,0,0,0), 4, 4), "sparseMatrix")
     > I <- i1 <- I1 <- Diagonal(1)
     > ## TODO? stopifnot(identical(I, Matrix(1, sparse=TRUE))) # doDiag=TRUE default
     > I1[1,1] <- i1[1, ] <- I [ ,1] <- NA
     > stopifnot(identical3(I,i1,I1))
     > image(d4) # gave infinite recursion
     rectangle size 100.9 x 100.9 [pixels]; --> lwd :1
     >
     > ## Steve Walker, Mar 12, 2014:
     > n <- 7
     > (M <- triu(Matrix(seq_len(n^2), n, sparse=TRUE)))
     7 x 7 sparse Matrix of class "dtCMatrix"
    
     [1,] 1 8 15 22 29 36 43
     [2,] . 9 16 23 30 37 44
     [3,] . . 17 24 31 38 45
     [4,] . . . 25 32 39 46
     [5,] . . . . 33 40 47
     [6,] . . . . . 41 48
     [7,] . . . . . . 49
     > im <- image(M) # should be an n-by-n image plot, but is not
     > stopifnot(n == diff(sort(im$y.limits)))
     > ## ylimits were too small (by 1 on each side)
     >
     > assertError( Matrix(factor(letters)) )
     > n.lsec <- length(.leap.seconds)# 27 (2017-07)
     > mlp <- matrix(.leap.seconds)## 27 x 1 numeric matrix
     > Mlp <- Matrix(.leap.seconds)
     > stopifnot(identical(dim(Mlp), c(n.lsec, 1L)))
     > assert.EQ.mat(Mlp, mlp)
     > .Leap.seconds <- as.POSIXlt(.leap.seconds)
     > if(FALSE) { ## TODO -- once R itself does better ...
     + mLp <- matrix(.Leap.seconds)## 11 x 1 list of (Numeric,Int.,Char.) each of length 27 -- yuck!!!
     + MLp <- Matrix(.Leap.seconds)## --> error (for now)
     + }
     >
     > E <- rep(c(TRUE,NA,TRUE), length=8)
     > F <- new("nsparseVector", length = 8L, i = c(2L, 5L, 8L))
     > e <- as(E, "sparseVector"); f <- as(F,"lsparseVector")
     > Fv <- as.vector(F, "any") # failed in Matrix <= 1.2.0, and base::as.vector(.) failed too:
     > stopifnot(E | as.vector(F), identical(E | F, F | E),
     + all(e | f), all(E | F), # <- failed Ops.spv.spv
     + identical(Fv, base::as.vector(F)),
     + is.logical(Fv), which(Fv) == c(2,5,8))
     > F[-8:-1] # was partly "illegal" (length = 0 is ok; nnz '3' is not)
     sparse vector (nnz/length = 0/0) of class "nsparseVector"
     > F.ineg <- lapply(1:8, function(k) F[-8:-k])
     > F.pos <- lapply(1:8, function(k) F[seq_len(k-1)])
     > F.vec <- lapply(1:8, function(k) Fv[seq_len(k-1)])
     > str(F.vec, vec=8)
     List of 8
     $ : logi(0)
     $ : logi FALSE
     $ : logi [1:2] FALSE TRUE
     $ : logi [1:3] FALSE TRUE FALSE
     $ : logi [1:4] FALSE TRUE FALSE FALSE
     $ : logi [1:5] FALSE TRUE FALSE FALSE TRUE
     $ : logi [1:6] FALSE TRUE FALSE FALSE TRUE FALSE
     $ : logi [1:7] FALSE TRUE FALSE FALSE TRUE FALSE FALSE
     > (nT <- vapply(F.vec, sum, 1L)) # == 0 0 1 1 1 2 2 2
     [1] 0 0 1 1 1 2 2 2
     > str(whichT <- lapply(F.vec, which))
     List of 8
     $ : int(0)
     $ : int(0)
     $ : int 2
     $ : int 2
     $ : int 2
     $ : int [1:2] 2 5
     $ : int [1:2] 2 5
     $ : int [1:2] 2 5
     > i.lengths <- function(L) vapply(L, function(.) length(.@i), 1L)
     > stopifnot(identical(lengths(F.vec), 0:7)
     + ,
     + identical(lengths(F.ineg), 0:7)
     + ,
     + identical(lengths(F.pos), 0:7)
     + ,
     + identical(i.lengths(F.pos), nT)
     + ,
     + identical(i.lengths(F.ineg), nT) # failed before 2018-03-19
     + ,
     + identical(lapply(F.pos, slot, "i"), whichT)
     + ,
     + identical(lapply(F.ineg, slot, "i"), whichT) # failed before 2018-03-19
     + )
     > ## Here, sparseVector '[' is really wrong:
     > SV <- new("nsparseVector", length = 30L,
     + i = c(1L, 8L, 9L, 12L, 13L, 18L, 21L, 22L))
     > NI <- -c(1:5, 7:10, 12:16, 18:27, 29,30)
     > sv <- SV[1:14]; ni <- -(1:14)[-c(6,11)] # smaller example
     > selectMethod("[", c("nsparseVector","index","missing","missing"))# the culprit
     Method Definition:
    
     function (x, i, j, ..., drop = TRUE)
     {
     has.x <- .hasSlot(x, "x")
     n <- x@length
     if (extends(cl.i <- getClass(class(i)), "numeric") && any(i <
     0)) {
     if (any(i > 0))
     stop("you cannot mix negative and positive indices")
     if (any(z <- i == 0))
     i <- i[!z]
     i <- unique(sort(-i))
     nom <- is.na(m <- match(x@i, i))
     x@i <- x@i[nom]
     if (has.x)
     x@x <- x@x[nom]
     x@i <- x@i - findInterval(x@i, i)
     x@length <- n - length(i)
     }
     else {
     ii <- intIv(i, n, cl.i = cl.i)
     m <- match(x@i, ii, nomatch = 0)
     sel <- m > 0L
     x@length <- length(ii)
     x@i <- m[sel]
     if (any(iDup <- duplicated(ii))) {
     i.i <- match(ii[iDup], ii)
     jm <- lapply(i.i, function(.) which(. == m))
     if (has.x)
     sel <- c(which(sel), unlist(jm))
     x@i <- c(x@i, rep.int(which(iDup), lengths(jm)))
     }
     if (has.x)
     x@x <- x@x[sel]
     }
     x
     }
     <bytecode: 0x0000000009d2f038>
     <environment: namespace:Matrix>
    
     Signatures:
     x i j drop
     target "nsparseVector" "index" "missing" "missing"
     defined "sparseVector" "index" "ANY" "ANY"
     > if(FALSE)
     + trace("[", browser, signature=c("nsparseVector","index","missing","missing"))
     > stopifnot(
     + SV[NI] == as.vector(SV)[NI] ## badly failed before 2018-03-19
     + ,
     + sv[ni] == as.vector(sv)[ni] ## ditto
     + )
     > if(FALSE)
     + untrace("[", signature=c("nsparseVector","index","missing","missing"))
     >
     > dT <- new("dgTMatrix",
     + i = c(1:2,1:2), j=rep(1:2, each=2), Dim = c(4L, 4L), x = c(1, 1, NA, 2))
     > dt <- new("dtTMatrix", i = 0:3, j = 0:3, Dim = c(4L, 4L), x = c(1,0,0,0),
     + uplo = "U", diag = "N")
     > c1 <- as(dT, "CsparseMatrix")
     > c2 <- as(dt, "CsparseMatrix")
     > isValid(lc <- c1 > c2,"lgCMatrix")
     [1] TRUE
     > isValid(lt <- dT > dt,"lgCMatrix")
     [1] TRUE
     > stopifnot(identical(lc,lt))
     >
     > ## Versions of Diagonal()
     > dD <- Diagonal(x = 5:1)
     > sD <- .symDiagonal(5, 5:1)
     > tD <- .trDiagonal (5, 5:1) # x=<integer> had failed for both
     > stopifnot(all(sD == dD)
     + , all(tD == dD)
     + , identical(sD, .symDiagonal(x = 5:1))
     + , identical(tD, .sparseDiagonal(x=5:1))
     + , identical(tD, .trDiagonal (x = 5:1)))# 'n' now has default
     >
     > M <- Diagonal(4); M[1,2] <- 2 ; M
     4 x 4 sparse Matrix of class "dtCMatrix" (unitriangular)
    
     [1,] I 2 . .
     [2,] . I . .
     [3,] . . I .
     [4,] . . . I
     > cM <- crossprod(M) # >> as_cholmod_l_triplet(): could not reallocate for internal diagU2N()
     > stopifnot(identical(cM, tcrossprod(t(M))))
     >
     > S.na <- spMatrix(3, 4, c(1,2,3), c(2,3,3), c(NA,1,0))
     > (S.na <- S.na - 2 * S.na)
     3 x 4 sparse Matrix of class "dgCMatrix"
    
     [1,] . NA . .
     [2,] . . -1 .
     [3,] . . 0 .
     > (L <- S.na != 0)
     3 x 4 sparse Matrix of class "lgCMatrix"
    
     [1,] . N . .
     [2,] . . | .
     [3,] . . : .
     >
     > (Ln0 <- S.na != rep(0, prod(dim(L))))
     3 x 4 sparse Matrix of class "lgCMatrix"
    
     [1,] . N . .
     [2,] . . | .
     [3,] . . . .
     > .Lm0 <- S.na != Matrix(0, 3, 4)
     > stopifnot(Q.eq(L, Ln0), identical(Ln0, .Lm0)); rm(Ln0, .Lm0)
     >
     >
     > ### Unit-diagonal and unitriangular {methods need diagU2N() or similar}
     > I <- Diagonal(3)
     > (T <- as(I,"TsparseMatrix")) # unitriangular
     3 x 3 sparse Matrix of class "dtTMatrix" (unitriangular)
    
     [1,] I . .
     [2,] . I .
     [3,] . . I
     > (C <- as(I,"CsparseMatrix")) # (ditto)
     3 x 3 sparse Matrix of class "dtCMatrix" (unitriangular)
    
     [1,] I . .
     [2,] . I .
     [3,] . . I
     > lT <- as(T,"lMatrix")
     > lC <- as(C,"lMatrix")
     > stopifnot(
     + identical((n0 <- I != 0), Diagonal(3, TRUE)), I@diag == "U",
     + identical(n0, I & TRUE), identical(n0, I | FALSE),
     + identical(n0, TRUE & I), identical(n0, FALSE | I),
     + all(n0 == !(I == 0)), all(I == n0), identical(n0 == I, I == n0)
     + ,
     + identical4(lT, as(Diagonal(3, x=TRUE),"TsparseMatrix"), T & TRUE, TRUE & T),
     + identical4(lC, as(Diagonal(3, x=TRUE),"CsparseMatrix"), C & TRUE, TRUE & C),
     + identical3(lT, T | FALSE, FALSE | T),
     + identical3(lC, C | FALSE, FALSE | C),
     + TRUE)
     > I[,1] <- NA; I[2,2] <- NA ; I[3,] <- NaN
     > stopifnotValid(I, "sparseMatrix")
     > I # gave error in printSpMatrix() - because of R bug in format.info()
     3 x 3 sparse Matrix of class "dtCMatrix"
    
     [1,] NA . .
     [2,] NA NA .
     [3,] NaN NaN NaN
     >
     > L <- spMatrix(9, 30, i = rep(1:9, 3), 1:27, (1:27) %% 4 != 1)
     > M <- drop0(crossprod(L))
     > diag(M) <- diag(M) + 5 # to make it pos.def.
     > M. <- M[1:12,1:12] # small ex
     > N3 <- as(Matrix(upper.tri(diag(3))), "nMatrix")
     > stopifnotValid(bdN <- bdiag(N3, N3),"nsparseMatrix")
     >
     > stopifnot(identical(L, L == TRUE), ## used to give infinite recursion
     + all(drop0((0 - L) != 0) == drop0(L)))
     > L[sample(length(L), 10)] <- NA
     diagnosing replTmat(x,i,j,v): nargs()= 3; missing (i,j) = (0,1)
     > ll <- as(L,"logical")
     > stopifnot(all.equal(mean(L, na.rm=TRUE),
     + mean(ll, na.rm=TRUE), tol= 1e-14),
     + all.equal(mean(L, na.rm=TRUE, trim=1/4),# <- with a warning
     + mean(ll, na.rm=TRUE, trim=1/4), tol= 1e-14))
     Warning in .local(x, ...) :
     trimmed mean of 'sparseVector' -- suboptimally using as.numeric(.)
     >
     >
     > ## Examples where is.na(.) was wrong:
     > validObject(sc <- new("dsCMatrix", i=as.integer(c(0,0:1,1:2,0:1,3)), Dim=c(4L,4L),
     + p = c(0L,1L,3L,5L,8L), x = c(0,NA,NA,0:1,0,NA,1)))
     [1] TRUE
     > validObject(gc <- as(sc, "generalMatrix"))
     [1] TRUE
     >
     > stopifnot(isSymmetric(M), isSymmetric(M.),
     + is(bdiag(M., M.),"symmetricMatrix"),
     + is(bdN, "triangularMatrix"),
     + all(sc == gc | (is.na(sc) & is.na(gc))),
     + all.equal(N3,N3),
     + tail(all.equal(N3, t(N3)), 1) == all.equal(1,-1),# ~= "Mean relative difference: 2"
     + all((bdN != t(bdN)) == (bdN + t(bdN))), # <nsparse> != <nsparse> failed to work...
     + !any((0+bdN) > bdN), # <dsparse> o <nsparse>
     + !any(bdN != (0+bdN)), # <nsparse> o <dsparse>
     + length(grep("Length", all.equal(M., (vM <- as.vector(M.))))) > 0,
     + identical(M., (M2 <- Matrix(vM, 12,12))),
     + all.equal(M., M2, tolerance =0)
     + )
     >
     > Filter(function(.) inherits(get(.), "symmetricMatrix"), ls())
     [1] "M" "M." "M2" "cM" "d4d" "o4" "sD" "sc"
     > ## [1] "cM" "M" "M." "M2" "o4" "sc"
     > tt <- as(kronecker(cM, Diagonal(x = c(10,1))), "symmetricMatrix")
     > dimnames(tt) <- list(NULL, cn <- letters[1:ncol(tt)])
     > stopifnotValid(tt, "dsTMatrix")
     > (cc <- as(tt, "CsparseMatrix")) # shows *symmetric* dimnames
     8 x 8 sparse Matrix of class "dsCMatrix"
     a b c d e f g h
     a 10 . 20 . . . . .
     b . 1 . 2 . . . .
     c 20 . 50 . . . . .
     d . 2 . 5 . . . .
     e . . . . 10 . . .
     f . . . . . 1 . .
     g . . . . . . 10 .
     h . . . . . . . 1
     > stopifnot(identical3( cc @Dimnames, tt @Dimnames, list(NULL, cn)),
     + identical3(t(cc)@Dimnames, t(tt)@Dimnames, list(cn, NULL)),
     + identical3(dimnames(cc), dimnames(tt), list(cn, cn)))# now symmetric !
     >
     > stopifnot(identical3(dimnames(cc),
     + dimnames(as(cc, "generalMatrix")), ## should fixup dimnames to *symmetric*
     + dimnames(as(tt, "generalMatrix"))))
     > ## --> .Call(Csparse_symmetric_to_general, from)
     >
     > mat <- as(cc, "matrix") ## --> should fixup dimnames to *symmetric*
     > mat # should print *symmetric* dimnames
     a b c d e f g h
     a 10 0 20 0 0 0 0 0
     b 0 1 0 2 0 0 0 0
     c 20 0 50 0 0 0 0 0
     d 0 2 0 5 0 0 0 0
     e 0 0 0 0 10 0 0 0
     f 0 0 0 0 0 1 0 0
     g 0 0 0 0 0 0 10 0
     h 0 0 0 0 0 0 0 1
     > stopifnot(identical3(dimnames(cc), dimnames(mat), dimnames(as(tt, "matrix"))))
     >
     > selectMethod(coerce, c("dsCMatrix", "denseMatrix"))
     Method Definition:
    
     function (from, to = "denseMatrix", strict = TRUE)
     .Call(Csparse_to_dense, from, 1L)
     <bytecode: 0x000000000bc53a58>
     <environment: namespace:Matrix>
    
     Signatures:
     from to
     target "dsCMatrix" "denseMatrix"
     defined "dsCMatrix" "denseMatrix"
     > dmat <- as(cc, "denseMatrix") ## --> gave Error (!!) in Matrix 1.1-5
     > stopifnot(identical3(tt@Dimnames, dmat@Dimnames, list(NULL, cn)))
     > dmat # should print *symmetric* dimnames (not modifying dmat as it did intermittently)
     8 x 8 Matrix of class "dsyMatrix"
     a b c d e f g h
     a 10 0 20 0 0 0 0 0
     b 0 1 0 2 0 0 0 0
     c 20 0 50 0 0 0 0 0
     d 0 2 0 5 0 0 0 0
     e 0 0 0 0 10 0 0 0
     f 0 0 0 0 0 1 0 0
     g 0 0 0 0 0 0 10 0
     h 0 0 0 0 0 0 0 1
     > stopifnot(identical(dmat@Dimnames, list(NULL, cn)))
     > ttdm <- as(tt, "denseMatrix")
     > stopifnot(all.equal(dmat, ttdm),
     + ## ^^^^^^ not identical(): 'x' slot differs, as only "U" is needed
     + identical(as(dmat, "dspMatrix"), as(ttdm, "dspMatrix")),
     + identical(dimnames(cc), dimnames(dmat)),
     + ## coercing back should give original :
     + identical(cc, as(dmat, "sparseMatrix")),
     + identical(uniqTsparse(tt), as(ttdm, "TsparseMatrix")))
     >
     > ## MM: now *if* cc is "truly symmetric", these dimnames should be, too:
     > d5 <- cn[1:5]; dnm5 <- list(d5,d5)
     > stopifnot(identical(dimnames( cc [1:5, 1:5]), dnm5),
     + identical(dimnames(t(cc)[1:5, 1:5]), dnm5))
     >
     >
     > ## large sparse ones: these now directly "go sparse":
     > str(m0 <- Matrix(0, nrow=100, ncol = 1000))
     Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
     ..@ i : int(0)
     ..@ p : int [1:1001] 0 0 0 0 0 0 0 0 0 0 ...
     ..@ Dim : int [1:2] 100 1000
     ..@ Dimnames:List of 2
     .. ..$ : NULL
     .. ..$ : NULL
     ..@ x : num(0)
     ..@ factors : list()
     > str(l0 <- Matrix(FALSE, nrow=100, ncol = 200))
     Formal class 'lgCMatrix' [package "Matrix"] with 6 slots
     ..@ i : int(0)
     ..@ p : int [1:201] 0 0 0 0 0 0 0 0 0 0 ...
     ..@ Dim : int [1:2] 100 200
     ..@ Dimnames:List of 2
     .. ..$ : NULL
     .. ..$ : NULL
     ..@ x : logi(0)
     ..@ factors : list()
     > stopifnot(all(!l0),
     + identical(FALSE, any(l0)))
     >
     > if(!interactive()) warnings()
     > ## really large {length(<dense equivalent>) is beyond R's limits}:
     > op <- options(warn = 2) # warnings (e.g. integer overflow!) become errors:
     > n <- 50000L
     > stopifnot(n^2 > .Machine$integer.max)
     > ## had integer overflow in index constructions:
     > x <- 1:n
     > D <- Diagonal(n, x=x[n:1])
     > summary(D)# special method
     50000 x 50000 diagonal Matrix of class "ddiMatrix"
     Min. 1st Qu. Median Mean 3rd Qu. Max.
     1 12501 25001 25001 37500 50000
     > summary(D != 0)
     50000 x 50000 diagonal Matrix of class "ldiMatrix"
     Mode TRUE
     logical 50000
     > stopifnot(identical(x*D, (Dx <- D*x)),
     + identical(D != 0, as(D, "lMatrix")),
     + identical(Dx, local({d <- D; d@x <- d@x * x; d})))
     >
     > Lrg <- new("dgTMatrix", Dim = c(n,n))
     > l0 <- as(as(Lrg, "lMatrix"), "lgCMatrix")
     > d0 <- as(l0, "dgCMatrix")
     >
     > if(FALSE) { #_____________________ FIXME: Should use cholmod_l_*() everywhere (?)____
     + ## problem in Csparse_to_dense :
     + dl0 <- as(l0, "denseMatrix")
     + dd0 <- as(d0, "denseMatrix")
     + ## currently, both give --- Error in asMethod(object) :
     + ## Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
     + ##--> And there it is 'Int_max' ==> ../src/CHOLMOD/Include/cholmod_internal.h
     + ## defines 'Int_max' and does that depending of "mode", and
     + ## MM thinks we should use the "DLONG" mode now -- for 64-bit integers!
     + ## ==> Then Int_max := SuiteSparse_long_max := LONG_MAX
     + ## (the latter from ../src/SuiteSparse_config/SuiteSparse_config.h )
     + ## ==> use cholmod_l_<foo> instead of cholmod_<foo> in *many places*
     + ##
     + ## check they are ok
     + stopifnot(identical(dim(dl0), c(n,n)), identical(dim(dd0), c(n,n)),
     + !any(dl0), all(dd0 == 0))
     + rm(dl0, dd0)# too large to keep in memory and pass to checkMatrix()
     + }
     >
     > diag(Lrg[2:9,1:8]) <- 1:8
     > ## ==: Lrg[2:9,1:8] <- `diag<-`(Lrg[2:9,1:8], 1:8)
     > e1 <- try(Lrg == Lrg) # ==> Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105
     Error in asMethod(object) :
     Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 102
     > ## (error message almost ok)
     >
     > (memGB <- Sys.memGB("MemFree")) # from test-tools-1.R
     Error: (converted from warning) 'memory.limit()' is no longer supported
     Execution halted
Flavor: r-devel-windows-x86_64-old