Running ‘Class+Meth.R’ [2s/4s]
  Running ‘Simple.R’ [8s/11s]
  Running ‘abIndex-tsts.R’ [3s/6s]
  Running ‘base-matrix-fun.R’ [2s/3s]
  Running ‘bind.R’ [3s/4s]
  Comparing ‘bind.Rout’ to ‘bind.Rout.save’ ... OK
  Running ‘dg_Matrix.R’ [3s/4s]
  Running ‘dpo-test.R’ [5s/6s]
  Running ‘dtpMatrix.R’ [2s/2s]
  Running ‘factorizing.R’ [13s/19s]
  Running ‘group-methods.R’ [4s/5s]
  Running ‘indexing.R’ [13s/19s]
  Comparing ‘indexing.Rout’ to ‘indexing.Rout.save’ ...1032,1033d1031
< Warning in if (class(x) != class(y)) { :
<   the condition has length > 1 and only the first element will be used
1109,1110d1106
< Warning in if (class(x) != class(y)) { :
<   the condition has length > 1 and only the first element will be used
1152,1153d1147
< Warning in if (class(x) != class(y)) { :
<   the condition has length > 1 and only the first element will be used
  Running ‘matprod.R’ [3s/5s]
  Running ‘matr-exp.R’ [2s/4s]
  Running ‘other-pkgs.R’ [2s/3s]
  Running ‘spModel.matrix.R’ [3s/5s]
  Running ‘validObj.R’ [4s/6s]
  Running ‘write-read.R’ [2s/4s]
Running the tests in ‘tests/matprod.R’ failed.
Complete output:
  > library(Matrix)
  > 
  > ### Matrix Products including  cross products
  > 
  > source(system.file("test-tools.R", package = "Matrix")) # is.EQ.mat(), dnIdentical() ..etc
  Loading required package: tools
  > doExtras
  [1] FALSE
  > options(warn=1, # show as they happen
  + 	Matrix.verbose = doExtras)
  > 
  > ##' Check matrix multiplications with (unit) Diagonal matrices
  > chkDiagProd <- function(M) {
  +     stopifnot(is.matrix(M) || is(M,"Matrix"))
  +     I.l  <- Diagonal(nrow(M)) # I_n -- "unit" Diagonal
  +     I.r  <- Diagonal(ncol(M)) # I_d
  +     D2.l <- Diagonal(nrow(M), x = 2) # D_n
  +     D2.r <- Diagonal(ncol(M), x = 2) # I_d
  +     stopifnot(is.EQ.mat(M, M %*% I.r),
  + 	      is.EQ.mat(M, I.l %*% M),
  + 	      is.EQ.mat(2*M, M %*% D2.r),
  + 	      is.EQ.mat(M*2, D2.l %*% M),
  + 	      ## crossprod
  + 	      is.EQ.mat(t(M), crossprod(M, I.l)),
  + 	      is.EQ.mat(  M , crossprod(I.l, M)),
  + 	      is.EQ.mat(t(2*M), crossprod(M, D2.l)),
  + 	      is.EQ.mat(  M*2 , crossprod(D2.l, M)),
  + 	      ## tcrossprod
  + 	      is.EQ.mat(  M , tcrossprod(M, I.r)),
  + 	      is.EQ.mat(t(M), tcrossprod(I.r, M)),
  + 	      is.EQ.mat(  2*M , tcrossprod(M, D2.r)),
  + 	      is.EQ.mat(t(M*2), tcrossprod(D2.r, M)))
  + }
  > 
  > ### dimnames -- notably for matrix products ----------------
  > #
  > ##' Checks that matrix products are the same, including dimnames
  > ##'
  > ##' @param m matrix = traditional-R-matrix version of M
  > ##' @param M optional Matrix = "Matrix class version of m"
  > ##' @param browse
  > chkDnProd <- function(m = as(M, "matrix"), M = Matrix(m), browse=FALSE, warn.ok=FALSE) {
  +     ## TODO:
  +     ## if(browse) stopifnot <- f.unction(...)  such that it enters browser() when it is not fulfilled
  +     if(!warn.ok) { # NO warnings allowd
  +         op <- options(warn = 2)
  +         on.exit(options(op))
  +     }
  +     stopifnot(is.matrix(m), is(M, "Matrix"), identical(dim(m), dim(M)), dnIdentical(m,M))
  +     ## m is  n x d  (say)
  +     is.square <- nrow(m) == ncol(m)
  + 
  +     p1 <- (tm <- t(m)) %*% m ## d x d
  +     p1. <- crossprod(m)
  +     stopifnot(is.EQ.mat3(p1, p1., crossprod(m,m)))
  + 
  +     t1 <- m %*% tm ## n x n
  +     t1. <- tcrossprod(m)
  +     stopifnot(is.EQ.mat3(t1, t1., tcrossprod(m,m)))
  + 
  +     if(is.square) {
  + 	mm <- m %*% m
  + 	stopifnot(is.EQ.mat3(mm, crossprod(tm,m), tcrossprod(m,tm)))
  +     }
  + 
  +     chkDiagProd(m)## was not ok in Matrix 1.2.0
  + 
  +     ## Now the	"Matrix" ones -- should match the "matrix" above
  +     M0 <- M
  +     cat("sparse: ")
  +     for(sparse in c(TRUE, FALSE)) {
  + 	cat(sparse, "; ")
  + 	M <- as(M0, if(sparse) "sparseMatrix" else "denseMatrix")
  + 	P1 <- (tM <- t(M)) %*% M
  + 	P1. <- crossprod(M)
  + 	stopifnot(is.EQ.mat3(P1, P1., p1),
  + 		  is.EQ.mat3(P1., crossprod(M,M), crossprod(M,m)),
  + 		  is.EQ.mat (P1., crossprod(m,M)))
  + 
  + 	## P1. is "symmetricMatrix" -- semantically "must have" symm.dimnames
  + 	PP1 <- P1. %*% P1. ## still  d x d
  + 	R <- triu(PP1); r <- as(R, "matrix") # upper - triangular
  + 	L <- tril(PP1); l <- as(L, "matrix") # lower - triangular
  + 	stopifnot(isSymmetric(P1.), isSymmetric(PP1),
  + 		  isDiagonal(L) || is(L,"triangularMatrix"),
  + 		  isDiagonal(R) || is(R,"triangularMatrix"),
  + 		  isTriangular(L, upper=FALSE), isTriangular(R, upper=TRUE),
  + 		  is.EQ.mat(PP1, (pp1 <- p1 %*% p1)),
  + 		  dnIdentical(PP1, R),
  + 		  dnIdentical(L, R))
  + 
  + 	T1 <- M %*% tM
  + 	T1. <- tcrossprod(M)
  + 	stopifnot(is.EQ.mat3(T1, T1., t1),
  + 		  is.EQ.mat3(T1., tcrossprod(M,M), tcrossprod(M,m)),
  + 		  is.EQ.mat (T1., tcrossprod(m,M)),
  + 		  is.EQ.mat(tcrossprod(T1., tM),
  + 			    tcrossprod(t1., tm)),
  + 		  is.EQ.mat(crossprod(T1., M),
  + 			    crossprod(t1., m)))
  + 
  + 	## Now, *mixing*  Matrix x matrix:
  + 	stopifnot(is.EQ.mat3(tM %*% m, tm %*% M, tm %*% m))
  + 
  + 	if(is.square)
  + 	    stopifnot(is.EQ.mat (mm, M %*% M),
  + 		      is.EQ.mat3(mm, crossprod(tM,M), tcrossprod(M,tM)),
  + 		      ## "mixing":
  + 		      is.EQ.mat3(mm, crossprod(tm,M), tcrossprod(m,tM)),
  + 		      is.EQ.mat3(mm, crossprod(tM,m), tcrossprod(M,tm)))
  + 
  + 	## Symmetric and Triangular
  + 	stopifnot(is.EQ.mat(PP1 %*% tM, pp1 %*% tm),
  + 		  is.EQ.mat(R %*% tM, r %*% tm),
  + 		  is.EQ.mat(L %*% tM, L %*% tm))
  + 
  + 	## Diagonal :
  + 	chkDiagProd(M)
  +     }
  +     cat("\n")
  +     invisible(TRUE)
  + }
  > 
  > ## All these are ok  {now, (2012-06-11) also for dense
  > (m <- matrix(c(0, 0, 2:0), 3, 5))
       [,1] [,2] [,3] [,4] [,5]
  [1,]    0    1    0    0    2
  [2,]    0    0    2    0    1
  [3,]    2    0    1    0    0
  > m00 <- m # *no* dimnames
  > dimnames(m) <- list(LETTERS[1:3], letters[1:5])
  > (m.. <- m) # has *both* dimnames
    a b c d e
  A 0 1 0 0 2
  B 0 0 2 0 1
  C 2 0 1 0 0
  > m0. <- m.0 <- m..
  > dimnames(m0.)[1] <- list(NULL); m0.
       a b c d e
  [1,] 0 1 0 0 2
  [2,] 0 0 2 0 1
  [3,] 2 0 1 0 0
  > dimnames(m.0)[2] <- list(NULL); m.0
    [,1] [,2] [,3] [,4] [,5]
  A    0    1    0    0    2
  B    0    0    2    0    1
  C    2    0    1    0    0
  > d <- diag(3); dimnames(d) <- list(c("u","v","w"), c("X","Y","Z")); d
    X Y Z
  u 1 0 0
  v 0 1 0
  w 0 0 1
  > dU <- diagN2U(Matrix(d)) # unitriangular sparse
  > (T <- new("dtrMatrix", diag = "U", x= c(0,0,5,0), Dim= c(2L,2L),
  +           Dimnames= list(paste0("r",1:2),paste0("C",1:2)))) # unitriangular dense
  2 x 2 Matrix of class "dtrMatrix" (unitriangular)
     C1 C2
  r1  1  5
  r2  .  1
  > ##                                                                   ^^^^^^^^^^^^
  > ## currently many warnings about sub-optimal matrix products :
  > chkDnProd(m..)
  sparse: TRUE ; FALSE ; 
  > chkDnProd(m0.)
  sparse: TRUE ; FALSE ; 
  > chkDnProd(m.0)
  sparse: TRUE ; FALSE ; 
  > chkDnProd(m00)
  sparse: TRUE ; FALSE ; 
  > chkDnProd(M =   T)
  sparse: TRUE ; FALSE ; 
  > chkDnProd(M = t(T))
  sparse: TRUE ; FALSE ; 
  > chkDnProd(M =   dU)
  sparse: TRUE ; FALSE ; 
  > chkDnProd(M = t(dU))
  sparse: TRUE ; FALSE ; 
  > ## all the above failed in 1.2-0 and 1.1-5, 1.1-4 some even earlier
  > chkDnProd(M = Diagonal(4))
  sparse: TRUE ; FALSE ; 
  > chkDnProd(diag(x=3:1))
  sparse: TRUE ; FALSE ; 
  > chkDnProd(d)
  sparse: TRUE ; FALSE ; 
  > chkDnProd(M = as(d, "denseMatrix"))# M: dtrMatrix (diag = "N")
  sparse: TRUE ; FALSE ; 
  > 
  > 
  > m5 <- 1 + as(diag(-1:4)[-5,], "dgeMatrix")
  > ## named dimnames:
  > dimnames(m5) <- list(Rows= LETTERS[1:5], paste("C", 1:6, sep=""))
  > tr5 <- tril(m5[,-6])
  > m. <- as(m5, "matrix")
  > m5.2 <- local({t5 <- as.matrix(tr5); t5 %*% t5})
  > stopifnotValid(tr5, "dtrMatrix")
  > stopifnot(dim(m5) == 5:6,
  + 	  class(cm5 <- crossprod(m5)) == "dpoMatrix")
  > assert.EQ.mat(t(m5) %*% m5, as(cm5, "matrix"))
  > assert.EQ.mat(tr5.2 <- tr5 %*% tr5, m5.2)
  > stopifnotValid(tr5.2, "dtrMatrix")
  > stopifnot(as.vector(rep(1,6) %*% cm5) == colSums(cm5),
  + 	  as.vector(cm5 %*% rep(1,6)) == rowSums(cm5))
  > ## uni-diagonal dtrMatrix with "wrong" entries in diagonal
  > ## {the diagonal can be anything: because of diag = "U" it should never be used}:
  > tru <- Diagonal(3, x=3); tru[i.lt <- lower.tri(tru, diag=FALSE)] <- c(2,-3,4)
  > tru@diag <- "U" ; stopifnot(diag(trm <- as.matrix(tru)) == 1)
  > ## TODO: Also add *upper-triangular*  *packed* case !!
  > stopifnot((tru %*% tru)[i.lt] ==
  + 	  (trm %*% trm)[i.lt])
  > 
  > ## crossprod() with numeric vector RHS and LHS
  > i5 <- rep.int(1, 5)
  > isValid(S5 <- tcrossprod(tr5), "dpoMatrix")# and inherits from "dsy"
  [1] TRUE
  > G5 <- as(S5, "generalMatrix")# "dge"
  > assert.EQ.mat( crossprod(i5, m5), rbind( colSums(m5)))
  > assert.EQ.mat( crossprod(i5, m.), rbind( colSums(m5)))
  > assert.EQ.mat( crossprod(m5, i5), cbind( colSums(m5)))
  > assert.EQ.mat( crossprod(m., i5), cbind( colSums(m5)))
  > assert.EQ.mat( crossprod(i5, S5), rbind( colSums(S5))) # failed in Matrix 1.1.4
  > ## tcrossprod() with numeric vector RHS and LHS :
  > stopifnot(identical(tcrossprod(i5, S5), # <- lost dimnames
  + 		    tcrossprod(i5, G5) -> m51),
  + 	  identical(dimnames(m51), list(NULL, LETTERS[1:5]))
  + 	  )
  > m51 <- m5[, 1, drop=FALSE] # [6 x 1]
  > m.1 <- m.[, 1, drop=FALSE] ; assert.EQ.mat(m51, m.1)
  > ## The only (M . v) case
  > assert.EQ.mat(tcrossprod(m51, 5:1), tcrossprod(m.1, 5:1))
  > ## The two  (v . M) cases:
  > assert.EQ.mat(tcrossprod(rep(1,6), m.), rbind( rowSums(m5)))# |v| = ncol(m)
  > assert.EQ.mat(tcrossprod(rep(1,3), m51),
  +               tcrossprod(rep(1,3), m.1))# ncol(m) = 1
  > 
  > ## classes differ
  > tc.m5 <- m5 %*% t(m5)	 # "dge*", no dimnames (FIXME)
  > (tcm5 <- tcrossprod(m5)) # "dpo*"  w/ dimnames
  5 x 5 Matrix of class "dpoMatrix"
    A  B  C  D  E
  A 5  5  6  7  9
  B 5  6  7  8 10
  C 6  7  9  9 11
  D 7  8  9 14 12
  E 9 10 11 12 30
  > assert.EQ.mat(tc.m5, mm5 <- as(tcm5, "matrix"))
  > ## tcrossprod(x,y) :
  > assert.EQ.mat(tcrossprod(m5, m5), mm5)
  > assert.EQ.mat(tcrossprod(m5, m.), mm5)
  > assert.EQ.mat(tcrossprod(m., m5), mm5)
  > 
  > M50 <- m5[,FALSE, drop=FALSE]
  > M05 <- t(M50)
  > s05 <- as(M05, "sparseMatrix")
  > s50 <- t(s05)
  > assert.EQ.mat(M05, matrix(1, 0,5))
  > assert.EQ.mat(M50, matrix(1, 5,0))
  > assert.EQ.mat(tcrossprod(M50), tcrossprod(as(M50, "matrix")))
  > assert.EQ.mat(tcrossprod(s50), tcrossprod(as(s50, "matrix")))
  > assert.EQ.mat( crossprod(s50),	crossprod(as(s50, "matrix")))
  > stopifnot(identical( crossprod(s50), tcrossprod(s05)),
  + 	  identical( crossprod(s05), tcrossprod(s50)))
  > (M00 <- crossprod(M50))## used to fail -> .Call(dgeMatrix_crossprod, x, FALSE)
  0 x 0 Matrix of class "dpoMatrix"
  <0 x 0 matrix>
  > stopifnot(identical(M00, tcrossprod(M05)),
  + 	  all(M00 == t(M50) %*% M50), dim(M00) == 0)
  > 
  > ## simple cases with 'scalars' treated as 1x1 matrices:
  > d <- Matrix(1:5)
  > d %*% 2
  5 x 1 Matrix of class "dgeMatrix"
       [,1]
  [1,]    2
  [2,]    4
  [3,]    6
  [4,]    8
  [5,]   10
  > 10 %*% t(d)
  1 x 5 Matrix of class "dgeMatrix"
       [,1] [,2] [,3] [,4] [,5]
  [1,]   10   20   30   40   50
  > assertError(3 %*% d)		 # must give an error , similar to
  > assertError(5 %*% as.matrix(d))	 # -> error
  > 
  > ## right and left "numeric" and "matrix" multiplication:
  > (p1 <- m5 %*% c(10, 2:6))
  5 x 1 Matrix of class "dgeMatrix"
    [,1]
  A   20
  B   30
  C   33
  D   38
  E   54
  > (p2 <- c(10, 2:5) %*% m5)
  1 x 6 Matrix of class "dgeMatrix"
       C1 C2 C3 C4 C5 C6
  [1,] 14 24 27 32 24 44
  > (pd1 <- m5 %*% diag(1:6))
  5 x 6 Matrix of class "dgeMatrix"
    [,1] [,2] [,3] [,4] [,5] [,6]
  A    0    2    3    4    5    6
  B    1    2    3    4    5    6
  C    1    2    6    4    5    6
  D    1    2    3   12    5    6
  E    1    2    3    4    5   30
  > (pd. <- m5 %*% Diagonal(x = 1:6))
  5 x 6 Matrix of class "dgeMatrix"
      
  Rows C1 C2 C3 C4 C5 C6
     A  0  2  3  4  5  6
     B  1  2  3  4  5  6
     C  1  2  6  4  5  6
     D  1  2  3 12  5  6
     E  1  2  3  4  5 30
  > (pd2 <- diag (10:6)	   %*% m5)
  5 x 6 Matrix of class "dgeMatrix"
       C1 C2 C3 C4 C5 C6
  [1,]  0 10 10 10 10 10
  [2,]  9  9  9  9  9  9
  [3,]  8  8 16  8  8  8
  [4,]  7  7  7 21  7  7
  [5,]  6  6  6  6  6 30
  > (pd..<- Diagonal(x = 10:6) %*% m5)
  5 x 6 Matrix of class "dgeMatrix"
      
  Rows C1 C2 C3 C4 C5 C6
     A  0 10 10 10 10 10
     B  9  9  9  9  9  9
     C  8  8 16  8  8  8
     D  7  7  7 21  7  7
     E  6  6  6  6  6 30
  > stopifnot(dim(crossprod(t(m5))) == c(5,5),
  + 	  c(class(p1),class(p2),class(pd1),class(pd2),
  + 	    class(pd.),class(pd..)) == "dgeMatrix")
  > assert.EQ.mat(p1, cbind(c(20,30,33,38,54)))
  > assert.EQ.mat(pd1, m. %*% diag(1:6))
  > assert.EQ.mat(pd2, diag(10:6) %*% m.)
  > assert.EQ.mat(pd., as(pd1,"matrix"))
  > assert.EQ.mat(pd..,as(pd2,"matrix"))
  > 
  > ## check that 'solve' and '%*%' are inverses
  > suppressWarnings(RNGversion("3.5.0")); set.seed(1)
  > A <- Matrix(rnorm(25), nc = 5)
  > y <- rnorm(5)
  > all.equal((A %*% solve(A, y))@x, y)
  [1] TRUE
  > Atr <- new("dtrMatrix", Dim = A@Dim, x = A@x, uplo = "U")
  > all.equal((Atr %*% solve(Atr, y))@x, y)
  [1] TRUE
  > 
  > ## R-forge bug 5933 by Sebastian Herbert,
  > ## https://r-forge.r-project.org/tracker/index.php?func=detail&aid=5933&group_id=61&atid=294
  > mLeft  <- matrix(data = double(0), nrow = 3, ncol = 0)
  > mRight <- matrix(data = double(0), nrow = 0, ncol = 4)
  > MLeft   <- Matrix(data = double(0), nrow = 3, ncol = 0)
  > MRight  <- Matrix(data = double(0), nrow = 0, ncol = 4)
  > stopifnot(identical3(class(mLeft), class(mRight), "matrix"))
  Error: identical3(class(mLeft), class(mRight), "matrix") is not TRUE
  Execution halted