# SCM Repository

[matrix] Diff of /pkg/tests/simple.R
 [matrix] / pkg / tests / simple.R

# Diff of /pkg/tests/simple.R

revision 1237, Thu Mar 30 15:23:47 2006 UTC revision 1238, Thu Mar 30 19:56:09 2006 UTC
# Line 99  Line 99
99  assert.EQ.mat(kt2, ktf, tol= 0)  assert.EQ.mat(kt2, ktf, tol= 0)
100  ## but kt1 and kt2, both "dgT" are different since entries are not ordered!  ## but kt1 and kt2, both "dgT" are different since entries are not ordered!
101
102    tm <- matrix(0, 8,8)
103    tm[cbind(c(1,1,2,7,8),
104             c(3,6,4,8,8))] <- c(2,-30,15,20,80)
105    (tM <- Matrix(tm))                ## dtC
106    (mM <- Matrix(m <- (tm + t(tm)))) ## dsC
107    mT <- as(mM, "dsTMatrix")
108    assert.EQ.mat(tM, tm, tol=0)
109    assert.EQ.mat(mT, m,  tol=0)
110    stopifnot(is(mM, "dsCMatrix"), is(tM, "dtCMatrix"),
111              ## coercions  general <-> symmetric
112              identical(as(as(mM, "dgCMatrix"), "dsCMatrix"), mM),
113              identical(as(as(mM, "dgTMatrix"), "dsTMatrix"), mT),
114              identical(as(as(tM, "dgCMatrix"), "dtCMatrix"), tM)
115    )
116    eM <- eigen(mM) # works thanks to base::as.matrix hack in ../R/zzz.R
117    stopifnot(all.equal(eM\$values,
118                    { v <- c(162.462112512353, 30.0665927567458)
119                      c(v, 15, 0, 0, 160-v[1], -15, -v[2])}, tol=1e-14))
120
121  ##--- symmetric -> pos.def. needs valid test:  ##--- symmetric -> pos.def. needs valid test:
122  if(FALSE) # this happily "works" but MM thinks it shouldn't:  m5 <- Matrix(diag(5) - 1)
123  assertError(as(as(Matrix(diag(5)-1), "dsyMatrix"), "dpoMatrix"))  if(FALSE) # FIXME: this happily "works" but MM thinks it shouldn't:
124    assertError(as(m5, "dpoMatrix"))
125
126
127  ###-- logical sparse : ----------  ###-- logical sparse : ----------
128
129  (lkt <- as(as(kt1, "dgCMatrix"), "lgCMatrix"))# ok  (lkt <- as(as(kt1, "dgCMatrix"), "lgCMatrix"))# ok
130  (clt <- crossprod(lkt))  (clt <- crossprod(lkt))
131  if(FALSE)  if(FALSE) ## FIXME!
132      crossprod(clt)      crossprod(clt)
133  ## CHOLMOD error: matrix cannot be symmetric  ## CHOLMOD error: matrix cannot be symmetric
134
# Line 138  Line 158
158
159
160  cat('Time elapsed: ', proc.time(),'\n') # "stats"  cat('Time elapsed: ', proc.time(),'\n') # "stats"

Legend:
 Removed from v.1237 changed lines Added in v.1238