Last chance! 50% off unlimited learning
Sale ends in
nsparseMatrix
class is a virtual class of sparse
matrices with TRUE
/FALSE
entries. Only the positions of the
elements that are TRUE
are stored. These can be stored in the
``triplet'' form (classes ngTMatrix
, nsTMatrix
, and
ntTMatrix
which really contain pairs, not triplets) or in
compressed column-oriented form (classes ngCMatrix
,
nsCMatrix
, and ntCMatrix
) or in compressed row-oriented
form (classes ngRMatrix
, nsRMatrix
, and
ntRMatrix
). The second letter in the name of these non-virtual
classes indicates g
eneral, s
ymmetric, or t
riangular.new("ngCMatrix",
...)
and so on. More frequently objects are created by coercion of
a numeric sparse matrix to the logical form for use in
the symbolic analysis phase
of an algorithm involving sparse matrices. Such algorithms often
involve two phases: a symbolic phase wherein the positions of the
non-zeros in the result are determined and a numeric phase wherein the
actual results are calculated. During the symbolic phase only the
positions of the non-zero elements in any operands are of interest,
hence any numeric sparse matrices can be treated as logical sparse
matrices.dgCMatrix
(m <- Matrix(c(0,0,2:0), 3,5, dimnames=list(LETTERS[1:3],NULL)))
## ``extract the nonzero-pattern of (m) into an nMatrix'':
nm <- as(m, "ngCMatrix")
str(nm) # no 'x' slot
!nm # no longer sparse
## consistency check:
stopifnot(xor(as( nm, "matrix"),
as(!nm, "matrix")))
data(KNex)
nmm <- as(KNex $ mm, "ngCMatrix")
str(xlx <- crossprod(nmm))# "nsCMatrix"
stopifnot(isSymmetric(xlx))
image(xlx, main=paste("crossprod(nmm) : Sparse", class(xlx)))
Run the code above in your browser using DataLab