SCM

SCM Repository

[matrix] Diff of /pkg/tests/validObj.R
ViewVC logotype

Diff of /pkg/tests/validObj.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 538, Thu Feb 10 13:50:27 2005 UTC revision 628, Thu Mar 10 17:57:47 2005 UTC
# Line 22  Line 22 
22      invisible(t.res)      invisible(t.res)
23  }  }
24    
25  ## "dMatrix"  ### --- "dMatrix" ---
26  str(new("Matrix"))  ## the empty ones:
27    chk.matrix(new("Matrix"))
28    chk.matrix(new("dMatrix"))
29    chk.matrix(new("ddenseMatrix"))
30    chk.matrix(new("dgeMatrix"))
31    
32  ## "dge"  ## "dge"
33  assertError( new("dgeMatrix", Dim = c(2,2), x= 1:4) )# double 'Dim'  assertError( new("dgeMatrix", Dim = c(2,2), x= 1:4) )# double 'Dim'
 if(FALSE)## FIXME: this creates an integer '@ x' !  
34  assertError( new("dgeMatrix", Dim = as.integer(c(2,2)), x= 1:4) )# int 'x'  assertError( new("dgeMatrix", Dim = as.integer(c(2,2)), x= 1:4) )# int 'x'
35  assertError( new("dgeMatrix", Dim = 2:2, x=as.double(1:4)) )# length(Dim) !=2  assertError( new("dgeMatrix", Dim = 2:2, x=as.double(1:4)) )# length(Dim) !=2
36  assertError( new("dgeMatrix", Dim = as.integer(c(2,2)), x= as.double(1:5)))  assertError( new("dgeMatrix", Dim = as.integer(c(2,2)), x= as.double(1:5)))
37    
38  chk.matrix(m1 <- Matrix(1:6, ncol=2))  chk.matrix(m1 <- Matrix(1:6, ncol=2))
39  chk.matrix(m2 <- Matrix(1:7, ncol=3)) # a warning  chk.matrix(m2 <- Matrix(1:7, ncol=3)) # a warning
40    stopifnot(is(m1) == c("dgeMatrix", "ddenseMatrix", "dMatrix", "Matrix"),
41              dim(t(m1)) == 2:3,
42              identical(m1, t(t(m1))))
43    c.nam <- paste("C",1:2, sep='')
44    dimnames(m1) <- list(NULL, c.nam)
45    stopifnot(colnames(m1) == c.nam,
46              identical(dimnames(t(m1)), list(c.nam, NULL)),
47              identical(m1, t(t(m1))))
48    
49    ## an example of *named* dimnames
50    (t34N <- as(unclass(table(x = gl(3,4), y=gl(4,3))), "dgeMatrix"))
51    stopifnot(identical(dimnames(t34N),
52                        dimnames(as(t34N, "matrix"))))
53    
54  ## "dpo"  ## "dpo"
55  chk.matrix(cm <- crossprod(m1))  chk.matrix(cm <- crossprod(m1))
56  chk.matrix(as(cm, "dsyMatrix"))  chk.matrix(as(cm, "dsyMatrix"))
57  chk.matrix(as(cm, "dgeMatrix"))  chk.matrix(as(cm, "dgeMatrix"))
58  try( chk.matrix(as(cm, "Matrix")) ) # gives an error  chk.matrix(as(cm, "dMatrix"))
59    try( chk.matrix(as(cm, "Matrix")) )# gives an error: "Matrix" has NULL 'dim()'
60    
61  ## Cholesky  ## Cholesky
62  chk.matrix(ch <- chol(cm))  chk.matrix(ch <- chol(cm))
# Line 50  Line 67 
67  ### Very basic  triangular matrix stuff  ### Very basic  triangular matrix stuff
68    
69  assertError( new("dtrMatrix", Dim = c(2,2), x= 1:4) )# double 'Dim'  assertError( new("dtrMatrix", Dim = c(2,2), x= 1:4) )# double 'Dim'
 if(FALSE)## FIXME: this creates an integer '@ x' !  
70  assertError( new("dtrMatrix", Dim = as.integer(c(2,2)), x= 1:4) )# int 'x'  assertError( new("dtrMatrix", Dim = as.integer(c(2,2)), x= 1:4) )# int 'x'
71    ## This caused a segfault (before revision r1172 in ../src/dtrMatrix.c):
72  assertError( new("dtrMatrix", Dim = 2:2, x=as.double(1:4)) )# length(Dim) !=2  assertError( new("dtrMatrix", Dim = 2:2, x=as.double(1:4)) )# length(Dim) !=2
73  assertError( new("dtrMatrix", Dim = as.integer(c(2,2)), x= as.double(1:5)))  assertError( new("dtrMatrix", Dim = as.integer(c(2,2)), x= as.double(1:5)))
74    
75  tr22 <- new("dtrMatrix", Dim = as.integer(c(2,2)), x=as.double(1:4))  tr22 <- new("dtrMatrix", Dim = as.integer(c(2,2)), x=as.double(1:4))
76  try( t(tr22) ) # fails -- FIXME  tt22 <- t(tr22)
77    (tPt <- tr22 + tt22)
78    stopifnot(identical(10 * tPt, tPt * 10),
79              (t.22 <- (tr22 / .5)* .5)@x == c(1,0,3,4),
80              TRUE) ## not yet: class(t.22) == "dtrMatrix")
81    
82  ## non-square  
83    ## non-square  triagonal Matrices --- should this be forbidden anyway? ---
84  tru <- new("dtrMatrix", Dim = 2:3, x=as.double(1:6), uplo="L", diag="U")  tru <- new("dtrMatrix", Dim = 2:3, x=as.double(1:6), uplo="L", diag="U")
85  trn <- new("dtrMatrix", Dim = 2:3, x=as.double(1:6), uplo="L", diag="N")  trn <- new("dtrMatrix", Dim = 2:3, x=as.double(1:6), uplo="L", diag="N")
86  try( tru + trn ) # not yet  tru + trn  # a 'dgeMatrix'
   
 try( t(tru) ) ## FIXME !  
 try( t(trn) ) ## FIXME  
87    
88    as(t(tru),"dgeMatrix")
89    as(t(trn),"dgeMatrix")
90    as(t(t(tru)), "dgeMatrix")# pretty non sense

Legend:
Removed from v.538  
changed lines
  Added in v.628

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge