The R Project SVN R-packages

Rev

Rev 1569 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1569 Rev 1582
Line 1... Line 1...
1
library(Matrix)
1
library(Matrix)
2
 
2
 
-
 
3
is.all.equal3 <- function(x,y,z, tol = .Machine$double.eps^0.5)
-
 
4
    isTRUE(all.equal(x,y, tol=tol)) && isTRUE(all.equal(y,z, tol=tol))
-
 
5
 
-
 
6
is.all.equal4 <- function(x,y,z,u, tol = .Machine$double.eps^0.5)
-
 
7
    is.all.equal3(x,y,z, tol=tol) && isTRUE(all.equal(z,u, tol=tol))
-
 
8
 
-
 
9
 
3
data(mm)
10
data(mm)
4
stopifnot(##is(mm) == c("dgCMatrix", "dMatrix", "Matrix"),
11
stopifnot(##is(mm) == c("dgCMatrix", "dMatrix", "Matrix"),
5
          dim(mm) == (dm <- c(1850, 712)),
12
          dim(mm) == (dm <- c(1850, 712)),
6
          identical(dimnames(mm), list(NULL,NULL)))
13
          identical(dimnames(mm), list(NULL,NULL)))
7
str(mm)
14
str(mm)
Line 22... Line 29...
22
          validObject(mTm), dim(mTm) == dm[c(2,2)],
29
          validObject(mTm), dim(mTm) == dm[c(2,2)],
23
          validObject(mmT), dim(mmT) == dm[c(1,1)],
30
          validObject(mmT), dim(mmT) == dm[c(1,1)],
24
          identical(as(tmm, "matrix"), t(as(mm, "matrix"))))
31
          identical(as(tmm, "matrix"), t(as(mm, "matrix"))))
25
 
32
 
26
## from a bug report by Guissepe Ragusa <gragusa@ucsd.edu>
33
## from a bug report by Guissepe Ragusa <gragusa@ucsd.edu>
-
 
34
set.seed(101)
-
 
35
for(i in 1:10) {
27
A <- matrix(rnorm(400), nrow = 100, ncol = 4)
36
    A <- matrix(rnorm(400), nrow = 100, ncol = 4)
28
A[A < 0] <- 0
37
    A[A < +1] <- 0
29
Acsc <- as(A, "dgCMatrix")
38
    Acsc <- as(A, "dgCMatrix")
30
A <- as(A, "dgeMatrix")
39
    A <- as(A, "dgeMatrix")
31
b <- matrix(rnorm(400), nrow = 4, ncol = 100)
40
    b <- matrix(rnorm(400), nrow = 4, ncol = 100)
32
B <- as(b, "dgeMatrix")
41
    B <- as(b, "dgeMatrix")
33
stopifnot(all.equal(A %*% B, Acsc %*% B),
42
    stopifnot(is.all.equal4(A %*% B, Acsc %*% B,
34
          all.equal(A %*% b, Acsc %*% b),
43
                            A %*% b, Acsc %*% b),
35
          all.equal(b %*% A, b %*% Acsc),
44
              is.all.equal4(b %*% A, b %*% Acsc,
36
          all.equal(B %*% A, B %*% Acsc))
45
                            B %*% A, B %*% Acsc))
-
 
46
}
37
 
47
 
38
proc.time() # for ``statistical reasons''
48
proc.time() # for ``statistical reasons''