drop0 | R Documentation |
Deletes “non-structural” zeros (i.e., zeros stored explicitly, in memory) from a sparse matrix and returns the result.
drop0(x, tol = 0, is.Csparse = NA, give.Csparse = TRUE)
x |
a |
tol |
a non-negative number. If |
is.Csparse |
a logical used only if |
give.Csparse |
a logical indicating if the result must
inherit from virtual class |
A sparseMatrix
, the result of deleting
non-structural zeros from x
, possibly after coercion.
drop0
is sometimes called in conjunction with
zapsmall
, e.g., when dealing with sparse
matrix products; see the example.
Function sparseMatrix
, for constructing objects
inheriting from virtual class sparseMatrix
;
nnzero
.
(m <- sparseMatrix(i = 1:8, j = 2:9, x = c(0:2, 3:-1),
dims = c(10L, 20L)))
drop0(m)
## A larger example:
t5 <- new("dtCMatrix", Dim = c(5L, 5L), uplo = "L",
x = c(10, 1, 3, 10, 1, 10, 1, 10, 10),
i = c(0L,2L,4L, 1L, 3L,2L,4L, 3L, 4L),
p = c(0L, 3L, 5L, 7:9))
TT <- kronecker(t5, kronecker(kronecker(t5, t5), t5))
IT <- solve(TT)
I. <- TT %*% IT ; nnzero(I.) # 697 ( == 625 + 72 )
I.0 <- drop0(zapsmall(I.))
## which actually can be more efficiently achieved by
I.. <- drop0(I., tol = 1e-15)
stopifnot(all(I.0 == Diagonal(625)), nnzero(I..) == 625)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.