(m <- Matrix(c(0,0,2:0), 3,5, dimnames=list(LETTERS[1:3],NULL)))
(lm <- (m > 1)) # lgC
!lm # no longer sparse
stopifnot(is(lm,"lsparseMatrix"),
identical(!lm, m <= 1))
data(KNex)
str(mmG.1 <- (KNex $ mm) > 0.1)# "lgC..."
## from logical to nz_pattern -- okay when there are no NA's :
nmG.1 <- as(mmG.1, "nMatrix")
## from logical to "double"
dmG.1 <- as(mmG.1, "dMatrix") # and back:
lmG.1 <- as(dmG.1, "lMatrix")
stopifnot(validObject(lmG.1), identical(lmG.1, mmG.1))
class(xnx <- crossprod(nmG.1))# "nsC.."
class(xlx <- crossprod(mmG.1))# "dsC.." : numeric
is0 <- (xlx == 0)
sum(as.vector(is0))# quite sparse, but
table(xlx@x == 0)# more than half of the entries are (non-structural!) 0
stopifnot(isSymmetric(xlx), isSymmetric(xnx),
## compare xnx and xlx :
sapply(slotNames(xnx),
function(n) identical(slot(xnx, n), slot(xlx, n))))
Run the code above in your browser using DataLab